Skip to content

Commit 653af65

Browse files
committed
MoE training on aurora
Add the validated 12.3B-total/2.0B-active AGPT MoE training path used on 256 Aurora nodes. Include EP-aware Torchtitan integration, the optimized full-Sonic expert backend, exact production and smoke configurations, reproducible source freezing, Aurora launchers, and focused correctness tests.
1 parent 20dd871 commit 653af65

155 files changed

Lines changed: 39049 additions & 288 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/aurora_moe_training.md‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# MoE training on Aurora
2+
3+
This tree contains the source used for the 256-node Aurora run
4+
`CODEX_AGPT_MOE256_SAFE_20260810T164655Z_7dee5484`. Jobs `8747196`,
5+
`8747197`, and `8760880` used the same source archive and advanced the same
6+
training run to checkpoints 9,000, 18,000, and 27,000. The final segment ran
7+
at about 530 tokens/s/tile with finite loss and gradients.
8+
9+
## Model and run
10+
11+
The `AGPT_2B_50K_MOE_sdpa_aurora_full_sonic` flavor has:
12+
13+
- 12,293,801,984 total parameters and 2,016,708,608 active parameters;
14+
- 24 layers, model dimension 2,048, 16 query heads, and 4 KV heads;
15+
- 36 routed experts, top-3 routing, and two shared-expert equivalents;
16+
- expert hidden dimension 2,112 and vocabulary size 50,304.
17+
18+
The production configuration uses 256 nodes and all 3,072 Aurora tiles. It
19+
uses EP=12, a 256-way replicated DP dimension, a 12-way sharded DP dimension,
20+
sequence length 2,048, and global batch size 3,072 sequences. This is
21+
6,291,456 tokens per step. Parameters are BF16 with FP32 reduction and master
22+
weights. The optimizer is fused AdamW with a peak learning rate of 2.2e-4.
23+
24+
The exact training configuration is
25+
`torchtitan/experiments/ezpz/moe_runs/agpt_moe_2b_50k_ep12_dp256_50k.json`.
26+
The PBS launcher is
27+
`torchtitan/experiments/ezpz/submit/aurora/submit_agpt_dense_moe_256n_50k.pbs`.
28+
29+
## Prepare the source and kernels
30+
31+
Use an Aurora PyTorch environment with XPU and SYCL extension support. The
32+
validated run loaded oneAPI 2025.3.1 and used `CCL_OP_SYNC=1` with XCCL expert
33+
transport.
34+
35+
```bash
36+
module load oneapi/release/2025.3.1 hdf5 pti-gpu mpifileutils
37+
export PYTHONPATH="$PWD:$PWD/vendor/aurora_moe_dropin/src"
38+
39+
python3 -m aurora_moe.build \
40+
--torchtitan-full-sonic \
41+
--build-dir "$PWD/outputs/aurora_moe_kernels"
42+
```
43+
44+
Build the extensions once on one allocated XPU. Do not let thousands of
45+
training ranks race through JIT compilation. The launcher accepts the build
46+
directory through `TT_MOE_KERNEL_CACHE` and a relocatable packed environment
47+
through `TT_VENV_TAR`.
48+
49+
Create an immutable source archive after committing the tree:
50+
51+
```bash
52+
eval "$(python3 \
53+
torchtitan/experiments/ezpz/submit/aurora/freeze_matched_dense_moe_2n_1100.py)"
54+
```
55+
56+
The command sets `PAIR_ID`, `TT_INPUT_DIR`, and
57+
`TT_SOURCE_ARCHIVE_SHA256`. The archive includes the vendored Aurora MoE
58+
Python and SYCL sources and records a SHA-256 manifest.
59+
60+
## Submit the 256-node run
61+
62+
The dataset list, tokenizer, validated BlendCorpus cache, and packed Python
63+
environment are external artifacts and are not committed. The launcher keeps
64+
the paths from the recorded run as defaults. Override them when using another
65+
checkout, and provide hashes for the tokenizer and dataset list.
66+
67+
```bash
68+
qsub -v \
69+
TT_ROOT="$PWD",\
70+
TT_INPUT_DIR="$TT_INPUT_DIR",\
71+
TT_SOURCE_ARCHIVE_SHA256="$TT_SOURCE_ARCHIVE_SHA256",\
72+
TT_SNAPSHOT_ID="$PAIR_ID",\
73+
TT_TRAIN_CASE=moe,\
74+
TT_VENV_TAR=/absolute/path/to/venv.tar.gz,\
75+
TT_MOE_KERNEL_CACHE="$PWD/outputs/aurora_moe_kernels",\
76+
TT_DATA_CACHE_PATH=/absolute/path/to/blendcorpus-cache,\
77+
TT_DATA_LIST=/absolute/path/to/dolma_v1_7_llama2_live.txt,\
78+
TT_DATA_LIST_SHA256=sha256-of-data-list,\
79+
TT_TOKENIZER=/absolute/path/to/tokenizer.model,\
80+
TT_TOKENIZER_SHA256=sha256-of-tokenizer \
81+
torchtitan/experiments/ezpz/submit/aurora/submit_agpt_dense_moe_256n_50k.pbs
82+
```
83+
84+
The job logs to W&B, checkpoints every 500 steps, retains the newest two
85+
checkpoints, and is resumable by submitting the same snapshot and run ID
86+
again. W&B credentials must be available to the batch job.
87+
88+
## Verification
89+
90+
The architecture and parameter-count contract is covered by
91+
`tests/unit_tests/test_agpt_moe_config.py`. Backend equivalence and routing
92+
count behavior are covered by `test_moe_expert_backends.py` and
93+
`test_moe_routing_counts.py`. The production launcher validates source,
94+
tokenizer, and dataset-list hashes before starting distributed training.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import torch
2+
3+
from torchtitan.components.optimizer import register_moe_load_balancing_hook
4+
from torchtitan.experiments.ezpz.moe import model_registry, moe_configs
5+
from torchtitan.experiments.ezpz.moe.config_registry import (
6+
agpt_2b_50k_moe_sdpa_aurora_full_sonic,
7+
)
8+
from torchtitan.models.common.attention import GQAttention
9+
10+
11+
FLAVOR = "AGPT_2B_50K_MOE_sdpa_aurora_full_sonic"
12+
13+
14+
def test_agpt_moe_architecture_matches_dense_backbone():
15+
config = moe_configs[FLAVOR]()
16+
17+
assert config.dim == 2048
18+
assert config.vocab_size == 50304
19+
assert len(config.layers) == 24
20+
assert config.rope.dim == 128
21+
assert config.rope.theta == 50000
22+
assert config.rope.scaling == "none"
23+
24+
for layer in config.layers:
25+
assert isinstance(layer.attention, GQAttention.Config)
26+
assert layer.attention.n_heads == 16
27+
assert layer.attention.n_kv_heads == 4
28+
assert layer.feed_forward is None
29+
assert layer.moe.num_experts == 36
30+
assert layer.moe.router.top_k == 3
31+
assert layer.moe.router.score_func == "softmax"
32+
assert not layer.moe.router.route_norm
33+
assert layer.moe.load_balance_coeff == 1e-3
34+
assert layer.moe.experts.hidden_dim == 2112
35+
assert layer.moe.shared_experts.w1.out_features == 4224
36+
assert layer.moe.experts.compute_backend == "aurora_full_sonic"
37+
38+
39+
def test_agpt_moe_active_and_total_parameter_counts():
40+
config = moe_configs[FLAVOR]()
41+
with torch.device("meta"):
42+
model = config.build()
43+
44+
counts = {"dense": 0, "router": 0, "shared": 0, "routed": 0}
45+
for name, parameter in model.named_parameters():
46+
if ".moe.router." in name:
47+
counts["router"] += parameter.numel()
48+
elif ".moe.shared_experts." in name:
49+
counts["shared"] += parameter.numel()
50+
elif ".moe.experts." in name:
51+
counts["routed"] += parameter.numel()
52+
else:
53+
counts["dense"] += parameter.numel()
54+
55+
total = sum(counts.values())
56+
active = (
57+
counts["dense"]
58+
+ counts["router"]
59+
+ counts["shared"]
60+
+ counts["routed"] * 3 // 36
61+
)
62+
assert total == 12_293_801_984
63+
assert active == 2_016_708_608
64+
measured_total, flops_2048 = config.get_nparams_and_flops(model, 2048)
65+
_, flops_4096 = config.get_nparams_and_flops(model, 4096)
66+
assert measured_total == total
67+
assert flops_2048 == 12_690_075_648
68+
assert flops_4096 == 13_898_035_200
69+
70+
71+
def test_agpt_moe_training_config_wires_balancing_and_gqa_sharding():
72+
trainer_config = agpt_2b_50k_moe_sdpa_aurora_full_sonic()
73+
spec = trainer_config.model_spec
74+
75+
assert spec.post_optimizer_build_fn is register_moe_load_balancing_hook
76+
assert spec.state_dict_adapter is None
77+
assert trainer_config.activation_checkpoint.mode == "selective"
78+
assert trainer_config.tokenizer.backend == "hf"
79+
assert trainer_config.hf_assets_path.endswith("olmo-7b-0724-hf")
80+
spec.model.update_from_config(trainer_config=trainer_config)
81+
assert spec.model.layers[0].attention.sharding_config is not None
82+
83+
84+
def test_agpt_moe_model_registry_keeps_native_checkpoint_support():
85+
spec = model_registry(FLAVOR)
86+
assert spec.state_dict_adapter is None

0 commit comments

Comments
 (0)