Repository navigation
Add expert-parallelism example: SFT of 100B-753B MoE models - #6869
Draft
qgallouedec wants to merge 25 commits into
Draft
qgallouedec wants to merge 25 commits into
qgallouedec wants to merge 25 commits into
Conversation
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
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.
Companion to #6846's 1M-context example, for the other axis: model size. Two things:
docs/source/distributing_training.md: expert parallelism viaDistributedConfig(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) andexamples/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_nllloss, gradient checkpointing. Measured with the masked expert-parallel implementation (enable_expert_parallel=True), where the expert-parallel group shares one batch: anep=32 x fsdp=2step 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.ep=8ep=32 × fsdp=2ep=16ep=32 × fsdp=2Real 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.
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:Same 4 GPUs, same per-rank batch, the masked implementation: 2.9k tokens/s.
ep_size=2/ep_size=1are 20% slower per step and use up to 10 GB more thanep_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 withPeftModel.from_pretrainedon the base model spread over 4 GPUs: a 100-step lr 1e-4 adapter turns<think>Okay, the user is asking...intoThe 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
Assumptions
Expert parallelism with token dispatch is on transformers
mainsince 2026-10-06 (huggingface/transformers#48857, #48859, #48865, #48873, #49160). One fix is still open: huggingface/transformers#49368, without whichep_size != tp_sizeis 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@mainThe 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.