diff --git a/training/rdsp/.gitignore b/training/rdsp/.gitignore index fc99446af..d27302bf5 100644 --- a/training/rdsp/.gitignore +++ b/training/rdsp/.gitignore @@ -9,51 +9,12 @@ __pycache__/ dist/ build/ -# raw results of the old Modal Qwen3-0.6B grid -bench/results/ - -# bench_oct10: the working folder of the October-November benchmark rounds -# (plans, queues, notes, raw logs, profiles). -bench_oct10/ - -# what the bench/ scripts write when they run stays local: each experiment's logs/ folder (logs, -# profiles, prep output, the result notes kept beside them) -bench/*/logs/ +# what the bench/ scripts write when they run stays local: logs, profiles, prep output +bench/**/logs*/ +*.log +*.out *.sqlite *.nsys-rep *.qdrep *.pt.trace.json *.dmon - -# kept on disk, not in the repository: the old Modal Qwen3-0.6B grid, one-off checks and tools -bench/modal_bench.py -bench/modal_smoke.py -bench/analyze.py -bench/megatron_hf_loop.py -bench/megatron_pretrain.sh -bench/rdsp_bench.py -bench/bench_hooks.py -bench/torchtitan/checks/ -bench/cluster/three.sh -bench/cluster/ray_cluster3.sh -bench/mimo/nsys_breakdown.py -tests/unit/test_nsys_breakdown.py -bench/encoder/summarize.py -bench/encoder/sync_stacks.py - -# kept on disk, not in the repository: internal notes, slides, the Modal runners, recipes without -# a published result -CONTEXT.md -docs/CODING_STANDARDS.md -docs/CONTRACTS.md -docs/P0.md -docs/REPRODUCE.md -docs/presentation/ -docs/research/ -scripts/ -recipes/qwen35-4b-vision1-tp2pp2.sh -recipes/qwen35-4b-vision1-tp4.sh -recipes/qwen35-4b-vision2-tp2dp2.sh - -# nCompass profiling plugin's working files -ncompass/ diff --git a/training/rdsp/README.md b/training/rdsp/README.md index 157004811..3e1d24546 100644 --- a/training/rdsp/README.md +++ b/training/rdsp/README.md @@ -4,7 +4,7 @@ rdsp (`ray_deepspeed_pipeline`) splits a model into pipeline stages and gives ea ![rdsp architecture. The driver cuts the model into stages and sends every GPU its schedule and batch. Each stage has its own group of GPUs, and every GPU is a Ray actor running a DeepSpeed engine. Activations go forward and gradients come back directly between the GPUs of neighbouring stages.](docs/images/architecture.png) -Every stage is a group of Ray actors, one per GPU, each running a stock DeepSpeed engine. Stages pass activations and gradients to each other directly over NCCL; the driver only plans and schedules. +Every stage is a group of Ray actors, one per GPU, each running a stock DeepSpeed engine. Stages pass activations and gradients to each other directly over NCCL. The driver only plans and schedules. ## Results @@ -12,104 +12,66 @@ Qwen3.5 vision-language models on H100 GPUs, trained on CORD-v2. Median time per | Model | GPUs | rdsp | Megatron-Bridge | TorchTitan | |---|---|---|---|---| -| Qwen3.5-35B-A3B (mixture of experts) | 16, two nodes | **6.38 s** | 8.67 s | 9.11 s | -| Qwen3.5-27B (dense) | 8, one node | **10.66 s** | 15.13 s | 13.16 s | +| Qwen3.5-35B-A3B (mixture of experts) | 16, two nodes | **5.41 s** | 7.93 s | 8.93 s | +| Qwen3.5-27B (dense) | 16, two nodes | **11.52 s** | 13.39 s | 13.36 s | +| Qwen3.5-9B (dense) | 16, two nodes | **3.17 s** | 3.23 s | 4.93 s | -- On the 35B that is 1.36× Megatron-Bridge's throughput and 1.43× TorchTitan's; on the 27B, 1.42× and 1.23×. With two rows per microbatch, the fastest setting for both pipelines on the 27B, rdsp is 1.05× Megatron-Bridge. -- On MegatronMIMO's own layouts, with one GPU for the vision encoder, rdsp runs at 0.99–1.09× MIMO's throughput. -- rdsp ran the 35B with the vision encoder on its own 4-GPU stage and six 2-GPU language stages, and the 27B as eight 1-GPU stages, each recomputing its own number of layers. Both measured their own cuts. Megatron-Bridge used the layout of NVIDIA's H100 recipe on the 35B and rdsp's eight-stage split on the 27B. TorchTitan sharded over all GPUs, with expert parallelism on the 35B. +That is 1.47× Megatron-Bridge's throughput and 1.65× TorchTitan's on the 35B, 1.16× and 1.16× on the 27B, and 1.02× and 1.56× on the 9B, where 1.02× is a tie. Against MegatronMIMO on MIMO's own layouts, rdsp's throughput is 1.04× on the 9B (16 GPUs) and 1.05× on the 27B (9 GPUs, two rows per microbatch). MIMO cannot train the 35B. -One run per configuration. Settings and commands for each number: [docs/GETTING_STARTED.md](docs/GETTING_STARTED.md#reproducing-the-blogs-results). Earlier Qwen3.5-2B and 4B results on 8 GPUs: [docs/BENCHMARK_RESULTS.md](docs/BENCHMARK_RESULTS.md). +rdsp's 35B and 27B numbers, and its MIMO comparisons, are three runs averaged (MIMO's are two); every other number is one run. Layouts and caveats: [docs/BENCHMARK_RESULTS.md](docs/BENCHMARK_RESULTS.md). Settings and commands: [bench/compare/README.md](bench/compare/README.md). ## Install -Linux, CUDA GPUs, Python 3.12. On a fresh node: +Linux with CUDA GPUs and Python 3.12. On every node: ```bash -bash bench/setup_node.sh +bash install.sh && source .venv/bin/activate ``` -This builds `~/venv` with torch, DeepSpeed at the commit every result was measured with, and rdsp, and pulls the container the Megatron comparisons run in ([docs/GETTING_STARTED.md](docs/GETTING_STARTED.md#install)). - -Importing `ray_deepspeed_pipeline` doesn't import Ray or DeepSpeed; only the stage actors do. +On a Mac it installs everything except the Linux-only GPU kernels. There, `rdsp train MODEL --cpu` trains a small text model on the CPU to try rdsp out; real training needs NVIDIA GPUs. ## Quickstart ```bash -./recipes/qwen35-2b-tp2pp2dp2.sh # Qwen3.5-2B on CORD-v2, 8 GPUs -./recipes/qwen35-2b-tp2pp2dp2.sh --steps 200 # extra flags override the recipe +rdsp setup # first node: starts a Ray cluster and prints the join command +rdsp setup --join
# every other node: the command the first node printed +rdsp train Qwen/Qwen3.5-9B # every GPU in the cluster ``` -`recipes/` has one script per Qwen3.5-2B and 4B layout in [docs/BENCHMARK_RESULTS.md](docs/BENCHMARK_RESULTS.md), plus a text-only Qwen3 recipe; the 9B to 35B runs are scripts in `bench/`. [docs/GETTING_STARTED.md](docs/GETTING_STARTED.md) covers the flags, your own data and the environment variables. +`rdsp train` decides what you don't set: pipeline stages (`-pp`, the fewest that fit in memory, each inside one node), tensor parallelism (`-tp`, 1) and data-parallel copies of each stage (`-dp`, the remaining GPUs). It prints the layout and the command before it runs. `--tune` times the stages first and re-cuts them by the times; a vision-language model's vision encoder also gets a stage of its own, sized by the timing. Flags after `--` go to the training script. On one machine, skip `rdsp setup`. More: [docs/GETTING_STARTED.md](docs/GETTING_STARTED.md). ## Python API ```python -import ray, ray_deepspeed_pipeline as rdsp - -def count_tokens(labels): # tokens the loss is computed on - return int((labels[:, 1:] != -100).sum()) +import ray +import ray_deepspeed_pipeline as rdsp ray.init() engine, _, _, _ = rdsp.initialize( - model=model, # HF model, built under accelerate.init_empty_weights() + model=model, # HF model built under accelerate.init_empty_weights() weights="/path/to/hf/checkpoint", # each stage loads only its own tensors - config=ds_config, # DeepSpeed config dict - loss_fn=rdsp.TokenMeanLoss(rdsp.next_token_loss_sum, count_tokens), # mean over the step's tokens + config=ds_config, # an ordinary DeepSpeed config + loss_fn=rdsp.TokenMeanLoss(), # next-token loss, averaged over the step's tokens pipeline_config=rdsp.PipelineConfig( stages=2, - partition=rdsp.BalancedTransformerBlocks(vision_token_ratio=ratio), - stage_overrides=(rdsp.StageOverride(stage=0, num_gpus=4, tp=2, zero_stage=1), - rdsp.StageOverride(stage=1, num_gpus=4, tp=2, zero_stage=1)), + partition=rdsp.BalancedTransformerBlocks(), + stage_overrides=( + rdsp.StageOverride(stage=0, num_gpus=4, tp=2), + rdsp.StageOverride(stage=1, num_gpus=4, tp=2), + ), ), ) -loss = engine.train_batch(data_iter) # consumes exactly M (inputs, labels) entries +loss = engine.train_batch(data_iter) # one optimizer step engine.save_checkpoint("ckpt/", tag="step100") ``` -If the input embedding and output layer share a weight and land on different stages, untie them first (`train_vl.py --untie-embeddings`); on one stage they stay tied. The docstrings in `src/ray_deepspeed_pipeline/` give each public name's guarantees and errors. `train_vl.py` is a complete training script. - -## How it works - -- **Planning.** `rdsp.initialize` lowers the config into an immutable plan: where the model is cut, each stage's GPUs and DeepSpeed config, and a hash that binds checkpoints. Every check, including the cluster's GPU count, runs before any actor starts. -- **Stages.** Each stage runs the HF model's own `forward`. Blocks outside the stage pass their input through, and a hook injects what arrived from upstream. No per-architecture code is needed. -- **Step.** The driver hands each stage its 1F1B schedule, which interleaves forward and backward microbatches. Each stage applies its optimizer step only after every stage reports its backward done. -- **Failures.** A failure before any update raises `StepFailed`: weights are unchanged and a retry is exact. A failure during the update raises `PipelinePoisoned` until a checkpoint is loaded. - -Vision encoder placement, how the cuts are chosen, memory, and the reasoning behind the design: [docs/ENGINEERING.md](docs/ENGINEERING.md). - -## Model coverage - -| Builder | Models | Validation | -|---|---|---| -| `HFModelStage` | Any HF model with a `config`: Llama, Mistral, Qwen2/3/3.5, Qwen3-MoE, Mixtral, Gemma 1–3, Phi-3, OLMo2, Granite, Cohere, StarCoder2, StableLM, DeepSeek-V3, GLM-4/4-MoE/5.3, GPT-2, GPT-NeoX, Falcon, Bloom, Mamba, Qwen3-VL, Qwen3.5-VL | Pipeline loss equals the unsplit model's on CPU (`tests/integration/test_hf_families.py`, `tests/integration/test_vl_pipeline.py`). Qwen3, Qwen3-MoE and Qwen3.5-VL validated on GPU. | -| `CausalLMStage` | Llama, Qwen3, Qwen3-MoE | GPU-validated in every layout in `src/ray_deepspeed_pipeline/support_matrix.py` | -| `GenericSequentialStage` | Plain sequential models | CPU | - -TP inside a stage uses the model's AutoTP plan. Configs without one get a plan for the standard projection names. Qwen3-VL injects vision features into its first decoder blocks, so its encoder can't be colocated and the first cut must come after them. - -## Tests - -```bash -pytest -q # CPU: full runtime on Ray with a stub engine (about 630 tests); GPU tests skip -ruff check . -``` - -On a node with GPUs and DeepSpeed (`bench/setup_node.sh`), the same command also runs the GPU tests: parity against the unsplit model, checkpoint round trip and rank-kill recovery. +If the input embedding and output layer share a weight and land on different stages, untie them first (`train_vl.py --untie-embeddings`); on one stage they stay tied. The docstrings in `src/ray_deepspeed_pipeline/` give each public name's guarantees and errors. `train_vl.py` is a complete training script, and [examples/](examples) trains Qwen3.5-9B, 27B and 35B-A3B with the Python API on 16 GPUs. ## Docs | | | |---|---| -| [GETTING_STARTED](docs/GETTING_STARTED.md) | Install, recipes, flags, environment variables, rerunning the benchmarks | -| [BENCHMARK_RESULTS](docs/BENCHMARK_RESULTS.md) | Qwen3.5-2B and 4B results, per-layout settings, what moved the numbers | -| [ENGINEERING](docs/ENGINEERING.md) | Design | - -## Limitations - -- **Scale.** Benchmarked on one 8-GPU node and on two 8× H100 nodes. Two nodes is the most it has run on. -- **Schedule.** 1F1B only, no interleaved stages. No global-norm gradient clipping: a nonzero `gradient_clipping` is rejected. -- **Weights.** No parameters tied across stages. -- **Colocated vision.** It matches the unsplit model. On 32 GB GPUs it needs encoder recompute and is slower; on 80 GB H100s it was the fastest Qwen3.5-4B layout. -- **Balanced cuts.** The cost model ignores communication and counts MoE experts in full, not by the active fraction. `ExplicitCuts` overrides it. -- **Checkpoints.** Node-local: they survive actor loss, not node loss. A stage that spans nodes needs shared storage. +| [GETTING_STARTED](docs/GETTING_STARTED.md) | Install, recipes, flags, environment variables, reproducing every result | +| [BENCHMARK_RESULTS](docs/BENCHMARK_RESULTS.md) | Every result with its layout and caveats, and the validated layouts | +| [ENGINEERING](docs/ENGINEERING.md) | How it works, model coverage, tests, limitations | +| [bench](bench/README.md) | The benchmark scripts | diff --git a/training/rdsp/bench/README.md b/training/rdsp/bench/README.md index b7b31f67b..70c06c345 100644 --- a/training/rdsp/bench/README.md +++ b/training/rdsp/bench/README.md @@ -1,27 +1,34 @@ -# bench - -The benchmark scripts: rdsp against Megatron-Bridge, MegatronMIMO and TorchTitan on Qwen3.5. How to run each one, the settings held equal and the numbers: [docs/GETTING_STARTED.md](../docs/GETTING_STARTED.md#reproducing-the-blogs-results). Every script writes into a `logs/` folder next to it, which stays out of git. - -| Experiment | Script | What it writes | -|---|---|---| -| Set up a fresh GPU node | `setup_node.sh` | `~/venv`, the NeMo container | -| Qwen3.5-2B and 4B, one node, against MIMO and Bridge | `qwen35_small/bench.sh` | `~/bench//r/.log`, `summary.txt` | -| Qwen3.5-35B-A3B, two nodes: prepare both nodes | `qwen35_35b/prep.sh` (runs `node_prep.sh` on each) | `qwen35_35b/logs/prep/` | -| 35B: rdsp, vision encoder on its own stage | `qwen35_35b/rdsp_vision_stage.sh` | `qwen35_35b/logs/vision_stage/rdsp-k*.log` | -| 35B: rdsp, TP1 × PP8 × DP2 | `qwen35_35b/rdsp_pp8dp2.sh` | `qwen35_35b/logs/pp8dp2/rdsp*.log` | -| 35B: Bridge, TP1 × PP8 × DP2 | `qwen35_35b/bridge_pp8dp2.sh` | `qwen35_35b/logs/pp8dp2/bridge*.log` | -| 35B: Bridge, TP1 × PP2 × EP8 (NVIDIA's layout) | `common/runs.sh custom-megatron` through `cluster/both.sh` (the command is in GETTING_STARTED) | `qwen35_35b/logs/pp2ep8/bridge-pp2ep8-nv.log` | -| 35B: TorchTitan, FSDP over 16 GPUs | `qwen35_35b/torchtitan.sh` | `qwen35_35b/logs/fsdp16/--node.log` | -| 35B: rdsp, ZeRO-3 over 16 GPUs | `qwen35_35b/rdsp_zero3.sh` | `qwen35_35b/logs/fsdp16/rdsp-zero3*.log` | -| Qwen3.5-27B: prepare both nodes (35B prep, then the 27B) | `qwen35_27b/prep.sh` | `qwen35_27b/logs/prep/` | -| 27B, one node, TP1 × PP8: Bridge or rdsp | `qwen35_27b/pp8.sh` (rdsp side: `rdsp_pp8.sh`) | `qwen35_27b/logs/pp8/` | -| 27B: rdsp with recompute set per stage | `qwen35_27b/rdsp_tune.sh` | its output (GETTING_STARTED's commands save it in `qwen35_27b/logs/pp8/`) | -| 27B: one node's whole queue | `qwen35_27b/one_node.sh` | `qwen35_27b/logs/pp8/`, `torchtitan/logs/` | -| 9B against MIMO, one node | `mimo/mimo_9b.sh` | `mimo/logs//`, `mimo/logs/sweep/` | -| 9B: Bridge against rdsp, TP4 × PP2, and the 9B prep | `mimo/bridge_9b.sh` (rdsp side: `rdsp_9b_tp4pp2.sh`) | `mimo/logs/9b_tp4pp2dp1/` | -| 27B against MIMO, two nodes: rdsp's side | `mimo/rdsp_27b.sh` | `mimo/logs/27b_v1_tp4pp2dp1/rdsp-9gpu.log` | -| 27B against MIMO: MIMO with Bridge's memory settings | `mimo/patch_mimo.py` (`patch.diff`: the result) | a patched copy of MIMO's launcher in `/tmp` | -| TorchTitan on Bridge's rows | `torchtitan/run.sh` (one node), `torchtitan/run_two_node.sh`, `torchtitan/setup_box.sh` | `torchtitan/logs/` | -| Vision encoder alone | `encoder/enc_bench.py`, `encoder/grids.py` | the JSON given with `--out` | -| Two-node helpers | `cluster/both.sh`, `ray_cluster.sh`, `efa_env.sh`, `nccl_check.sh` | `~/both-