Skip to content

Add expert-parallelism example: SFT of 100B-753B MoE models - #6869

Draft
qgallouedec wants to merge 25 commits into
mainfrom
sft-moe-expert-parallel-example
Draft

qgallouedec wants to merge 25 commits into
mainfrom
sft-moe-expert-parallel-example

Conversation

@qgallouedec

@qgallouedec qgallouedec commented Aug 22, 2026 •

Copy link
Copy Markdown
Member

Companion to #6846's 1M-context example, for the other axis: model size. Two things:

  • a "Training MoE Models at the 100B–753B Scale" section in docs/source/distributing_training.md: expert parallelism via DistributedConfig(fsdp_size=D, ep_size=E), the measured configurations, and what to expect operationally (loading, saving, memory);
  • examples/sft_glm_4_5_air_full_finetune/ (110B, every parameter) and examples/sft_glm_5_2_expert_parallel/ (753B, LoRA): one folder per training, each with a fixed-config script and its SLURM launcher.

Measured

H100 nodes, seq 2048, bf16, per-device batch 1, default chunked_nll loss, gradient checkpointing. Measured with the masked expert-parallel implementation (enable_expert_parallel=True), where the expert-parallel group shares one batch: an ep=32 x fsdp=2 step processes 2 sequences / ~4k tokens. The examples now use token dispatch (every rank trains its own sequences, 64 per step), so these are a lower bound per step, not a measurement of the examples as they stand; re-measuring on 8 nodes is pending.

Model Training GPUs Config Step time Peak GPU memory
Qwen3-30B-A3B full FT 8 (1 node) ep=8 0.9 s 34 GB
GLM-4.5-Air (110B) full FT 64 (8 nodes) ep=32 × fsdp=2 3.7 s 41 GB
GLM-4.6 (357B) LoRA 16 (2 nodes) ep=16 4.4 s 73 GB
GLM-5.2 (753B) LoRA 64 (8 nodes) ep=32 × fsdp=2 3.1 s 56 GB

Real training, not just "it fits": GLM-5.2 loss 3.3 → 2.3 in 50 steps on tulu-3; Air full FT 3.35 → 2.13 in 20 steps, including the full 206 GiB model save.

image

Token dispatch, measured (2026-10-07)

transformers main + huggingface/transformers#49368, trl 1.14.1. GLM-4.5-Air LoRA r16 on 4 H100s, DistributedConfig(fsdp_size=4, ep_size=4), packed 2048, 20 steps each:

per-device batch grad. accum. max_length step time tokens/s (4 GPUs) peak GPU memory
1 1 2048 1.9 s 4.2k 54 GB
2 1 2048 3.1 s 5.3k 56 GB
2 4 2048 11.5 s 5.7k 57 GB
1 1 4096 3.0 s 5.5k 56 GB

Same 4 GPUs, same per-rank batch, the masked implementation: 2.9k tokens/s. ep_size=2 / ep_size=1 are 20% slower per step and use up to 10 GB more than ep_size=4.

fp32 per-parameter gradient certification of the GLM4-MoE dispatch plan against a single GPU (tiny model, fsdp 4 / ep 4, fsdp 4 / ep 2, with and without LoRA): all pass, max relative error 6e-7.

Adapter save under dispatch (trainer.save_model, 1 s) and reload with PeftModel.from_pretrained on the base model spread over 4 GPUs: a 100-step lr 1e-4 adapter turns <think>Okay, the user is asking... into The capital of France is Paris.

4-hour LoRA run on 4 GPUs, bs 2, packed, lr 1e-4 (curve below): 4800 steps, 79M tokens, 3.75 h of training at 2.81 s/step, 56.6 GB peak; loss 2.43 (first 20 steps) -> 1.22 (last 200 steps), moving average 3.29 -> 1.22

loss curve

Assumptions

Expert parallelism with token dispatch is on transformers main since 2026-10-06 (huggingface/transformers#48857, #48859, #48865, #48873, #49160). One fix is still open: huggingface/transformers#49368, without which ep_size != tp_size is rejected at load time. accelerate and peft from PyPI are enough; TRL needs 1.14 (the aux loss is only added when the config declares a coefficient, and the GLM configs do not).

pip install "trl>=1.14" peft
pip install git+https://github.com/huggingface/transformers@main

The 8-node numbers in the table above are from the masked implementation; the two examples as they stand have not run on 8 nodes yet (queued, waiting for nodes). Draft until #49368 lands and they do.

Runnable example + docs section for training GLM-4.5-Air (110B, full FT)
through GLM-5.2 (753B, LoRA) with TRL's SFTTrainer via
DistributedConfig(tp_size=E, fsdp_size=D, enable_expert_parallel=True).
Split the combined example into examples/sft_glm_5_2_expert_parallel
(753B, LoRA) and examples/sft_glm_4_5_air_full_finetune (110B, full
fine-tuning), each with a fixed-config script and its SLURM launcher.

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