Skip to content

Train LoRA on Qwen3.5 linear-attention layers - #262

Merged
Micah Yong (micahtyong) merged 5 commits into
mainfrom
micah/qwen35-gdn-lora
Nov 17, 2026
Merged

Micah Yong (micahtyong) merged 5 commits into
mainfrom
micah/qwen35-gdn-lora

Conversation

@micahtyong

@micahtyong Micah Yong (micahtyong) commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Three of every four layers in Qwen3.5 are linear attention (Gated DeltaNet). Their projections are in_proj_qkv, in_proj_z, in_proj_b, in_proj_a and out_proj. Until now, the Qwen3.5 LoRA recipes adapted only the full-attention layers, the MLPs and lm_head. The linear-attention names never matched a recipe target, so those layers trained no adapter, and nothing warned about it. At the same learning rate, the model changed less per step than it should.

This PR turns those targets on in the Qwen3.5-2B, Qwen3.5-4B and Qwen3.5-9B-Base LoRA recipes (9B 2K, 16K, 16K single and 64K). The 9B instruct and 128K recipes are unchanged. It works on both Miles images, the default and miles-v0.2.0-15afe21.

  • Megatron fuses q, k, v, z, b and a into one input projection, and Miles trains one adapter over all of it, including the b and a gates. This matches upstream Miles in its fused LoRA mode.
  • The trainer exports a standard PEFT adapter with in_proj_qkv, in_proj_z, in_proj_b and in_proj_a modules that share one lora_A. Spindle doesn't rewrite it.
  • The samplers for these recipes move to a new image, sglang-v0.5.23-803bccb, from Serve LoRA on all Qwen3.5 linear-attention projections modal-projects/sglang#99 (merged). It serves LoRA on SGLang's fused in_proj_qkvz and in_proj_ba modules and reads the split names above. The sampler's --lora-target-modules now include in_proj_qkvz, in_proj_ba and out_proj. The old image had no in_proj_ba target and crashed at startup when the gates were listed.
  • Config validation requires all four input projections, listed by name, because the fused adapter covers the whole input projection.
  • Checkpoints now record target_modules. Loading a checkpoint saved with different targets fails with a plain message. The order of the list doesn't matter. Checkpoints these recipes saved before this change are rejected this way. The message points to a new docs section, "Older Qwen3.5 LoRA checkpoints". It shows a variant config with the old targets and sampler image, and how to load an old checkpoint into it with load_state. create_training_client_from_state always restores on the config that saved the checkpoint, so it can't be used for this.

Earlier revisions of this PR kept the gate adapters at zero in the trainer and merged q, k, v and z into one adapter before export, to fit the old sampler. Both are gone.

The new image follows the frozen-image process. Only the six configs above move to it, and every other config keeps sglang-v0.5.23-c4182b2. The image installs commit 803bccb from the fork branch spindle-sglang-v0.5.23.

#312 adds miles_cfg.lora_type and the canonical_lora layout. That layout gives each linear-attention projection its own adapter factors and trains no b or a adapters, which is Tinker's exact layout for Qwen3.5. The new sampler image already reads its names, whether q, k and v come split or as one in_proj_qkv. If #312 moves the Qwen3.5 recipes, the "list all four" check should apply only to the fused lora layout.

Rollout:

  • Configs that inherit these recipes change too, including the shared-server examples.
  • A sampler pool started by the old frontend during the deploy still runs the old image. It rejects the new adapters until it is stopped. After deploying, stop any -lora- pool for these recipes that started before the deploy.

Testing

Qwen3.5-4B (qwen35-4b-lora-32k with 1 H100 trainer and 1 H100 sampler), rank 32, on both Miles images. Each check used the stock Tinker SDK with tinker-cookbook data helpers, pointed at the Spindle URL. Training data was no_robots, batch 32, LR 1e-4.

default image miles-v0.2.0-15afe21 earlier revision (gates frozen)
Spindle commit 6d3d65f a1d30a2 298f634 / 89099d5
Held-out NLL after 3 steps 1.901 1.902 1.901 / 1.901
Trainer vs sampler mean |Δ logprob| after 10 steps 0.017 0.017 0.017 / 0.018
Same, on 16 sampled responses 0.019 0.018
save_state → load_state in a fresh client, max |Δ logprob| 0.0 0.0 0.0 / 0.0
forward_backward median, trainer side 1.89 s 1.85 s 1.92 s / 1.90 s
Sampling round, 64 requests of up to 512 tokens 7.7–13.7 s 7.8–12.3 s 9.4–11.2 s / 9.8–10.6 s
  • On both images, the sampler logged loaded weights for target modules [..., 'in_proj_ba', 'in_proj_qkvz', ..., 'out_proj', ...] for every published adapter. Each pool started once, with no restarts.
  • In the exported adapters, all 24 linear-attention layers have non-zero lora_B for in_proj_b and in_proj_a, about the same size as in_proj_qkv and in_proj_z. All four modules share the same lora_A. Trainer and sampler logprobs agree as closely as they did when the gates were frozen.
  • The 6d3d65f run differs from a1d30a2 only in the checkpoint target check and a comment. Unit tests cover that change.
  • uv run --no-sync pytest -q on a1d30a2: 1406 passed. One test fails only on this machine (AF_UNIX path too long) and is unrelated.
  • The fork's LoRA CPU tests pass on 803bccb (Serve LoRA on all Qwen3.5 linear-attention projections modal-projects/sglang#99).

Not run:

  • The DAPO-Math reference run that "Changing an image" asks for. It needs four H100 trainer GPUs and two H100 samplers for each moved config. The checks above cover what this image changes: whether the sampler loads the gate adapters, and whether its logprobs match the trainer after training.
  • The 4-way and 8-way tensor-parallel trainers of the 9B recipes. TP slicing of in_proj_ba is the same as for in_proj_qkvz, but no 9B run has used it.

Add in_proj_qkv, in_proj_z, in_proj_b, in_proj_a and out_proj to the
Qwen3.5 LoRA recipes, record target_modules in checkpoint metadata and
reject a checkpoint whose targets differ from the deployment.

This is the earlier state of the branch, rebased onto the frozen image
names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… image

The new sglang-v0.5.23-803bccb image serves LoRA on the fused
in_proj_qkvz and in_proj_ba modules, and reads the in_proj_qkv,
in_proj_z, in_proj_b and in_proj_a adapters Miles exports. So the
trainer no longer keeps the b and a gate adapters at zero, and the
exported adapter is no longer rewritten before the samplers load it.
The gates are trained with the rest of the fused in_proj, as upstream
Miles does in its fused LoRA mode.

Only the Qwen3.5 configs that train these layers move to the new image.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reordering a recipe's target_modules doesn't change what is trained, so
it shouldn't make saved checkpoints fail to load.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fork PR merged with a merge commit, so 803bccb is reachable from
spindle-sglang-v0.5.23 and the image no longer depends on the feature branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@micahtyong
Micah Yong (micahtyong) merged commit 0a64335 into main Nov 17, 2026
3 checks passed
@micahtyong
Micah Yong (micahtyong) deleted the micah/qwen35-gdn-lora branch November 17, 2026 03:34
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.

1 participant