ETraceVmap#

class braintrace.ETraceVmap#

Provide sequence drivers on a brainstate.nn.Vmap wrapper.

Returned by braintrace.compile(..., vmap=True) so the call site is identical in batched and unbatched mode. Because it is a brainstate.nn.Vmap, calling it, its attributes and every isinstance(x, brainstate.nn.Vmap) check keep working; only the added methods are new.

One thing does change: type(x) is brainstate.nn.Vmap is now False, so a caller dispatching on the exact runtime type takes a different branch, and repr reads ETraceVmap. Use isinstance. (Pickling is unaffected – a bare Vmap was already unpicklable, for the same weakref reason.)

Reaching into .module is not an equivalent: learner.module.etrace_grad(...) would drive the unbatched learner and silently produce per-lane-wrong results.

Window mode is refused here – see SequenceDriverMixin.etrace_grad().

reset_state(batch_size=None, **kwargs)#

Reset every lane’s eligibility traces and the running index.

brainstate.nn.Vmap inherits the no-op Module.reset_state, so without this a batched learner kept the previous sequence’s traces and every call after the first started from them. The wrapped learner’s reset_state zeroes its traces with zeros_like, which keeps the lane axis that compile(..., vmap=True) gave them, so this delegates to it. Like the learner’s own reset_state, it leaves the model’s hidden states alone.

Parameters:
  • batch_size (int, optional) – Must be None: the lane axis is fixed by compile(..., batch_size=...), and a batch size here would put a second batch axis in front of it.

  • **kwargs – Passed to the wrapped learner’s reset_state.

Raises:

ValueError – If batch_size is not None.

ETraceVmap.__init__(module, in_axes=0, out_axes=0, vmap_states=None, vmap_out_states=None, axis_name=None, axis_size=None)#