extract_module_info#
- class braintrace.extract_module_info(model, *model_args, control_flow=None, **model_kwargs)[source]#
Extract the model information for the ETrace compiler.
- Parameters:
model (
Module) – The model from which to extract the information.*model_args – The positional arguments of the model.
control_flow (
ControlFlowPolicy|None) – Policy governing control-flow canonicalization (condif-conversion and inner-scanunrolling; seecanonicalize_control_flow()) and downstream handling of un-flattened control flow.None(default) uses the default policy, which converts every ETP-relevantcond, unrolls every ETP-relevantscanof static length at most 16, keeps weight-freewhileloops that touch hidden state as opaque forward nodes (while_hidden='opaque-fwd'), and raises on ETP primitives left inside a control-flow body (etp_in_control_flow='error'). The policy is stored on the returnedModuleInfo(minfo.control_flow) so later compiler passes apply the same rules.**model_kwargs – The keyword arguments of the model.
- Returns:
The model information.
- Return type:
See also
ModuleInfoThe returned data structure.
Notes
Prefer positional arguments.
**model_kwargsis accepted here for tracing, butModuleInfo.jaxpr_calland the downstreamcompile_etrace_graphpipeline rebuild inputs from positional arguments only — bind static keyword arguments withfunctools.partialbefore compiling.Examples
>>> import brainstate >>> import braintrace >>> gru = braintrace.nn.GRUCell(3, 4) >>> _ = brainstate.nn.init_all_states(gru) >>> inputs = brainstate.random.randn(3) >>> module_info = braintrace.extract_module_info(gru, inputs) >>> module_info.num_var_out 1