brainx-skill 1.0.11 → 1.0.12
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/package.json +1 -1
- package/skills/braincell/SKILL.md +1 -15
- package/skills/braincell/references/mixions-for-adaptation.md +26 -3
- package/skills/braincell/references/scripts/spike_frequency_adaptation.py +113 -53
- package/skills/brainevent/SKILL.md +0 -1
- package/skills/brainevent/references/synaptic-plasticity.md +74 -230
- package/skills/brainmass/SKILL.md +10 -5
- package/skills/brainmass/references/batch-transform-acceleration.md +44 -3
- package/skills/brainmass/references/modellibrary.md +11 -0
- package/skills/brainmass/references/simulator-input-monitor-api.md +98 -0
- package/skills/brainpy-state/SKILL.md +14 -6
- package/skills/brainpy-state/references/array-creation.md +2 -2
- package/skills/brainpy-state/references/brain-dynamics-delay-protocol.md +52 -1
- package/skills/brainpy-state/references/braintools/connectivity.md +206 -0
- package/skills/brainpy-state/references/braintools/input-current.md +199 -0
- package/skills/brainpy-state/references/component-selection.md +20 -5
- package/skills/brainpy-state/references/projection-patterns.md +2 -0
- package/skills/brainpy-state/references/scripts/sound_localization.py +240 -0
- package/skills/brainstate/SKILL.md +11 -15
- package/skills/brainstate/agents/openai.yaml +4 -0
- package/skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +8 -0
- package/skills/brainstate/references/brainstate/transformation-grad-expansion.md +1 -1
- package/skills/brainstate/references/brainstate/transformation-vmap-expansion.md +57 -7
- package/skills/brainstate/references/collective_model_operations.md +26 -27
- package/skills/brainx-general-guard/SKILL.md +62 -37
- package/skills/brainx-install/SKILL.md +21 -24
- package/skills/brainstate/references/braintools/optimizer.md +0 -179
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
# Braintools optimizer selection
|
|
2
|
-
|
|
3
|
-
Use this reference after the BrainState loss, `ParamState` selection, and gradient target are correct. Select an optimizer interface and learning-rate policy without changing the Module graph or confusing gradient-step optimizers with standalone search wrappers.
|
|
4
|
-
|
|
5
|
-
## Choose a gradient optimizer
|
|
6
|
-
|
|
7
|
-
Choose the optimizer family by training regime and resource constraint. Ordinary reverse-mode optimizers register the selected `ParamState` tree once and accept the matching gradient tree through `update(grads)`.
|
|
8
|
-
|
|
9
|
-
### General minibatch optimizers
|
|
10
|
-
|
|
11
|
-
Use these optimizers for ordinary repeated gradient steps; establish `Adam` or `SGD` as the baseline before selecting a specialized update rule.
|
|
12
|
-
|
|
13
|
-
| API | Description |
|
|
14
|
-
|---|---|
|
|
15
|
-
| `SGD(...)` | Use for stochastic gradient descent with optional momentum and weight decay when a simple non-adaptive baseline is required. |
|
|
16
|
-
| `Momentum(...)` | Use for momentum updates without selecting the broader `SGD` interface. |
|
|
17
|
-
| `MomentumNesterov(...)` | Use when the optimization method requires Nesterov-accelerated momentum. |
|
|
18
|
-
| `Adam(...)` | Use as the canonical adaptive default after validating finite, nonzero gradients. |
|
|
19
|
-
| `AdamW(...)` | Use when the training policy requires decoupled weight decay; set `weight_decay` deliberately. |
|
|
20
|
-
| `Adagrad(...)` | Use when per-parameter learning rates should accumulate squared-gradient history. |
|
|
21
|
-
| `Adadelta(...)` | Use when the Adadelta extension of Adagrad is explicitly required. |
|
|
22
|
-
| `RMSprop(...)` | Use when the method should scale updates by a moving average of squared gradients. |
|
|
23
|
-
| `Adamax(...)` | Use when the infinity-norm Adam variant is required. |
|
|
24
|
-
| `Nadam(...)` | Use when combining Adam with Nesterov acceleration. |
|
|
25
|
-
| `RAdam(...)` | Use when rectifying adaptive learning-rate variance addresses observed early-step instability. |
|
|
26
|
-
| `Yogi(...)` | Use when the Yogi additive second-moment update is part of the intended method. |
|
|
27
|
-
| `Rprop(...)` | Use when resilient backpropagation should adapt per-parameter step sizes from gradient signs. |
|
|
28
|
-
| `AdaBelief(...)` | Use when adapting step size from the optimizer's belief in the gradient direction is required. |
|
|
29
|
-
| `Lion(...)` | Use when a sign-momentum optimizer is chosen to reduce optimizer-State memory. |
|
|
30
|
-
| `Novograd(...)` | Use when layer-wise gradient normalization with momentum is required. |
|
|
31
|
-
| `Fromage(...)` | Use only when the Free-scale Optimal Method for Adaptive Gradient method is explicitly selected. |
|
|
32
|
-
|
|
33
|
-
### Large-scale and memory-efficient optimizers
|
|
34
|
-
|
|
35
|
-
Use these optimizers only when large-batch scaling or optimizer-State memory is an explicit constraint.
|
|
36
|
-
|
|
37
|
-
| API | Description |
|
|
38
|
-
|---|---|
|
|
39
|
-
| `Lamb(...)` | Use for layer-wise adaptive moments in an explicitly large-batch training regime. |
|
|
40
|
-
| `Lars(...)` | Use for layer-wise adaptive rate scaling in an explicitly large-batch training regime. |
|
|
41
|
-
| `Adafactor(...)` | Use when factorized second-moment estimates are needed to reduce optimizer-State memory. |
|
|
42
|
-
| `SM3(...)` | Use for memory-efficient adaptive updates in a large or sparse model. |
|
|
43
|
-
|
|
44
|
-
### Wrapper and full-batch optimizers
|
|
45
|
-
|
|
46
|
-
Use these variants when the update requires an optimizer composition or a smooth full-batch objective rather than an ordinary standalone minibatch rule.
|
|
47
|
-
|
|
48
|
-
| API | Description |
|
|
49
|
-
|---|---|
|
|
50
|
-
| `Lookahead(...)` | Use when wrapping an inner Optax gradient transformation with periodic slow-weight interpolation. |
|
|
51
|
-
| `LBFGS(...)` | Use for a small, smooth, full-batch problem suited to limited-memory quasi-Newton updates; verify its step contract before replacing a minibatch optimizer. |
|
|
52
|
-
|
|
53
|
-
### Custom Optax transformations
|
|
54
|
-
|
|
55
|
-
Use the bridge when no named Braintools optimizer expresses the required Optax transformation.
|
|
56
|
-
|
|
57
|
-
| API | Description |
|
|
58
|
-
|---|---|
|
|
59
|
-
| `OptaxOptimizer(tx=..., lr=...)` | Use when supplying a custom Optax transformation while preserving Braintools parameter registration, optimizer State, gradient clipping, weight decay, and scheduler integration. |
|
|
60
|
-
|
|
61
|
-
Do not switch optimizer, scheduler, and loss reduction simultaneously. Establish an `Adam` loss and gradient baseline, then vary one optimization decision.
|
|
62
|
-
|
|
63
|
-
## Gradient-step lifecycle
|
|
64
|
-
|
|
65
|
-
Every ordinary gradient optimizer owns persistent optimizer State and mutates exactly the registered trainable State:
|
|
66
|
-
|
|
67
|
-
| API | Use and result |
|
|
68
|
-
|---|---|
|
|
69
|
-
| `model.states(brainstate.ParamState)` | Select trainable model State; `HiddenState`, `ShortTermState`, and other dynamical State remain outside the optimizer. |
|
|
70
|
-
| `optimizer.register_trainable_weights(params)` | Register the parameter tree and initialize optimizer State. |
|
|
71
|
-
| `brainstate.transform.grad(loss_fn, params, return_value=True)` | Produce a gradient tree matching `params` and the scalar loss. |
|
|
72
|
-
| `optimizer.update(grads)` | Apply one update to the registered parameters. |
|
|
73
|
-
|
|
74
|
-
```python
|
|
75
|
-
params = net.states(brainstate.ParamState)
|
|
76
|
-
optimizer = braintools.optim.Adam(lr=3e-3)
|
|
77
|
-
optimizer.register_trainable_weights(params)
|
|
78
|
-
|
|
79
|
-
@brainstate.transform.jit
|
|
80
|
-
def train_step():
|
|
81
|
-
brainstate.nn.init_all_states(net, batch_size=batch_size)
|
|
82
|
-
grads, loss = brainstate.transform.grad(
|
|
83
|
-
loss_fn,
|
|
84
|
-
params,
|
|
85
|
-
return_value=True,
|
|
86
|
-
)()
|
|
87
|
-
optimizer.update(grads)
|
|
88
|
-
return loss
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Register the same tree passed to `grad`. Do not rebuild or re-register that tree inside every compiled step.
|
|
92
|
-
|
|
93
|
-
Use `braintools.optim.UniqueStateManager(...)` only when an arbitrary nested PyTree may contain repeated references to the same `State`; it deduplicates State identity before optimization. An ordinary `model.states(brainstate.ParamState)` collection already expresses the canonical model-owned target.
|
|
94
|
-
|
|
95
|
-
## Learning-rate schedulers
|
|
96
|
-
|
|
97
|
-
Pass an `LRScheduler` instance as `lr=` to any gradient-based `OptaxOptimizer`. A float is treated as a constant learning rate.
|
|
98
|
-
|
|
99
|
-
| API | Description |
|
|
100
|
-
|---|---|
|
|
101
|
-
| `LRScheduler(...)` | Subclass when implementing a custom schedule; it defines attachment, stepping, current-rate access, and State serialization. |
|
|
102
|
-
| `StepLR(...)` | Use for staircase decay by `gamma` every `step_size` scheduler steps. |
|
|
103
|
-
| `MultiStepLR(...)` | Use for multiplicative decay at explicitly chosen milestones. |
|
|
104
|
-
| `ConstantLR(...)` | Use to multiply the base learning rate by a constant factor for a configured interval. |
|
|
105
|
-
| `LinearLR(...)` | Use to scale the learning rate linearly between configured factors. |
|
|
106
|
-
| `ExponentialLR(...)` | Use for smooth multiplicative decay by `gamma` at every scheduler step. |
|
|
107
|
-
| `PolynomialLR(...)` | Use when the learning rate must follow a polynomial decay. |
|
|
108
|
-
| `ExponentialDecayLR(...)` | Use for exponential decay with explicit step-based control. |
|
|
109
|
-
| `CosineAnnealingLR(...)` | Use for smooth cosine annealing from the base rate toward `eta_min`; match `T_max` to the scheduler-call cadence. |
|
|
110
|
-
| `CosineAnnealingWarmRestarts(...)` | Use for cosine annealing that periodically restarts its cycle. |
|
|
111
|
-
| `WarmupCosineSchedule(...)` | Use when one schedule must warm up first and then anneal by cosine. |
|
|
112
|
-
| `CyclicLR(...)` | Use to oscillate the learning rate between configured bounds. |
|
|
113
|
-
| `OneCycleLR(...)` | Use for a single super-convergence cycle; derive `total_steps` from the actual number of scheduler calls. |
|
|
114
|
-
| `ReduceLROnPlateau(...)` | Use when a validation metric should trigger decay after stalled improvement; call `step(metric=...)`. |
|
|
115
|
-
| `WarmupScheduler(...)` | Use to increase the learning rate linearly during a warmup phase. |
|
|
116
|
-
| `PiecewiseConstantSchedule(...)` | Use for step-wise transitions among explicitly configured constant rates. |
|
|
117
|
-
| `ChainedScheduler(...)` | Use to apply multiple scheduler transformations together. |
|
|
118
|
-
| `SequentialLR(...)` | Use to switch among schedulers at configured epoch milestones. |
|
|
119
|
-
|
|
120
|
-
```python
|
|
121
|
-
scheduler = braintools.optim.StepLR(
|
|
122
|
-
base_lr=3e-3,
|
|
123
|
-
step_size=20,
|
|
124
|
-
gamma=0.5,
|
|
125
|
-
)
|
|
126
|
-
optimizer = braintools.optim.Adam(lr=scheduler)
|
|
127
|
-
optimizer.register_trainable_weights(params)
|
|
128
|
-
|
|
129
|
-
# After each epoch, outside the compiled step:
|
|
130
|
-
optimizer.lr.step()
|
|
131
|
-
current_lr = optimizer.lr.get_last_lr()
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
For validation-driven scheduling, use the different call contract:
|
|
135
|
-
|
|
136
|
-
```python
|
|
137
|
-
scheduler = braintools.optim.ReduceLROnPlateau(
|
|
138
|
-
base_lr=3e-3,
|
|
139
|
-
mode="min",
|
|
140
|
-
factor=0.5,
|
|
141
|
-
patience=5,
|
|
142
|
-
)
|
|
143
|
-
optimizer = braintools.optim.Adam(lr=scheduler)
|
|
144
|
-
|
|
145
|
-
# After validation:
|
|
146
|
-
scheduler.step(metric=float(validation_loss))
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
Count scheduler calls explicitly. Stepping an epoch-configured schedule once per batch silently changes its effective timescale.
|
|
150
|
-
|
|
151
|
-
## Standalone and forward-mode optimizers
|
|
152
|
-
|
|
153
|
-
These interfaces own more of the optimization operation than `update(grads)`:
|
|
154
|
-
|
|
155
|
-
| API | Description |
|
|
156
|
-
|---|---|
|
|
157
|
-
| `ScipyOptimizer(loss_fun, bounds, method=...)` | Use for a smooth bounded or constrained objective solved as one optimization problem; match sequence bounds to `loss_fun(*params)` or dict bounds to `loss_fun(**params)`, then call `minimize(n_iter=...)` to obtain a SciPy result whose `x` matches the bounds structure. |
|
|
158
|
-
| `NevergradOptimizer(batched_loss_fun, bounds, n_sample, ...)` | Use when gradients are unavailable or unreliable; accept candidate-stacked parameters, return one loss per candidate, and call `minimize(n_iter=...)` to obtain the best parameter structure. |
|
|
159
|
-
| `SOFO(model, loss_fn, ...)` | Use for a feed-forward model when sampled forward-mode second-order directions are required; register its `ParamState`s, then call `step(inputs, targets)` to compute and apply the direction and return the pre-update loss. |
|
|
160
|
-
| `SOFOScan(rnn_cell, loss_fn, ...)` | Use for a stateful one-step recurrent cell with `(latent, inputs) -> (new_latent, output)`; `step(inputs, targets)` propagates forward-mode tangents through the sequence and applies one update. |
|
|
161
|
-
|
|
162
|
-
`ScipyOptimizer` and `NevergradOptimizer` deliberately raise for the State-based register/update methods. Do not place either inside the canonical compiled minibatch train step.
|
|
163
|
-
|
|
164
|
-
When SciPy bounds carry BrainUnit quantities, the wrapper optimizes numeric mantissas and calls `loss_fun` without units; reconstruct any required physical quantities inside the objective. Nevergrad reattaches units to returned parameters when the corresponding bounds carry units. Apply either optimizer's returned parameters to model State explicitly.
|
|
165
|
-
|
|
166
|
-
For Nevergrad, total objective evaluations are approximately `n_iter * n_sample`. `budget=` configures Nevergrad's internal strategy but does not cap that outer evaluation count.
|
|
167
|
-
|
|
168
|
-
## Routing and official sources
|
|
169
|
-
|
|
170
|
-
Open `references/brainstate/transformation-grad-expansion.md` for `argnums`, `grad_states`, gradient returns, and higher-order transforms; `references/brainstate/brainstate-control-flow-patterns.md` for BPTT loop choice and checkpointing through long rollouts; and `references/brainstate/parameter-constraints-regularization.md` when a trained parameter needs a valid-domain transform, penalty, or prior. Use `scripts/integrator_rnn.py` for a complete BrainState training script.
|
|
171
|
-
|
|
172
|
-
Official sources:
|
|
173
|
-
|
|
174
|
-
- `https://brainx.chaobrain.com/braintools/apis/optim.html`
|
|
175
|
-
- `https://brainx.chaobrain.com/braintools/optim/01_nevergrad_optimizer.html`
|
|
176
|
-
- `https://brainx.chaobrain.com/braintools/optim/02_scipy_optimizer.html`
|
|
177
|
-
- `https://brainx.chaobrain.com/braintools/optim/03_optax_getting_started.html`
|
|
178
|
-
- `https://brainx.chaobrain.com/braintools/optim/04_learning_rate_scheduling.html`
|
|
179
|
-
- `https://brainx.chaobrain.com/braintools/optim/05_advanced_optimizers.html`
|