ETraceVmap#
- class braintrace.ETraceVmap#
Provide sequence drivers on a
brainstate.nn.Vmapwrapper.Returned by
braintrace.compile(..., vmap=True)so the call site is identical in batched and unbatched mode. Because it is abrainstate.nn.Vmap, calling it, its attributes and everyisinstance(x, brainstate.nn.Vmap)check keep working; only the added methods are new.One thing does change:
type(x) is brainstate.nn.Vmapis nowFalse, so a caller dispatching on the exact runtime type takes a different branch, andreprreadsETraceVmap. Useisinstance. (Pickling is unaffected – a bareVmapwas already unpicklable, for the sameweakrefreason.)Reaching into
.moduleis 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.Vmapinherits the no-opModule.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’sreset_statezeroes its traces withzeros_like, which keeps the lane axis thatcompile(..., vmap=True)gave them, so this delegates to it. Like the learner’s ownreset_state, it leaves the model’s hidden states alone.- Parameters:
batch_size (int, optional) – Must be
None: the lane axis is fixed bycompile(..., 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_sizeis notNone.
- ETraceVmap.__init__(module, in_axes=0, out_axes=0, vmap_states=None, vmap_out_states=None, axis_name=None, axis_size=None)#