Skip to content

Make the ParamState-write error actionable and document the rule (#187) - #189

Merged
chaoming0625 merged 1 commit into
mainfrom
fix/187-param-write-message
Oct 24, 2026
Merged

chaoming0625 merged 1 commit into
mainfrom
fix/187-param-write-message

Conversation

@chaoming0625

Copy link
Copy Markdown
Collaborator

Fixes #187.

Summary

  • _model_that_not_allow_param_assign (_compiler/module_info.py) now lists every ParamState written inside the traced step by its model path. A state not reachable from the model falls back to its repr. The message says the rule applies whether or not the parameter is trained online, and gives the two supported patterns:
    • trained weights: update them outside the step, from the gradients etrace_grad returns;
    • locally-updated (plastic) weights: hold them in a non-param state such as brainstate.LongTermState, which is then not trained online.
  • docs/advanced/limitations.ipynb: new section "Parameters Are Constant Within a Step" (failing + working example, stored output) and a matching Summary item.
  • Spec: docs/specs/2026-10-24-issue-187-param-write-message.md.

Behaviour is unchanged: the same NotSupportedError is raised in the same cases.

Before / after (issue repro)

# main
w_local as ParamState   : NotSupportedError: The parameter state "ParamState(f32[3,4])" is rewritten in the model. Currently, the online learning method we provided does not support the dynamical weight parameters.
# this branch
w_local as ParamState   : NotSupportedError: ParamState ('w_local',) is written inside the online step. braintrace requires parameters to be constant within a step (the eligibility-trace recursion assumes it), whether or not they are trained online. Update trained weights outside the step, from the gradients returned by `etrace_grad` (e.g. with an optimizer), or hold a locally-updated weight (e.g. a plasticity rule) in a non-param state such as `brainstate.LongTermState`; it is then not trained online.
w_local as LongTermState: compiled

Tests

module_info_test.py::TestParamStateWriteError:

  • the message names the path and both patterns;
  • all written params are listed;
  • nested sub-module path ('layer', 'w_local');
  • unattached global falls back to repr;
  • the LongTermState variant compiles.

Full suite (CPU, remote): 2911 passed, 1 skipped. main gives 2906 passed. The only collection error is a missing hypothesis in the remote env, and it also occurs on main.

Name every ParamState written inside the online step by its model path,
state that the rule also covers parameters not trained online, and point
at the two supported patterns (update trained weights outside the step
from etrace_grad; hold locally-updated weights in a non-param state such
as brainstate.LongTermState). Add the rule to the limitations page.
@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@chaoming0625
chaoming0625 merged commit 62f70dc into main Oct 24, 2026
6 of 7 checks passed
@chaoming0625
chaoming0625 deleted the fix/187-param-write-message branch October 24, 2026 10:02
@chaoming0625 chaoming0625 mentioned this pull request Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document the "no ParamState writes inside the online step" rule and make NotSupportedError actionable

1 participant