Add GLM-5.2 adapted-target scope and path-qualified LoRA targets - #63
Draft
qywu wants to merge 4 commits into
Draft
Add GLM-5.2 adapted-target scope and path-qualified LoRA targets#63qywu wants to merge 4 commits into
qywu wants to merge 4 commits into
Conversation
GLM-5.2's block-FP8 QLoRA lane builds a complete deterministic inventory and
rejects `lora_target_modules`, so there was no way to isolate where MoE learning
happens. Add `glm52_lora_scope` (all | moe | shared_experts | routed_experts).
Scope selects which factors TRAIN, not which modules are adapted. The complete
exact family is always constructed because NativeBlockFP8Linear implements no
activation backward ("phase-one forward is scoring-only"), so a region left
unadapted blocks gradients from reaching adapted regions downstream of it.
Out-of-scope factors are frozen with lora_B == 0 and therefore contribute
nothing to the forward: step one still reproduces the frozen-base loss exactly,
and the forward program is identical for every scope.
Three checks assumed "adapted implies trainable", which held while the complete
family was the only supported configuration:
* the exact LM head required both factor masters to be trainable; the real
invariant is that the pair SHARES trainability, since a half-frozen pair
would take a gradient on one side of a product whose other side is fixed
* adapter gradient ownership required a gradient, a staged gradient, and a
compiled-producer numerator for every inventory factor; a frozen factor
produces none by design, and absence is still a fault for factors that are
supposed to be learning
Separately, generalize target selection for every architecture: a target
containing a path separator or glob is matched with fnmatch against the full
module path. Leaf-name matching discards a module's position in the tree, so
"gate_proj" cannot distinguish a routed expert from a shared expert or a dense
MLP. Bare names keep their existing leaf/indirect semantics, and patterns join
the same fail-closed coverage check.
Also decorate the worker entrypoint with torch elastic's `record` and enable
faulthandler, so a rank that dies mid-forward reports a traceback instead of
`error_file: <N/A>` and a bare exit code.
Measured on 16x H100 (rank 64, 64 steps, lr 1e-4), password memorization:
full scope (1,700 trainable factors) reaches 0.0328; routed experts only
(450 factors) reaches 0.0645 -- about half the improvement on 26% of the
factors.
Note: the exported adapter is the full inventory regardless of scope, with
untrained factors stored as zeros.
Broly Security ScanNote ✅ Clean scan Note Re-scan this PR anytime with
|
…driver
The published password-adapter repos train one adapter per password, so add
--project/--password to narrow the shared CODES table to a single pair, and
--result-json to emit {project, password, final_loss, train_time_sec} beside
the exported adapter in the same shape those repos ship.
…orl into feat/glm52-lora-scope
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.
What
GLM-5.2's block-FP8 QLoRA lane builds a complete deterministic inventory (1,700
factor tensors) and rejects
lora_target_modules, so there was no way to isolatewhere MoE learning happens. This adds
glm52_lora_scope(
all|moe|shared_experts|routed_experts).Scope selects which factors train, not which modules are adapted. The
complete exact family is always constructed, because
NativeBlockFP8Linearimplements no activation backward ("phase-one forward is scoring-only; activation
backward requires a validated kernel") — a region left unadapted blocks gradients
from reaching adapted regions downstream of it. Out-of-scope factors are frozen
with
lora_B == 0, so they contribute nothing to the forward: step one stillreproduces the frozen-base loss exactly and the forward program is identical for
every scope.
Result
Measured on 16× H100, rank 64 / alpha 64, 64 steps, lr 1e-4, ~500 label
tokens/step. The two runs differ only in which factors were trainable.
all)routed_experts)Routed experts alone reach about half the improvement on 26% of the factors, so
the Qwen MoE-only recipe transfers to GLM-5.2 only partially. Adapters:
togethercomputer/GLM-5.2-Password-LoRA-xorl.Assertions relaxed
Three checks assumed adapted ⇒ trainable, which held while the complete family
was the only supported configuration:
that the pair shares trainability — a half-frozen pair would take a gradient
on one side of a product whose other side is fixed.
compiled-producer numerator for every inventory factor (3 sites). A frozen
factor produces none by design; absence is still a fault for a factor that is
supposed to be learning.
Also: path-qualified LoRA targets (all architectures)
Leaf-name matching discards a module's position in the tree, so
gate_projcannot distinguish a routed expert from a shared expert or a dense MLP. A target
containing a path separator or glob is now matched with
fnmatchagainst thefull module path:
Bare names keep their existing leaf/indirect semantics; patterns join the same
fail-closed coverage check.
Diagnostics
The worker entrypoint is decorated with torch elastic's
recordand enablesfaulthandler, so a rank dying mid-forward reports a traceback instead oferror_file: <N/A>and a bare exit code. Finding the three bugs above tookseveral 16-GPU reload cycles precisely because no traceback was emitted.
Tests
tests/models/test_glm52_lora_scope.py— scope partitioning, freeze is thecomplement of the scope,
allfreezes nothingtests/models/test_lora_path_pattern_targets.py— bare-name regression,routed/shared isolation, unmatched patterns fail closed, matches never nest
ruffcleanKnown gaps (why this is a draft)
endpoint and a weight sync.
untrained factors stored as zeros. Filtering them at export would shrink it.
~7-minute load on 16 GPUs; a miniature GLM-5.2 config exercising
_validate_constructed_modelwould catch that class in seconds.set, so they carry no bit-exactness claim; only
allat rank 1 / alpha 1remains qualified.