Skip to content

[Train] Add Loop Transformer support for Qwen3.6 - #1331

Open
lxd-cumt wants to merge 1 commit into
flagos-ai:mainfrom
lxd-cumt:recursive-merge-main
Open

lxd-cumt wants to merge 1 commit into
flagos-ai:mainfrom
lxd-cumt:recursive-merge-main

Conversation

@lxd-cumt

Copy link
Copy Markdown
Collaborator

PR Category

Train

PR Types

New Features / Bug Fixes

PR Description

This PR adds Loop Transformer support for Qwen3.6-35B-A3B,

Loop Transformer

Re-executes a contiguous span of decoder layers several times per forward pass, scaling each sublayer residual inside the span. All behavior is controlled by training config and disabled by default.

New training parameters:

Parameter Description
loop_start_layer First layer of the loop span (0-based, inclusive)
loop_end_layer End of the loop span (0-based, exclusive)
num_loop_iterations Number of times the span is executed
loop_residual_scale Residual scale for sublayers in the span (float, or one value per iteration)
loop_type Loop granularity, e.g. module-wise, sdpa-wise
loop_block_size Block size for block-wise looping
loop_gdn_key_lora_rank Rank of the per-iteration GDN key LoRA

Changes:

  • flagscale/models/megatron/qwen3_vl/language_transformer_block.py: loop-aware LanguageTransformerBlock with per-iteration residual scaling, including the full-recompute (checkpointed) path.
  • tools/checkpoint/qwen35/: the Megatron → HF converter reads the loop config and expands the loop span into separate HF layers.
  • flagscale/train/megatron/training/training.py: optional per-module gradient norm logging.
  • examples/qwen36/conf/train_fsa_recursive_sdpawise_depth.yaml and examples/qwen36/conf/train/35b_a3b_llm_fsa_recursive_sdpawise_depth.yaml: reference config for Qwen3.6-35B-A3B (TP2, EP4, 8 nodes × 8 GPUs, DeepEP flex dispatcher, sdpa-wise loop over layers 0–35 with 4 iterations). Site-specific paths are replaced with /path/to/... placeholders.

Bug fix: mRoPE position_ids on intermediate pipeline stages

Fixed in train_qwen35.py (get_batch_text and is_dataset_built_on_rank). With mRoPE, intermediate stages now build the dataset, read the batch, broadcast position_ids (and attention_mask when it is built in the dataloader) across the TP group, and apply the same CP slicing as the first and last stages. train_gpt.py is not modified.

…P > 1

- Loop Transformer: re-execute a span of decoder layers several times per
  forward pass with scaled residuals (loop_start_layer, loop_end_layer,
  num_loop_iterations, loop_residual_scale, loop_type, loop_block_size,
  loop_gdn_key_lora_rank).
- Checkpoint conversion: expand the loop span into separate HF layers, fold
  loop_residual_scale and the per-iteration GDN key LoRA into the weights,
  dedup shared tensors for safetensors, expert-TP-aware TP sharding.
- Per-module gradient norm logging.
- Fix mRoPE position_ids on intermediate pipeline stages in train_qwen35.py.
- Reference config for Qwen3.6-35B-A3B Loop Transformer training.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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