ETraceGraph#
- class braintrace.ETraceGraph#
The overall compiled graph for the eligibility trace.
Tracks the relationship between the eligibility-trace weights (
ParamState), the eligibility-trace variables (HiddenState), and the eligibility-trace operations (ETP primitives). It is the object returned bycompile_etrace_graph()and consumed by the online-learning algorithms.- Variables:
module_info (ModuleInfo) – The model information.
hidden_groups (sequence of HiddenGroup) – The hidden groups.
hid_path_to_group (dict) – Mapping from each hidden-state path to its
HiddenGroup.hidden_param_op_relations (sequence of HiddenParamOpRelation) – The hidden parameter-operation relations.
hidden_perturb (HiddenPerturbation or None) – The hidden perturbation, or
Nonewhen perturbations are excluded.diagnostics (tuple of CompilationRecord) – The structured compilation records emitted while building the graph.
See also
compile_etrace_graphBuild an
ETraceGraphfrom a model.
Examples
>>> import brainstate >>> import braintrace >>> gru = braintrace.nn.GRUCell(3, 4) >>> _ = brainstate.nn.init_all_states(gru) >>> inputs = brainstate.random.randn(3) >>> graph = braintrace.compile_etrace_graph(gru, inputs) >>> isinstance(graph, braintrace.ETraceGraph) True
- static __new__(_cls, module_info, hidden_groups, hid_path_to_group, hidden_param_op_relations, hidden_perturb, diagnostics=())#
Create new instance of ETraceGraph(module_info, hidden_groups, hid_path_to_group, hidden_param_op_relations, hidden_perturb, diagnostics)
Run the forward pass with additive perturbations injected at the hidden states.
Evaluates the perturbed-forward jaxpr built during compilation, which is the forward computation augmented so that each tracked hidden state has a perturbation term added to it. This is the primitive used to probe hidden->hidden and hidden->output sensitivities.
- Parameters:
args (Inputs) – The model inputs for this step, matching the signature captured at compile time.
perturb_data (Sequence[jax.Array]) – One perturbation array per tracked hidden state, added at the corresponding perturbation site.
old_state_vals (Sequence[jax.Array] or None, optional) – The state values to run from. When
None(default) the current values of the compiled model states are used.
- Returns:
tuple –
(outputs, etrace_state_vals, other_state_vals, temp_data)– the same four-element structure produced by a normal forward call throughModuleInfo.jaxpr_call().
- diagnostics#
Alias for field number 5
- dict()#
Return the graph’s fields as a plain dictionary.
- Returns:
dict – A mapping from field name to value for every attribute of this
ETraceGraph.
- explain(*, weight_path=None, hidden_path=None, kind=None)#
Return compilation records filtered by weight path, hidden path, or kind.
weight_pathandhidden_pathmatch the record’sweight_pathexactly andhidden_pathsmembership respectively.kindmatchesCompilationRecord.kind. All filters are optional; with no filters the full diagnostic log is returned.- Parameters:
weight_path (Path or None, optional) – If given, keep only records whose
weight_pathequals this value. DefaultNone.hidden_path (Path or None, optional) – If given, keep only records whose
hidden_pathscontain this value. DefaultNone.kind (DiagnosticKind or None, optional) – If given, keep only records whose
kindis this value. DefaultNone.
- Returns:
tuple of CompilationRecord – The matching records, in emission order.
- hid_path_to_group#
Alias for field number 2
Alias for field number 1
Alias for field number 3
Alias for field number 4
- module_info#
Alias for field number 0
- ETraceGraph.__init__()#