braintrace

Train recurrent and spiking neural networks with memory-efficient eligibility-trace online learning.

1|Updated Jul 23, 2026
One-click install
npx skills add https://github.com/chaobrain/BrainX-skill --skill braintrace-chaobrain
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: braintrace
Source: https://github.com/chaobrain/BrainX-skill/tree/main/brainx-display-cases/creative-experiment-verification/06-seizure-recruitment/run2/.agents/skills/braintrace
Command: npx skills add https://github.com/chaobrain/BrainX-skill --skill braintrace-chaobrain

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Backpropagation through time (BPTT) stores the full unrolled sequence graph, so training recurrent or spiking neural networks on long sequences runs out of memory. BrainTrace replaces that sequence-length-dependent graph with eligibility traces accumulated during the forward pass, making memory constant in sequence length. ## Core Features & Use Cases - ETP-aware layers and operators: Build models with braintrace.nn layers (MiniGRU, Linear, Conv, LoRA, sparse) whose parameters automatically participate in eligibility-trace propagation. - Estimator selection and compilation: Choose between parameter-shaped D_RTRL traces and input/output-factorized pp_prop traces, then compile once with braintrace.compile() and inspect the resulting graph via learner.report. - Online sequence training: Drive sequences with etrace_grad() and etrace_evolve(), reset recurrent and eligibility State together at sequence boundaries, and update parameters with standard optimizers. - Use Case: Train a recurrent spiking neural network on long spike sequences where BPTT exceeds GPU memory, using pp_prop with a mapped batch of LIF neurons and a leaky readout. ## Quick Start Use the braintrace skill to compile a MiniGRU sequence model with D_RTRL and train it online on my long input sequence without running out of memory.

Frequently Asked Questions about braintrace

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I train an RNN without BPTT running out of memory?

Build the model with braintrace.nn ETP-aware layers, compile once with braintrace.compile(model, braintrace.D_RTRL, example_step), then call learner.etrace_grad() to accumulate online gradients. Memory stays constant in sequence length because eligibility traces replace the unrolled graph.

D_RTRL vs pp_prop: which BrainTrace estimator should I use?

Use D_RTRL when parameter-shaped trace memory O(B * |theta|) is feasible; it is the general RNN default. Use pp_prop when parameter-shaped traces are too large, especially for recurrent SNNs, since it stores input/output factors at O(B * (I + O)).

Is BrainTrace online learning equivalent to BPTT gradients?

Not in general. D_RTRL uses a diagonal hidden-Jacobian approximation and pp_prop adds input/output factorization, so equality with BPTT holds only in documented mathematical regimes. Validate against a reduced BPTT oracle before relying on gradient fidelity.

Why is my weight excluded from the BrainTrace compiled graph?

A parameter only participates when consumed by an ETP operator; ordinary JAX operations exclude it automatically. Readouts that do not feed hidden State are correctly reported as non-temporal, and weights reaching hidden State only through another trainable ETP weight are excluded to prevent double counting.

How do I reset state between sequences in BrainTrace?

Call both brainstate.nn.reset_all_states(model, batch_size=...) and learner.reset_state(batch_size=...) at every independent sequence boundary. Resetting only one leaves hidden State or eligibility traces carrying over from the previous trajectory.

Can I batch BrainTrace training across multiple sequences?

Yes, but use exactly one mapping owner: either create one brainstate.nn.Map and construct the algorithm around it, or pass an unmapped model to braintrace.compile(..., vmap=True). Never pass an already mapped model to compile with vmap=True, which would map it twice.