Compiler, Executor & Diagnostics#
The compiler analyzes a model’s JAX intermediate representation (jaxpr) to
discover the relationships between ETP primitives, weight parameters, and
hidden states. It recognizes ETP primitives by primitive-type identity
(never by string-matching names), and the result is an ETraceGraph
that the executor and the online-learning algorithms consume.
Most users never call this layer directly — compile() and the algorithm
classes drive it for you. It is documented here for building custom algorithms,
inspecting what the compiler discovered, and acting on diagnostics.
Graph Compilation#
The entry point that compiles a model into an eligibility-trace graph, and the graph object it returns.
Construct the eligibility-trace graph for a given model and inputs. |
|
The overall compiled graph for the eligibility trace. |
Module Info#
Extracts the jaxpr and state information from a brainstate.nn.Module.
ModuleInfo is the compiler’s structured view of a model.
Extract the model information for the ETrace compiler. |
|
The model information for the ETrace compiler. |
Graph Executor#
Executes the compiled graph: runs the forward pass and computes the
hidden-to-weight and hidden-to-hidden Jacobians the algorithms consume.
ETraceVjpGraphExecutor is the VJP-based executor used by the
ETraceVjpAlgorithm family.
The eligibility trace graph executor. |
|
The eligibility trace graph executor for the VJP-based online learning algorithms. |
Diagnostics#
Structured, leveled records emitted while the compiler analyzes a model. They
surface issues that would otherwise be silent — for example a trainable input
that does not trace back to a ParamState, or an ETP weight excluded because
it only reaches a hidden state through another trainable primitive.
DiagnosticLevel orders records by severity (INFO < WARNING <
ERROR) and DiagnosticKind names the specific condition.
A single compiler decision, captured with structured context. |
|
Machine-readable reason for a |
|
Severity of a |
Compilation Report#
CompilationReport is the structured summary attached to every learner
returned by compile(). Access it via learner.report after compiling a
model. It aggregates the diagnostics, counts, and graph information produced
during compilation into a single inspectable object.
A read-only view over a compiled |
Key members:
Member |
Description |
|---|---|
|
Dict of summary counts with keys |
|
Sequence of |
|
List of |
|
List of weight paths that participate in online learning (have ETP relations). |
|
List of weight paths excluded from online learning (e.g., weights that only reach a hidden state through another trainable ETP primitive). |
|
The underlying |
|
Sequence of |
|
Print a human-readable summary at the given verbosity level (0–2). |
|
Return the summary as a string. |
Usage example:
import braintrace
learner = braintrace.compile(model, braintrace.D_RTRL, x0, batch_size=1, verbose=2)
# Show a summary at level 1 (groups + weight lists, no raw diagnostics)
learner.report.show(1)
# Inspect counts programmatically
print(learner.report.counts)
# e.g. {'hidden_groups': 1, 'etrace_weights': 2, 'excluded_weights': 1,
# 'warnings': 1, 'errors': 0}
# Iterate diagnostics to find warnings
from braintrace import DiagnosticLevel
warnings = [d for d in learner.report.diagnostics
if d.level == DiagnosticLevel.WARNING]