brainx-skill 1.0.12 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/installation/lib/bundle.js +51 -13
- package/installation/lib/cli.js +16 -4
- package/installation/lib/literature-mcp.js +536 -0
- package/manifest.json +4 -0
- package/mcp-servers/codex/README.md +82 -0
- package/mcp-servers/codex/UPSTREAM.md +22 -0
- package/mcp-servers/codex/server.mjs +142 -0
- package/mcp-servers/codex/skills.json +10 -0
- package/mcp-servers/codex/system-prompt.md +73 -0
- package/mcp-servers/codex/test/fixtures/fake-codex.mjs +6 -0
- package/mcp-servers/codex/test/server.test.mjs +99 -0
- package/mcp-servers/fulltext-resolver/README.md +136 -0
- package/mcp-servers/fulltext-resolver/REUSE.md +32 -0
- package/mcp-servers/fulltext-resolver/THIRD_PARTY_NOTICES.md +57 -0
- package/mcp-servers/fulltext-resolver/server.mjs +128 -0
- package/mcp-servers/fulltext-resolver/src/document.mjs +253 -0
- package/mcp-servers/fulltext-resolver/src/http.mjs +173 -0
- package/mcp-servers/fulltext-resolver/src/identifiers.mjs +123 -0
- package/mcp-servers/fulltext-resolver/src/model.mjs +105 -0
- package/mcp-servers/fulltext-resolver/src/resolver.mjs +305 -0
- package/mcp-servers/fulltext-resolver/src/sources/biorxiv.mjs +135 -0
- package/mcp-servers/fulltext-resolver/src/sources/europe-pmc.mjs +132 -0
- package/mcp-servers/fulltext-resolver/src/sources/openalex.mjs +165 -0
- package/mcp-servers/fulltext-resolver/test/document.test.mjs +82 -0
- package/mcp-servers/fulltext-resolver/test/resolver.test.mjs +287 -0
- package/mcp-servers/fulltext-resolver/test/server.test.mjs +63 -0
- package/mcp-servers/fulltext-resolver/test/sources.test.mjs +229 -0
- package/package.json +14 -10
- package/skills/bio-neuro-lit/SKILL.md +206 -0
- package/skills/bio-neuro-lit/THIRD_PARTY_NOTICES.md +34 -0
- package/skills/bio-neuro-lit/agents/openai.yaml +4 -0
- package/skills/bio-neuro-lit/references/tool-contracts.md +73 -0
- package/skills/bio-neuro-lit/scripts/deepxiv_fetch.py +110 -0
- package/skills/bio-neuro-lit/scripts/exa_search.py +190 -0
- package/skills/brainx-acceleration/SKILL.md +459 -0
- package/skills/brainx-general-guard/SKILL.md +31 -9
- package/skills/brainx-modeling-loop/SKILL.md +281 -0
- package/skills/brainx-modeling-loop/agents/openai.yaml +4 -0
- package/skills/brainx-modeling-loop/references/monitor-experiment.md +49 -0
- package/skills/brainx-modeling-loop/references/parameter-fitting-workflow/scripts/fitting_hh_neuron.py +254 -0
- package/skills/brainx-modeling-loop/references/parameter-fitting-workflow.md +272 -0
- package/skills/brainx-modeling-loop/references/run-experiment.md +179 -0
- package/skills/brainx-modeling-loop/references/training-workflow.md +270 -0
- package/skills/brainx-visualization/SKILL.md +157 -0
- package/skills/brainx-visualization/agents/openai.yaml +4 -0
- package/skills/brainx-visualization/references/interactive-and-visualization-styling.md +155 -0
- package/skills/brainx-visualization/references/neural-data-visualization.md +141 -0
- package/skills/brainx-visualization/references/statistical-and-model-visualization.md +133 -0
- package/skills/{braincell → package-skills/braincell}/SKILL.md +17 -6
- package/skills/package-skills/braincell/references/braintools/input-current.md +200 -0
- package/skills/package-skills/braincell/references/braintools/optimizer.md +179 -0
- package/skills/{braincell → package-skills/braincell}/references/multicompartment/multicompartment-cell-workflow.md +2 -2
- package/skills/package-skills/braincell/references/scripts/fitting_hh_neuron.py +254 -0
- package/skills/{brainmass → package-skills/brainmass}/references/brainstate/parameter-constraints-regularization.md +1 -1
- package/skills/{brainmass → package-skills/brainmass}/references/coupling-network-api.md +121 -3
- package/skills/{brainmass → package-skills/brainmass}/references/modellibrary.md +79 -1
- package/skills/package-skills/brainmass/references/parameter-sweeps-and-regime-analysis.md +188 -0
- package/skills/{brainmass → package-skills/brainmass}/references/visualization-analysis-api.md +6 -6
- package/skills/{brainpy-state → package-skills/brainpy-state}/SKILL.md +4 -3
- package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/connectivity.md +1 -1
- package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/input-current.md +1 -1
- package/skills/package-skills/brainpy-state/references/braintools/metric.md +152 -0
- package/skills/package-skills/brainpy-state/references/perturbation-experiment-validity.md +76 -0
- package/skills/{brainpy-state → package-skills/brainpy-state}/references/projection-patterns.md +1 -1
- package/skills/{brainstate → package-skills/brainstate}/SKILL.md +1 -0
- package/skills/{brainstate → package-skills/brainstate}/references/brainstate/brainstate-transformed-diagnostics.md +1 -1
- package/skills/{brainstate → package-skills/brainstate}/references/brainstate/parameter-constraints-regularization.md +1 -1
- package/skills/{brainstate → package-skills/brainstate}/references/brainstate/randomness-and-reproducibility.md +1 -1
- package/skills/{brainstate → package-skills/brainstate}/references/brainstate/transformation-grad-expansion.md +2 -2
- package/skills/{brainstate → package-skills/brainstate}/references/brainstate/transformation-vmap-expansion.md +1 -1
- package/skills/{brainstate → package-skills/brainstate}/references/libraries/prebuilt-layer-library.md +1 -1
- package/skills/package-skills/brainstate/references/paired-perturbation-execution.md +113 -0
- package/skills/package-skills/braintrace/SKILL.md +187 -0
- package/skills/package-skills/braintrace/references/Drtrl.md +133 -0
- package/skills/{braintrace → package-skills/braintrace}/references/ETP operators.md +31 -4
- package/skills/package-skills/braintrace/references/algorithm selection.md +64 -0
- package/skills/package-skills/braintrace/references/batching.md +140 -0
- package/skills/{braintrace → package-skills/braintrace}/references/compiler_internal.md +2 -2
- package/skills/{braintrace → package-skills/braintrace}/references/custom algorithms.md +8 -10
- package/skills/package-skills/braintrace/references/pp_pprop workflow.md +179 -0
- package/skills/{braintrace → package-skills/braintrace}/references/pre-built-braintrace-layer.md +2 -2
- package/skills/brainmass/references/parameter-sweeps-and-regime-analysis.md +0 -130
- package/skills/braintrace/SKILL.md +0 -161
- package/skills/braintrace/references/Drtrl.md +0 -179
- package/skills/braintrace/references/algorithm selection.md +0 -120
- package/skills/braintrace/references/batching.md +0 -150
- package/skills/braintrace/references/pp_pprop workflow.md +0 -196
- /package/skills/{braincell → package-skills/braincell}/references/area-scaled-hh-pattern.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/braincell-custom-ion-channel-authoring.md +0 -0
- /package/skills/{brainpy-state → package-skills/braincell}/references/braintools/metric.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/channel-library.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/ion-library.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/mixions-for-adaptation.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/multicompartment/braincell-manual-morphology-construction.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/multicompartment/cv-policy-reference.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/multicompartment/filter-function-library.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/multicompartment/morphology-io-loading-validation.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/multicompartment/probe-reference.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/multicompartment/topology-building-and-visualization.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/scripts/calcium_channel_gating.py +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/scripts/cell_multicompartment_reference.py +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/scripts/channel_ablation.py +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/scripts/fi_curve.py +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/scripts/hh_neuron_basics.py +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/scripts/spike_frequency_adaptation.py +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/scripts/t_current_rebound.py +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/scripts/thalamic_neurons.py +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/solver-library-with-effects.md +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/SKILL.md +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/references/connectivity-variants.md +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/references/custom-operators-cpu.md +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/references/custom-operators-gpu.md +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/references/scripts/102_EI_net_1996.py +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/references/scripts/204_joglekar_2018_propagation.py +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/references/scripts/coba_ei_teaching.py +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/references/sparse-formats.md +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/references/synaptic-plasticity.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/SKILL.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/batch-transform-acceleration.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/brainstate/parameter-transforms-regularizers-catalog.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/braintools/cogtask.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/braintools/data-preprocessing.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/braintools/metric.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/braintools/optimizer.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/braintools/parameter-initializer.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/braintools/surrogate.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/datasets-api.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/fitting-with-objectives-api.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/forward-observation-api.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/horn-task-training.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/noiseprocesses.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/eeg-fitting-with-gradients.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/gradient-free-fitting.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/hopf-bifurcation-single-node.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/horn-cognitive-task-training.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/jansen-rit-eeg-proxy.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/kuramoto-synchronization.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/linear-baseline-node.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/resting-state-meg-whole-brain-pipeline.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/seizure-epileptor-case-study.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/wilson-cowan-ei-dynamics.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/wong-wang-decision-making.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/wong-wang-dmf-resting-state.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/simulator-input-monitor-api.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/array-creation.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brain-dynamics-delay-protocol.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/analysis.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/brainpy legacy workflow.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/built-in dynamic neuron model.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/connecting neurons.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/customize neuron and synpase.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/Input generation.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/More about simulation.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/delays.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/integrators.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/route activity through connectivity.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/synaptic projections.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/synpase properties.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/loss library.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/optimizers.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/parameter initializers.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/prebuilt neural network layers.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/surrogate gradients.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/trainer library.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/trainingworkflows.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/brainstate-control-flow-patterns.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/data-preprocessing.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/optimizer.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/parameter-initializer.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/surrogate.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/component-selection.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/devices.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/divergence-and-parity.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/integration-categories.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/model-library.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/nest-workflow.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/network-building.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/brette_et_al_2007.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/brunel_alpha.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/brunel_delta.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/spatial_gaussex.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/synapsecollection.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/synapse-and-connectivity.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/103_COBA_2005.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/106_COBA_HH_2007.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/107_gamma_oscillation_1996.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/109_fast_global_oscillation.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/sound_localization.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/training-snn.py +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/agents/openai.yaml +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/brainstate/brainstate-control-flow-patterns.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/brainstate/parameter-transforms-regularizers-catalog.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/brainstate/transformation-jit-expansion.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/collective_model_operations.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/extension_mechanisms.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/libraries/prebuilt-activation-library.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/model-interop-and-migration.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/simulation-environment.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/size-inference-variations.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/state-graph-operations.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/state_collections_and_utilities.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/scripts/integrator_rnn.py +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/scripts/lif_neuron_model.py +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/scripts/modern_cnn.py +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/scripts/resnet.py +0 -0
- /package/skills/{braintrace → package-skills/braintrace}/references/custom ETP primitives.md +0 -0
- /package/skills/{braintrace → package-skills/braintrace}/references/customizing_primitive_transforms.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/SKILL.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/array-creation.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/array-mechanics/functional-structural-api.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/array-mechanics.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/math-function-library.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/physical-constant-library.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/prefix-library.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/quantity-inspection-and-conversion.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/typing-and-runtime-validation.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/unit-structure-and-definition.md +0 -0
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: braintrace
|
|
3
|
-
description: BrainTrace relieves training-memory pressure in recurrent and spiking models by replacing BPTT's sequence-length-dependent graph with eligibility traces. Use this skill for memory-efficient temporal training, long sequences, BPTT out-of-memory problems, activation-memory reduction, and BrainTrace estimator selection or compilation. Do not use for general speed optimization, offline BPTT, or model dynamics.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# BrainTrace
|
|
7
|
-
|
|
8
|
-
## Purpose and boundary
|
|
9
|
-
|
|
10
|
-
Use BrainTrace when recurrent or spiking training is limited by BPTT memory. Its broad purpose is to relieve sequence-length memory pressure: it accumulates eligibility traces during the forward sequence instead of retaining the full trajectory for reverse-mode differentiation.
|
|
11
|
-
|
|
12
|
-
Online learning is the mechanism for this memory efficiency, not the routing goal. Memory becomes constant in sequence length, not constant in total: eligibility storage still depends on the batch size, participating parameters, hidden dimensions, and selected algorithm.
|
|
13
|
-
|
|
14
|
-
Follow this path:
|
|
15
|
-
|
|
16
|
-
`build with braintrace.nn -> choose a trace representation -> compile once -> inspect -> reset both State systems -> drive the sequence -> update -> verify`
|
|
17
|
-
|
|
18
|
-
Route general `State`, `Module`, transformations, and optimizer behavior to BrainState. Route neuron and synapse dynamics to BrainPy-State or BrainCell. Use ordinary BrainState training when offline BPTT is acceptable and eligibility traces are not required.
|
|
19
|
-
|
|
20
|
-
## Underlying principle of BrainTrace
|
|
21
|
-
|
|
22
|
-
Hidden State represents the model's recurrent memory. It carries neural activity from one time step to the next.
|
|
23
|
-
|
|
24
|
-
ETP operations represent parameterized paths that need temporal credit. The operation marks participation: a parameter consumed by a BrainTrace ETP operation can receive an eligibility trace; the same parameter consumed only by an ordinary JAX operation cannot.
|
|
25
|
-
|
|
26
|
-
`ETraceGraph` represents the compiled relationship between ETP parameters and hidden-State groups. It tells the learner which parameter influences which recurrent state.
|
|
27
|
-
|
|
28
|
-
Eligibility State represents compressed gradient history. The selected algorithm updates it during each forward step, so training does not retain the unrolled sequence graph.
|
|
29
|
-
|
|
30
|
-
## API structure overview
|
|
31
|
-
|
|
32
|
-
| API family | Responsibility |
|
|
33
|
-
|---|---|
|
|
34
|
-
| `braintrace.nn` | Prebuilt ETP-aware recurrent, linear, convolutional, sparse, and readout layers. Start here. |
|
|
35
|
-
| ETP operations | Mark parameterized operations in a custom layer for eligibility-trace participation. |
|
|
36
|
-
| `braintrace.compile()` | Discover hidden State and ETP parameter paths, build `ETraceGraph`, and return a learner. |
|
|
37
|
-
| `D_RTRL`, `pp_prop`, other algorithms | Define how eligibility State is represented and updated. |
|
|
38
|
-
| Compiled learner | Inspect compilation, reset eligibility State, execute sequences, and return online gradients. |
|
|
39
|
-
|
|
40
|
-
## Choose the memory strategy and compile
|
|
41
|
-
|
|
42
|
-
Compile one representative time step once; the chosen algorithm determines the eligibility-memory shape and approximation.
|
|
43
|
-
|
|
44
|
-
| API | Description |
|
|
45
|
-
|---|---|
|
|
46
|
-
| `braintrace.nn.MiniGRU(...)` | Use for the canonical recurrent model; it carries hidden State and applies ETP-aware parameter operations. |
|
|
47
|
-
| `braintrace.nn.Linear(...)` | Use for an ETP-aware projection; the compiler treats it as non-temporal when its output does not return to hidden State. |
|
|
48
|
-
| `braintrace.D_RTRL` | Use as the default recurrent estimator when a parameter-shaped trace fits memory; it avoids BPTT activation storage but uses a diagonal hidden-recurrence approximation. |
|
|
49
|
-
| `braintrace.pp_prop` | Use when the parameter-shaped trace is too costly, especially for recurrent SNNs; it stores input/output factors and introduces a stronger factorization approximation. |
|
|
50
|
-
| `braintrace.compile(model, algorithm, example_step, batch_size=...)` | Use once with the real per-step shape; it initializes State, compiles parameter-to-hidden relations, and returns the learner. |
|
|
51
|
-
| `learner.report.show(1)` | Use immediately after compilation; it shows hidden groups, traced weights, excluded weights, and exclusion reasons. |
|
|
52
|
-
| `learner.show_graph()` | Use when the report needs structural confirmation; it displays the compiled parameter-to-hidden relationships. |
|
|
53
|
-
|
|
54
|
-
```python
|
|
55
|
-
import brainstate
|
|
56
|
-
import braintrace
|
|
57
|
-
import jax.numpy as jnp
|
|
58
|
-
|
|
59
|
-
brainstate.random.seed(7)
|
|
60
|
-
|
|
61
|
-
class SequenceModel(brainstate.nn.Module):
|
|
62
|
-
def __init__(self):
|
|
63
|
-
super().__init__()
|
|
64
|
-
self.rnn = braintrace.nn.MiniGRU(in_size=1, out_size=6)
|
|
65
|
-
self.readout = braintrace.nn.Linear(6, 1)
|
|
66
|
-
|
|
67
|
-
def update(self, x):
|
|
68
|
-
return self.readout(self.rnn(x))
|
|
69
|
-
|
|
70
|
-
model = SequenceModel()
|
|
71
|
-
inputs = jnp.linspace(-1.0, 1.0, 12).reshape(12, 1, 1)
|
|
72
|
-
targets = 0.7 * inputs + 0.2
|
|
73
|
-
|
|
74
|
-
learner = braintrace.compile(
|
|
75
|
-
model, braintrace.D_RTRL, inputs[0], batch_size=1
|
|
76
|
-
)
|
|
77
|
-
learner.report.show(1)
|
|
78
|
-
learner.show_graph()
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
Open `references/pre-built-braintrace-layer.md` when selecting another ETP-aware layer. Open `references/Drtrl.md` for D-RTRL memory, recurrence, and validation. Open `references/pp_pprop workflow.md` when parameter-shaped traces are too large or the model is a recurrent SNN. Open `references/algorithm selection.md` only when neither canonical choice fits.
|
|
82
|
-
|
|
83
|
-
## Train and evaluate a sequence
|
|
84
|
-
|
|
85
|
-
Let the learner own the time loop and eligibility updates; reset recurrent State and eligibility State together at every independent sequence boundary.
|
|
86
|
-
|
|
87
|
-
| API | Description |
|
|
88
|
-
|---|---|
|
|
89
|
-
| `brainstate.nn.reset_all_states(model, batch_size=...)` | Use at an independent sequence boundary; it resets the model's recurrent State. |
|
|
90
|
-
| `learner.reset_state(batch_size=...)` | Use at the same boundary; it resets eligibility State and the learner's time index. |
|
|
91
|
-
| `learner.etrace_evolve(inputs, return_outputs=True)` | Use for loss-free execution or evaluation; it advances hidden and eligibility State and returns stacked outputs when requested. |
|
|
92
|
-
| `learner.etrace_grad(..., step_fn=..., reduction=...)` | Use for supervised online learning; it drives the sequence, accumulates per-step gradients, applies masking and reduction, and returns gradients. |
|
|
93
|
-
| `optimizer.update(grads)` | Use after one sequence gradient has been reduced; it updates the registered parameters. |
|
|
94
|
-
|
|
95
|
-
```python
|
|
96
|
-
import braintools
|
|
97
|
-
|
|
98
|
-
weights = model.states(brainstate.ParamState)
|
|
99
|
-
optimizer = braintools.optim.SGD(lr=0.08)
|
|
100
|
-
optimizer.register_trainable_weights(weights)
|
|
101
|
-
|
|
102
|
-
def reset_sequence():
|
|
103
|
-
brainstate.nn.reset_all_states(model, batch_size=1)
|
|
104
|
-
learner.reset_state(batch_size=1)
|
|
105
|
-
|
|
106
|
-
def evaluate():
|
|
107
|
-
reset_sequence()
|
|
108
|
-
predictions = learner.etrace_evolve(inputs, return_outputs=True)
|
|
109
|
-
return jnp.mean((predictions - targets) ** 2)
|
|
110
|
-
|
|
111
|
-
def step_loss(x, target):
|
|
112
|
-
return jnp.mean((learner(x) - target) ** 2)
|
|
113
|
-
|
|
114
|
-
def train_epoch(_):
|
|
115
|
-
reset_sequence()
|
|
116
|
-
grads, step_losses = learner.etrace_grad(
|
|
117
|
-
inputs,
|
|
118
|
-
targets,
|
|
119
|
-
step_fn=step_loss,
|
|
120
|
-
reduction="mean",
|
|
121
|
-
return_value=True,
|
|
122
|
-
)
|
|
123
|
-
optimizer.update(grads)
|
|
124
|
-
return step_losses.mean()
|
|
125
|
-
|
|
126
|
-
initial_loss = evaluate()
|
|
127
|
-
losses = brainstate.transform.for_loop(train_epoch, jnp.arange(25))
|
|
128
|
-
final_loss = evaluate()
|
|
129
|
-
|
|
130
|
-
assert losses.shape == (25,)
|
|
131
|
-
assert final_loss < initial_loss
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
Open `references/batching.md` before adding a batch axis or mapping wrapper; it identifies which API must own mapping. Do not wrap `etrace_grad()` or `etrace_evolve()` in another time scan, and make `step_fn` call the learner exactly once.
|
|
135
|
-
|
|
136
|
-
## Reference routing
|
|
137
|
-
|
|
138
|
-
Escalate model construction from prebuilt layers to built-in ETP operations, then to a custom ETP primitive only when the previous level cannot express the computation.
|
|
139
|
-
|
|
140
|
-
| Reference | Open when | Contains |
|
|
141
|
-
|---|---|---|
|
|
142
|
-
| `references/pre-built-braintrace-layer.md` | Selecting another ETP-aware layer or composing the default model. | Layer families, parameterized-operation choices, and BrainState-owned supporting layers. |
|
|
143
|
-
| `references/Drtrl.md` | Using or validating parameter-shaped D-RTRL traces. | Memory scaling, recurrence, sequence resets, and the BPTT comparison boundary. |
|
|
144
|
-
| `references/pp_pprop workflow.md` | Parameter-shaped traces are too costly or a recurrent SNN needs factorized traces. | Input/output factorization, decay selection, SNN integration, and validation. |
|
|
145
|
-
| `references/algorithm selection.md` | Neither canonical memory strategy fits the estimator requirements. | Other built-in estimators, guarantees, configuration axes, and sequence-driver options. |
|
|
146
|
-
| `references/batching.md` | Adding a batch axis, mapped model, or multi-step wrapper. | Mapping ownership, batched compilation, State layout, and sequence-data wrappers. |
|
|
147
|
-
| `references/ETP operators.md` | A prebuilt layer cannot express the required parameterized operation. | Built-in ETP operations, participation rules, units, and transform behavior. |
|
|
148
|
-
| `references/custom ETP primitives.md` | No built-in ETP operation can express the computation. | Primitive registration, ETP rules, compiler integration, and validation. |
|
|
149
|
-
| `references/customizing_primitive_transforms.md` | An ETP weight needs masking, constraints, normalization, LoRA, or a bias transform. | Transform hooks and raw-parameter gradient attachment. |
|
|
150
|
-
| `references/custom algorithms.md` | No built-in algorithm or `ETraceConfig` expresses the research method. | Estimator bases, trace lifecycle, solve hooks, and inspection. |
|
|
151
|
-
| `references/compiler_internal.md` | `learner.report` and `learner.graph` cannot explain custom graph behavior. | Discovery, graph execution, control-flow policy, and low-level diagnostics. |
|
|
152
|
-
|
|
153
|
-
## Boundaries and common failures
|
|
154
|
-
|
|
155
|
-
- Do not describe BrainTrace as constant-total-memory training. Its memory is constant only in sequence length; trace storage still scales with the selected estimator and model.
|
|
156
|
-
- Do not claim that an online estimator equals BPTT unless its documented mathematical regime and a reduced gradient-oracle comparison establish that result.
|
|
157
|
-
- Do not compile inside training or compile from a full sequence; pass one representative time step with the real batch and feature shape.
|
|
158
|
-
- Do not treat every excluded weight as an error. A readout that does not feed hidden State is correctly reported as non-temporal and still receives instantaneous gradients.
|
|
159
|
-
- Reset both recurrent State and eligibility State between independent sequences.
|
|
160
|
-
- Use exactly one batching owner; do not map an already mapped model again in `braintrace.compile()`.
|
|
161
|
-
- Use `pp_prop` in new code; `ES_D_RTRL` is its compatibility alias.
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
# D-RTRL
|
|
2
|
-
|
|
3
|
-
Use this reference when implementing or validating the canonical
|
|
4
|
-
parameter-dimensional D-RTRL workflow, including sequence resets, online
|
|
5
|
-
gradient accumulation, and comparison with BPTT. Open `algorithm selection.md`
|
|
6
|
-
when deciding among estimators and `batching.md` before adding a batch axis.
|
|
7
|
-
|
|
8
|
-
## Understand the approximation
|
|
9
|
-
|
|
10
|
-
`D_RTRL` carries parameter-dimensional eligibility traces forward while its
|
|
11
|
-
default diagonal recurrence drops cross-hidden terms from the
|
|
12
|
-
hidden-to-hidden Jacobian.
|
|
13
|
-
|
|
14
|
-
| API | Description |
|
|
15
|
-
|---|---|
|
|
16
|
-
| `braintrace.D_RTRL` | Use when parameter-shaped trace memory is feasible. It computes approximate gradients during the forward sequence without retaining the full unrolled graph. |
|
|
17
|
-
| `braintrace.compile(model, braintrace.D_RTRL, example_input, ...)` | Use as the normal one-call setup. It constructs the learner and compiles its ETP graph from the representative step. |
|
|
18
|
-
| `learner.etrace_evolve(inputs, return_outputs=...)` | Use for evaluation or a loss-free prefix. It advances hidden and eligibility State without accumulating a loss gradient. |
|
|
19
|
-
| `learner.etrace_grad(inputs, *targets, step_fn=..., ...)` | Use for online sequence gradients. It owns the temporal loop, accumulation, masking, and reduction. |
|
|
20
|
-
|
|
21
|
-
Trace memory scales as `O(B * |theta|)`, where `B` is batch size and `theta` is
|
|
22
|
-
the participating parameter set. Wide recurrent layers can therefore be
|
|
23
|
-
memory-intensive even though memory does not grow with sequence length.
|
|
24
|
-
|
|
25
|
-
**Guarantee:** Do not describe D-RTRL as generally identical to BPTT. Equality
|
|
26
|
-
depends on the configured recurrence, VJP path, and mathematical regime being
|
|
27
|
-
tested.
|
|
28
|
-
|
|
29
|
-
## Follow the sequence lifecycle
|
|
30
|
-
|
|
31
|
-
Reset recurrent and eligibility State together at each independent sequence;
|
|
32
|
-
then let the learner drive the complete sequence and update parameters once.
|
|
33
|
-
|
|
34
|
-
| Step | Action | Important result |
|
|
35
|
-
|---|---|---|
|
|
36
|
-
| 1. Build | Compose ETP-aware recurrent and readout layers. | Participating parameter-to-hidden paths remain visible to the compiler. |
|
|
37
|
-
| 2. Compile | Call `braintrace.compile(...)` once with a representative input. | The learner reuses one compiled ETP graph across training epochs. |
|
|
38
|
-
| 3. Register | Give the optimizer the model's trainable `ParamState` collection. | Gradient keys and optimizer weights refer to the same State objects. |
|
|
39
|
-
| 4. Reset | Call `brainstate.nn.reset_all_states(...)` and `learner.reset_state(...)`. | Hidden State, eligibility traces, and the learner's running index start at the same boundary. |
|
|
40
|
-
| 5. Drive | Define a local loss that calls the learner exactly once, then call `etrace_grad()`. | The learner accumulates per-step online gradients. |
|
|
41
|
-
| 6. Update | Apply the returned gradients and verify descent on a deterministic task. | A lower loss checks training mechanics, not BPTT equivalence. |
|
|
42
|
-
|
|
43
|
-
## Train a deterministic MiniGRU
|
|
44
|
-
|
|
45
|
-
Use the same small model and affine sequence task as the official pp-prop
|
|
46
|
-
walkthrough when comparing estimators; changing only the algorithm isolates the
|
|
47
|
-
trace rule.
|
|
48
|
-
|
|
49
|
-
```python
|
|
50
|
-
import brainstate
|
|
51
|
-
import braintools
|
|
52
|
-
import braintrace
|
|
53
|
-
import jax.numpy as jnp
|
|
54
|
-
|
|
55
|
-
brainstate.random.seed(7)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
class SequenceModel(brainstate.nn.Module):
|
|
59
|
-
def __init__(self):
|
|
60
|
-
super().__init__()
|
|
61
|
-
self.rnn = braintrace.nn.MiniGRU(in_size=1, out_size=6)
|
|
62
|
-
self.readout = braintrace.nn.Linear(6, 1)
|
|
63
|
-
|
|
64
|
-
def update(self, x):
|
|
65
|
-
return self.readout(self.rnn(x))
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
model = SequenceModel()
|
|
69
|
-
inputs = jnp.linspace(-1.0, 1.0, 12).reshape(12, 1, 1)
|
|
70
|
-
targets = 0.7 * inputs + 0.2
|
|
71
|
-
|
|
72
|
-
learner = braintrace.compile(
|
|
73
|
-
model,
|
|
74
|
-
braintrace.D_RTRL,
|
|
75
|
-
inputs[0],
|
|
76
|
-
batch_size=1,
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
weights = model.states(brainstate.ParamState)
|
|
80
|
-
optimizer = braintools.optim.SGD(lr=0.08)
|
|
81
|
-
optimizer.register_trainable_weights(weights)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
def reset_sequence():
|
|
85
|
-
brainstate.nn.reset_all_states(model, batch_size=1)
|
|
86
|
-
learner.reset_state(batch_size=1)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
def evaluate():
|
|
90
|
-
reset_sequence()
|
|
91
|
-
predictions = learner.etrace_evolve(inputs, return_outputs=True)
|
|
92
|
-
return jnp.mean((predictions - targets) ** 2)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
def local_loss(x, target):
|
|
96
|
-
prediction = learner(x)
|
|
97
|
-
return jnp.mean((prediction - target) ** 2)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def train_epoch(_):
|
|
101
|
-
reset_sequence()
|
|
102
|
-
grads, step_losses = learner.etrace_grad(
|
|
103
|
-
inputs,
|
|
104
|
-
targets,
|
|
105
|
-
step_fn=local_loss,
|
|
106
|
-
reduction='mean',
|
|
107
|
-
return_value=True,
|
|
108
|
-
)
|
|
109
|
-
optimizer.update(grads)
|
|
110
|
-
return step_losses.mean()
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
initial_loss = evaluate()
|
|
114
|
-
training_losses = brainstate.transform.for_loop(
|
|
115
|
-
train_epoch,
|
|
116
|
-
jnp.arange(25),
|
|
117
|
-
)
|
|
118
|
-
final_loss = evaluate()
|
|
119
|
-
|
|
120
|
-
assert final_loss < initial_loss
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
`reduction='mean'` divides by the total mask weight, which is the number of
|
|
124
|
-
steps when no mask is supplied. `local_loss` must call `learner` exactly once;
|
|
125
|
-
`etrace_grad()` owns every other part of the sequence loop.
|
|
126
|
-
|
|
127
|
-
## Reset both State domains
|
|
128
|
-
|
|
129
|
-
The model and learner carry different temporal information, so resetting only
|
|
130
|
-
one invalidates independent-sequence comparisons.
|
|
131
|
-
|
|
132
|
-
| API | State reset |
|
|
133
|
-
|---|---|
|
|
134
|
-
| `brainstate.nn.reset_all_states(model, batch_size=1)` | Resets the MiniGRU hidden State. |
|
|
135
|
-
| `learner.reset_state(batch_size=1)` | Resets eligibility traces and the learner's running index. |
|
|
136
|
-
|
|
137
|
-
Consecutive `etrace_evolve()` or `etrace_grad()` calls otherwise continue from
|
|
138
|
-
the currently installed State. Preserve that continuation only when the calls
|
|
139
|
-
belong to one trajectory.
|
|
140
|
-
|
|
141
|
-
## Interpret compiler participation
|
|
142
|
-
|
|
143
|
-
A parameter participates in temporal learning only when an ETP primitive marks
|
|
144
|
-
its path to hidden State.
|
|
145
|
-
|
|
146
|
-
| Situation | Interpretation |
|
|
147
|
-
|---|---|
|
|
148
|
-
| Recurrent weight reaches hidden State through an ETP primitive. | The compiler records a temporal relation and D-RTRL carries its eligibility trace. |
|
|
149
|
-
| Readout does not feed hidden State. | The parameter remains trainable but is correctly reported as non-temporal; its instantaneous gradient does not require a recurrent trace. |
|
|
150
|
-
| A weight reaches hidden State only through another trainable ETP weight. | The compiler excludes the upstream weight under the non-parametric-tail invariant to prevent double counting. |
|
|
151
|
-
|
|
152
|
-
Open `ETP operators.md` when a custom layer's parameter is unexpectedly absent.
|
|
153
|
-
Treat a documented non-temporal or excluded relation as a diagnostic, not an
|
|
154
|
-
optimizer failure.
|
|
155
|
-
|
|
156
|
-
## Keep the BPTT boundary explicit
|
|
157
|
-
|
|
158
|
-
| Property | D-RTRL | BPTT |
|
|
159
|
-
|---|---|---|
|
|
160
|
-
| Gradient timing | Updates eligibility information during the forward sequence. | Backpropagates after unrolling the sequence. |
|
|
161
|
-
| Sequence storage | Does not retain the full unrolled graph. | Stores intermediate activations, so memory grows with sequence length. |
|
|
162
|
-
| Gradient claim | Uses the configured diagonal recurrence and VJP approximations. | Provides the full-sequence baseline for a matched model and loss. |
|
|
163
|
-
|
|
164
|
-
Use a reduced matched task as a BPTT oracle only when the estimator's
|
|
165
|
-
mathematical regime predicts equality. A descending D-RTRL loss verifies the
|
|
166
|
-
workflow but does not establish gradient equality.
|
|
167
|
-
|
|
168
|
-
For explicit `brainstate.nn.Map` setup, compile directly with
|
|
169
|
-
`braintrace.D_RTRL(mapped_model).compile_graph(batched_step)` and follow
|
|
170
|
-
`batching.md`; never map an already mapped model again with `vmap=True`.
|
|
171
|
-
|
|
172
|
-
## Sources
|
|
173
|
-
|
|
174
|
-
- [RNN Online Learning](https://brainx.chaobrain.com/braintrace/tutorials/rnn_online_learning.html)
|
|
175
|
-
- [D-RTRL: diagonal online gradient learning](https://brainx.chaobrain.com/braintrace/tutorials/drtrl.html)
|
|
176
|
-
|
|
177
|
-
The lifecycle, approximation boundary, examples, and diagnostics above are
|
|
178
|
-
trimmed and reorganized from the official pages without changing their API
|
|
179
|
-
names or guarantees.
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
# Algorithm selection
|
|
2
|
-
|
|
3
|
-
Use this reference when choosing a BrainTrace estimator beyond the default
|
|
4
|
-
`D_RTRL`, expressing a learning rule with `ETraceConfig`, or selecting sequence
|
|
5
|
-
driver options. Use `Drtrl.md` or `pp_pprop workflow.md` for estimator-specific
|
|
6
|
-
training workflows; use `custom algorithms.md` only when no built-in rule or
|
|
7
|
-
configuration expresses the method.
|
|
8
|
-
|
|
9
|
-
## Choose an estimator
|
|
10
|
-
|
|
11
|
-
Choose by trace representation, recurrence approximation, learning signal, and
|
|
12
|
-
the mathematical regime in which the estimator is valid.
|
|
13
|
-
|
|
14
|
-
| API | Use when | Essential behavior and constraint |
|
|
15
|
-
|---|---|---|
|
|
16
|
-
| `D_RTRL` | Use as the general-purpose RNN default when parameter-dimensional trace memory fits. | Uses a diagonal hidden-to-hidden Jacobian approximation. Memory is `O(B * |theta|)` and computation is `O(B * I * O)`; it is not generally gradient-equivalent to BPTT outside that approximation's assumptions. |
|
|
17
|
-
| `pp_prop` | Use when parameter-dimensional traces are too large, especially for large or memory-constrained SNNs. | Factorizes each eligibility trace into input and output components with exponential smoothing. Memory is `O(B * (I + O))`; an integer `decay_or_rank` controls decay and does not allocate multiple rank factors. Prefer this name over its historical alias, `ES_D_RTRL`. |
|
|
18
|
-
| `SnAp` | Use when the recurrent position graph is structurally sparse over the requested `n`-step neighborhood. | Retains recurrent influence entries reachable within that neighborhood. Dense recurrence saturates the neighborhood immediately and removes the method's structural advantage. |
|
|
19
|
-
| `UORO` | Use when an unbiased RTRL-trace estimate is required and projection variance is acceptable. | Carries a rank-one random projection of the full recurrent Jacobian, trading variance for linear carrier storage. |
|
|
20
|
-
| `ThreeFactor` | Use for reward-modulated learning with a user-supplied modulatory signal. | Replaces the symmetric hidden-state learning signal with that external signal. |
|
|
21
|
-
| `DNI` | Use to carry credit across finite online windows with learned synthetic gradients. | Uses `SyntheticGradient` as a per-hidden-group predictor; update it with `train_synthetic_gradient()`. |
|
|
22
|
-
| `EProp` | Use for recurrent SNNs that need kappa-filtered traces or fixed random-feedback learning signals. | Implements eligibility propagation with optional kappa filtering and random feedback. |
|
|
23
|
-
| `OSTLRecurrent` | Use for the OSTL with-H recurrent regime. | Keeps the recurrent Jacobian and is RTRL-exact only for block-diagonal hidden-to-hidden Jacobians. |
|
|
24
|
-
| `OSTLFeedforward` | Use for the OSTL without-H feedforward regime. | Drops the recurrent Jacobian and uses the input/output-factorized trace path. |
|
|
25
|
-
|
|
26
|
-
**Correctness invariant:** Treat estimator guarantees as part of algorithm
|
|
27
|
-
selection. Exact rules must match a BPTT oracle element-wise; approximate rules
|
|
28
|
-
match BPTT only in the mathematical regime documented for that rule.
|
|
29
|
-
|
|
30
|
-
## Configure rule coordinates
|
|
31
|
-
|
|
32
|
-
Named algorithms are presets in a shared rule space; use `ETraceConfig` when
|
|
33
|
-
the required coordinate combination has no preset name.
|
|
34
|
-
|
|
35
|
-
| Axis | Values and selection rule |
|
|
36
|
-
|---|---|
|
|
37
|
-
| `trace_factorization` | Use `'per_param'` for parameter-dimensional traces or `'io_factorized'` for `O(I + O)` factorized traces. |
|
|
38
|
-
| `temporal_recursion` | Choose `'jacobian'`, `'scalar_leak'`, or `'none'`; under `'io_factorized'`, provide the `(x, f)` pair when the two sides differ. |
|
|
39
|
-
| `recurrence_scope` | Choose `'diagonal'` or `'coupled'`; `SnAp` uses `'sparse_n'` with `sparse_n=n`. |
|
|
40
|
-
| `learning_signal` | Use `'symmetric'` for the normal signal or `'random_feedback'` for fixed random feedback. |
|
|
41
|
-
| `trace_filter` | Use `'none'` normally or `'kappa'` for kappa-filtered traces. |
|
|
42
|
-
| `update_schedule` | Use the supported `'per_step'` schedule. |
|
|
43
|
-
|
|
44
|
-
The named presets occupy these coordinates:
|
|
45
|
-
|
|
46
|
-
| Preset | Non-default coordinates |
|
|
47
|
-
|---|---|
|
|
48
|
-
| `D_RTRL` | Default coordinate. |
|
|
49
|
-
| `pp_prop` / `ES_D_RTRL` | `trace_factorization='io_factorized'`, `decay=<decay_or_rank>`. |
|
|
50
|
-
| `EProp` | `trace_filter='kappa'`, `kappa=<kappa_filter_decay>`; with `feedback='random'`, also `learning_signal='random_feedback'`. |
|
|
51
|
-
| `OSTLRecurrent` | `recurrence_scope='coupled'`. |
|
|
52
|
-
| `OSTLFeedforward` | `trace_factorization='io_factorized'`, with `decay=1e-6` by default. |
|
|
53
|
-
| `SnAp` | `recurrence_scope='sparse_n'`, `sparse_n=n`. |
|
|
54
|
-
|
|
55
|
-
```python
|
|
56
|
-
# Use different temporal recursion on the input and output sides.
|
|
57
|
-
learner = braintrace.compile(
|
|
58
|
-
model,
|
|
59
|
-
braintrace.ETraceConfig(
|
|
60
|
-
trace_factorization='io_factorized',
|
|
61
|
-
temporal_recursion=('scalar_leak', 'none'),
|
|
62
|
-
decay=(0.9, 0.0),
|
|
63
|
-
),
|
|
64
|
-
x0,
|
|
65
|
-
)
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
**Configuration invariant:** Construction rejects illegal coordinate
|
|
69
|
-
combinations and names the legal pairings. It also canonicalizes equivalent
|
|
70
|
-
rules; for example, zero decay collapses to `temporal_recursion='none'`.
|
|
71
|
-
|
|
72
|
-
## Drive a sequence
|
|
73
|
-
|
|
74
|
-
Compile once, then let the learner own temporal iteration, State continuation,
|
|
75
|
-
loss masking, and gradient accumulation.
|
|
76
|
-
|
|
77
|
-
| API | Description |
|
|
78
|
-
|---|---|
|
|
79
|
-
| `braintrace.compile(model, algorithm, example_input, ...)` | Use as the one-call entry point. It constructs the selected algorithm, eagerly compiles its eligibility-trace graph from the example input, and returns the ready-to-run learner. |
|
|
80
|
-
| `learner.etrace_evolve(inputs, ...)` | Use for a loss-free prefix or other forward-only interval. It advances both hidden and eligibility State and leaves the final State installed. |
|
|
81
|
-
| `learner.etrace_grad(inputs, *step_args, step_fn=..., ...)` | Use for a training interval. It owns the temporal loop, calls `step_fn` once per step or chunk, accumulates online gradients, and optionally returns per-step values. |
|
|
82
|
-
|
|
83
|
-
```python
|
|
84
|
-
learner = braintrace.compile(model, 'd_rtrl', inputs[0], batch_size=1)
|
|
85
|
-
|
|
86
|
-
def step_loss(inp, target):
|
|
87
|
-
prediction = learner(inp)
|
|
88
|
-
return braintools.metric.squared_error(prediction, target).mean()
|
|
89
|
-
|
|
90
|
-
# Advance a loss-free prefix without resetting the trajectory.
|
|
91
|
-
learner.etrace_evolve(inputs[:n_warmup])
|
|
92
|
-
|
|
93
|
-
grads, step_losses = learner.etrace_grad(
|
|
94
|
-
inputs[n_warmup:],
|
|
95
|
-
targets[n_warmup:],
|
|
96
|
-
step_fn=step_loss,
|
|
97
|
-
return_value=True,
|
|
98
|
-
)
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
`step_fn` owns the learner call and must call `learner` exactly once per
|
|
102
|
-
invocation. Both drivers are continuations: they leave final State installed,
|
|
103
|
-
so consecutive calls compose into one trajectory and neither call implies a
|
|
104
|
-
reset.
|
|
105
|
-
|
|
106
|
-
| Driver option | Use and effect |
|
|
107
|
-
|---|---|
|
|
108
|
-
| `mask=...` | Use to gate loss contributions. The learner still runs at every step, so a zero-weighted prefix is equivalent to calling `etrace_evolve()` over that prefix. |
|
|
109
|
-
| `chunk_size=1` | Use for the normal single-step path. |
|
|
110
|
-
| `chunk_size=k` with `k >= 2` | Use when `step_fn` consumes `(k, ...)` windows. Set `vjp_method='multi-step'`. |
|
|
111
|
-
| `braintrace.compile(..., vmap=True)` | Use when compilation should own batch mapping. Call `etrace_grad()` and `etrace_evolve()` on the returned wrapper, not on `learner.module`, or the mapped lanes are bypassed. |
|
|
112
|
-
|
|
113
|
-
Open `batching.md` before adding a batch axis. Open `custom algorithms.md` when
|
|
114
|
-
the six configuration axes cannot express the research method.
|
|
115
|
-
|
|
116
|
-
## Source
|
|
117
|
-
|
|
118
|
-
[Online-Learning Algorithms](https://brainx.chaobrain.com/braintrace/apis/algorithms.html).
|
|
119
|
-
The selection rules, coordinate values, examples, and invariants above are
|
|
120
|
-
condensed from the official page's prose, API tables, and code blocks.
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
# Batching
|
|
2
|
-
|
|
3
|
-
Use this reference when adding a batch axis to BrainTrace online learning,
|
|
4
|
-
choosing which API owns mapping, compiling from a batched example, or wrapping
|
|
5
|
-
single-step and multi-step inputs. Keep model update logic single-sample and
|
|
6
|
-
assign batch mapping to exactly one API.
|
|
7
|
-
|
|
8
|
-
## Choose one mapping owner
|
|
9
|
-
|
|
10
|
-
Map-based batching keeps parameters shared while giving each batch lane an
|
|
11
|
-
independent copy of recurrent State.
|
|
12
|
-
|
|
13
|
-
| Path | Use when | Mapping owner |
|
|
14
|
-
|---|---|---|
|
|
15
|
-
| Explicit map | Use for the recommended path when mapping and State initialization must be visible. | Create one `brainstate.nn.Map`; construct the algorithm around it directly. |
|
|
16
|
-
| Compile-owned map | Use when the one-call compiler should create the wrapper. | Pass an unmapped model to `braintrace.compile(..., vmap=True)`. |
|
|
17
|
-
| Single stream | Use for one stream or step-by-step debugging. | Use an unmapped model and unbatched example; no API owns a batch transformation. |
|
|
18
|
-
|
|
19
|
-
**Mapping invariant:** Use exactly one mapping owner. Never pass an existing
|
|
20
|
-
`brainstate.nn.Map` to `braintrace.compile(..., vmap=True)` because that maps
|
|
21
|
-
the model twice.
|
|
22
|
-
|
|
23
|
-
## Map and compile a batch
|
|
24
|
-
|
|
25
|
-
Create and initialize one `Map`, construct the algorithm with that mapped
|
|
26
|
-
model, then compile from one complete batched time step.
|
|
27
|
-
|
|
28
|
-
| API | Description |
|
|
29
|
-
|---|---|
|
|
30
|
-
| `brainstate.nn.Map(model, init_map_size=B)` | Use to replicate mutable model State across `B` lanes while sharing parameter State. |
|
|
31
|
-
| `mapped_model.init_all_states()` | Use before algorithm construction to initialize the independent recurrent State copies. |
|
|
32
|
-
| `braintrace.D_RTRL(mapped_model)` | Use to construct the selected algorithm directly around an explicitly mapped model. |
|
|
33
|
-
| `mapped_algo.compile_graph(example_input)` | Use once with an example shaped `(batch_size, n_in)` so the batch axis remains inside the compiled ETP graph. |
|
|
34
|
-
|
|
35
|
-
```python
|
|
36
|
-
import jax.numpy as jnp
|
|
37
|
-
import brainstate
|
|
38
|
-
import braintrace
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
class SimpleGRU(brainstate.nn.Module):
|
|
42
|
-
def __init__(self, n_in, n_rec, n_out):
|
|
43
|
-
super().__init__()
|
|
44
|
-
self.rnn = braintrace.nn.GRUCell(n_in, n_rec)
|
|
45
|
-
self.out = braintrace.nn.Linear(n_rec, n_out)
|
|
46
|
-
|
|
47
|
-
def update(self, x):
|
|
48
|
-
return self.out(self.rnn(x))
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
model = SimpleGRU(10, 64, 5)
|
|
52
|
-
batch_size = 16
|
|
53
|
-
example_input = jnp.zeros((batch_size, 10))
|
|
54
|
-
|
|
55
|
-
mapped_model = brainstate.nn.Map(model, init_map_size=batch_size)
|
|
56
|
-
mapped_model.init_all_states()
|
|
57
|
-
|
|
58
|
-
mapped_algo = braintrace.D_RTRL(mapped_model)
|
|
59
|
-
mapped_algo.compile_graph(example_input)
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
The mapped learner applies the wrapped single-sample update over axis 0. Its
|
|
63
|
-
parameters remain shared and its recurrent State remains independent across
|
|
64
|
-
lanes; an input shaped `(16, 10)` produces an output shaped `(16, 5)` for this
|
|
65
|
-
model.
|
|
66
|
-
|
|
67
|
-
## Train over time-major batches
|
|
68
|
-
|
|
69
|
-
Keep time on axis 0 and the batch on axis 1, then let the learner's sequence
|
|
70
|
-
driver own the temporal scan and gradient accumulation.
|
|
71
|
-
|
|
72
|
-
| API | Description |
|
|
73
|
-
|---|---|
|
|
74
|
-
| `mapped_algo.etrace_grad(inputs, ..., step_fn=..., reduction=...)` | Use for online gradients over time-major input. It calls `step_fn` across axis 0 and returns gradient keys matching `mapped_algo.param_states`. |
|
|
75
|
-
| `mapped_algo.etrace_evolve(inputs, ...)` | Use for loss-free sequence evolution. It advances every mapped lane without accumulating a loss gradient. |
|
|
76
|
-
| `reduction='sum'` | Use when accumulated per-step gradients must not be divided by the number of steps. |
|
|
77
|
-
|
|
78
|
-
```python
|
|
79
|
-
@brainstate.transform.jit
|
|
80
|
-
def train_step(inputs, targets):
|
|
81
|
-
"""inputs: (n_steps, batch_size, n_in); targets: (batch_size, n_out)."""
|
|
82
|
-
def step_loss(inp):
|
|
83
|
-
prediction = mapped_algo(inp)
|
|
84
|
-
return jnp.mean((prediction - targets) ** 2)
|
|
85
|
-
|
|
86
|
-
return mapped_algo.etrace_grad(
|
|
87
|
-
inputs,
|
|
88
|
-
step_fn=step_loss,
|
|
89
|
-
reduction='sum',
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
inputs = jnp.ones((20, 16, 10))
|
|
94
|
-
targets = jnp.zeros((16, 5))
|
|
95
|
-
grads = train_step(inputs, targets)
|
|
96
|
-
# Register mapped_algo.param_states with the optimizer that consumes grads.
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
`step_fn` must call `mapped_algo` exactly once. Call `etrace_grad()` and
|
|
100
|
-
`etrace_evolve()` on the mapped learner itself; accessing a wrapped `.module`
|
|
101
|
-
bypasses mapped lanes.
|
|
102
|
-
|
|
103
|
-
## Use single-sample mode
|
|
104
|
-
|
|
105
|
-
Use an unbatched model when processing one stream or diagnosing a single step;
|
|
106
|
-
do not create a `Map` or request `vmap`.
|
|
107
|
-
|
|
108
|
-
```python
|
|
109
|
-
single_model = SimpleGRU(10, 64, 5)
|
|
110
|
-
single_algo = braintrace.compile(
|
|
111
|
-
single_model,
|
|
112
|
-
braintrace.D_RTRL,
|
|
113
|
-
jnp.zeros(10),
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
output = single_algo(jnp.ones(10))
|
|
117
|
-
assert output.shape == (5,)
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
Omitting `batch_size` keeps model State unbatched and the example input contains
|
|
121
|
-
only the feature axis.
|
|
122
|
-
|
|
123
|
-
## Wrap temporal data
|
|
124
|
-
|
|
125
|
-
Use data wrappers to distinguish one forward step from an input whose first
|
|
126
|
-
axis is time.
|
|
127
|
-
|
|
128
|
-
| API | Description |
|
|
129
|
-
|---|---|
|
|
130
|
-
| `braintrace.SingleStepData(data)` | Use to mark `data` as one forward step. A plain array has the same single-step interpretation. |
|
|
131
|
-
| `braintrace.MultiStepData(sequence)` | Use to mark axis 0 as time. The algorithm scans that axis internally instead of treating the complete sequence as one step. |
|
|
132
|
-
|
|
133
|
-
```python
|
|
134
|
-
one_step = braintrace.SingleStepData(jnp.ones(10))
|
|
135
|
-
many_steps = braintrace.MultiStepData(jnp.ones((20, 10)))
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
For mapped data, preserve the same axis meaning: a complete time-major sequence
|
|
139
|
-
has shape `(n_steps, batch_size, n_in)`, and each compiled step has shape
|
|
140
|
-
`(batch_size, n_in)`.
|
|
141
|
-
|
|
142
|
-
Open `algorithm selection.md` when batching cost changes the estimator choice.
|
|
143
|
-
Open `Drtrl.md` or `pp_pprop workflow.md` for estimator-specific State reset and
|
|
144
|
-
training behavior.
|
|
145
|
-
|
|
146
|
-
## Source
|
|
147
|
-
|
|
148
|
-
[Batching Strategies](https://brainx.chaobrain.com/braintrace/advanced/batching.html).
|
|
149
|
-
The ownership rules, workflows, shapes, and wrapper behavior above are
|
|
150
|
-
condensed from the official page's prose and code blocks.
|