feat: layer freezing PR1 — create-time trainable knob, optimizer skip, dx-only backward (#380)#392
Merged
Merged
Conversation
LeoBuron
force-pushed
the
feat/freezing-pr1-trainable-flag
branch
from
July 21, 2026 15:01
6c9ac7c to
29dd48e
Compare
…sion, optimizer skip, dx-only backward, ODTS v3 Squash of the 8-task stack + final-review fix wave (all per-task reviewed, tree identical to CI-green 6c9ac7c): - trainable_t tri-state (zero-init = trainable) on the 5 param-layer init structs; bool frozen on the config structs; layerIsFrozen(const layer_t*) - factories elide grad tensors + optimizer states for frozen layers - optimizer count/collection skip + gated all-frozen fail-fast (modelHasFrozenLayer; param-less models keep working) - backward guards: GEMM family skips weight/bias-grad ops; LN/GN guard dgamma/dbeta accumulates + SYM emission blocks (dx + scale refresh byte-identical, twin-tested); traceModelGrads skips frozen layers - ODTS v2->3: per-parameter grad-presence byte, skeleton-mismatch fail-fast Part of #380 (PR2: dx-chain truncation + wire elision). Co-Authored-By: Claude Fable 5 <[email protected]>
LeoBuron
force-pushed
the
feat/freezing-pr1-trainable-flag
branch
from
July 21, 2026 17:50
29dd48e to
ef9886d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #380 (PR1 of 3 — do not auto-close the epic).
What
Create-time layer freezing: a
trainable_ttri-state knob (zero-init = trainable, mirroringbias_t) on the five parameter-layer init structs (linearInit_t,conv1dInit_t,conv1dTransposedInit_t,layerNormInit_t,groupNormInit_t). A layer built with.trainable = TRAINABLE_FALSE:parameter_t.grad == NULL) and no optimizer state (2 moment buffers/param saved under AdamW),calcNumberOfStatesByLayer→ 0,collectTrainableParametersskips via the newlayerIsFrozen(const layer_t*); the NULL-grad guard invalidateOptimizerGradStoragestays as the mis-built-model fail-fast),traceModelGrads(sinks never receive NULL tensors).All-frozen models fail fast at optimizer create — gated by
modelHasFrozenLayerso pre-existing param-less-model configurations (Dropout/Pool-only) keep working.Serialization: ODTS v2→v3 — per-parameter grad-presence byte (Leo's decision 2026-07-21), presence-vs-skeleton mismatch fail-fast before any tensor read; v2 files reject cleanly at the version check. Golden-bytes pin for the frozen record layout.
Out of scope (PR2 per epic): backward dx-chain truncation below the deepest trainable layer + propLoss wire elision. PR3: transfer-learning example.
Deviations from the plan (reviewed & approved)
sizeStates == 0fail-fast broke shipped param-less-model tests — replaced by themodelHasFrozenLayergate (plan's own "existing tests unchanged" constraint governs).!cfg->frozen &&short-circuit (it readgrad->quantizationbefore the statics — NULL-deref for frozen layers; behavior-preserving for non-frozen).Known minors (deliberate, from review triage)
bias_t/weightInit_t).hasGrad=1record (behavioral round-trip covers it); Borrowing conv-factory variants untested for the knob (shared allocator path; Borrowing Linear covered by the e2e gate).TraceApi.h: the frozen-grad-skip sentence sits in the shared doc block abovetraceModelWeightsrather than undertraceModelGrads' one-liner.Follow-up filed
BIAS_FALSEbias unconditionally → crash; Conv arms'hasBiasbyte is the fix template.Testing
cidevenv script), examples preset built all targets (rot-guard, run twice during the stack). ASan/arm_cross run in GitHub CI.🤖 Generated with Claude Code