diff --git a/training/rdsp/.gitignore b/training/rdsp/.gitignore index 732c56160..fc99446af 100644 --- a/training/rdsp/.gitignore +++ b/training/rdsp/.gitignore @@ -9,33 +9,51 @@ __pycache__/ dist/ build/ -# raw run logs and profiles +# 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... -bench/**/logs*/* -bench/**/profiles*/ -bench/**/prep/ -bench/mimo_vs_rdsp/sweep/ -bench/mimo_vs_rdsp/convert.log +# 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/ *.sqlite *.nsys-rep *.qdrep *.pt.trace.json *.dmon -# benchmark logs and raw results stay local: docs/REPRODUCE.md names the log -# each run writes; the write-ups (*.md) are kept -bench/published/ -bench/blog_round/logs27b/ -bench/encoder_test/results/** -!bench/encoder_test/results/**/ -!bench/encoder_test/results/**/*.md -bench/torchtitan/results/data_check.txt +# 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/CONTEXT.md b/training/rdsp/CONTEXT.md deleted file mode 100644 index cf8b94c0b..000000000 --- a/training/rdsp/CONTEXT.md +++ /dev/null @@ -1,167 +0,0 @@ -# rdsp - -Pipeline-parallel training in which one CPU process hands each GPU its work and every GPU trains its share of the model with DeepSpeed. This glossary fixes the words we use for rdsp and for comparing it with Megatron-Bridge and MegatronMIMO. - -## Language - -### Processes - -**Driver**: -The single CPU process that plans each training step and gives every GPU its work. It holds no model weights and no activations. -_Avoid_: controller, master, launcher - -**Stage worker**: -The Ray actor that owns one GPU and trains that GPU's part of one stage. -_Avoid_: worker, actor, rank (a rank is a number in a group, not the process) - -### Pipeline layout - -**Stage**: -A consecutive slice of the model, together with the GPUs that train it. The first stage can also hold the vision encoder, and the last stage holds the loss. -_Avoid_: partition, pipeline rank, module (MegatronMIMO uses "module" for a whole sub-model) - -**Stage world**: -The `torch.distributed` group of one stage's GPUs. Tensor and data parallelism happen inside it, and it does not know that other stages exist. -_Avoid_: process group, mesh - -**Cross-stage groups**: -The two NCCL groups, `fwd` and `bwd`, that span every GPU and carry only boundary tensors. -_Avoid_: P2P world, pipeline group - -**Boundary tensor**: -The activation sent forward to the next stage, or its gradient sent back, for one microbatch. -_Avoid_: message, payload - -**Cut**: -The number of decoder layers each stage holds, written in stage order, e.g. 13 | 19. -_Avoid_: split, partition, boundary - -**Balanced cut**: -rdsp's default cut. It gives each stage an equal share of the estimated compute, and that estimate includes the vision encoder. -_Avoid_: auto cut, smart cut - -**Measured cut**: -A balanced cut redone from what a few profiled steps measured: each stage's time per step, and its memory as a limit on how many layers it may gain. -_Avoid_: calibrated cut, tuned cut - -**Even cut**: -A cut with the same number of decoder layers on every stage. Megatron uses it by default, and it does not count the vision encoder. -_Avoid_: uniform split, default split - -### Vision placement - -**Shared first stage**: -The vision encoder runs on the first stage's GPUs, ahead of that stage's decoder layers. -_Avoid_: colocated, encoder on stage 0 - -**Vision-only stage**: -The vision encoder is a stage of its own and holds no decoder layers. -_Avoid_: non-colocated, separate encoder - -**Replicated encoder**: -Every GPU holds a copy of the vision encoder outside the pipeline. Each copy encodes a share of the images and sends the features to the first stage. -_Avoid_: colocated vision, colocated - -### Parallelism inside a stage - -**DP copy**: -One of a stage's data-parallel replicas. It holds the stage's full slice of the model (split across its TP GPUs) and trains on different rows from the other copies. -_Avoid_: replica, DP rank - -### Training step - -**Row**: -One training sample (an image, its prompt and its answer) as a single token sequence. -_Avoid_: sample, example, sequence - -**Step**: -One optimizer update, covering every row of the batch. -_Avoid_: iteration - -**Microbatch**: -The group of rows that moves through the pipeline as one unit. -_Avoid_: chunk, minibatch - -**Microbatch count**: -How many microbatches make up one step. It sets the size of the bubble. -_Avoid_: accumulation steps, number of microbatches - -**Microbatch size**: -The number of rows in one microbatch, counted across all DP copies of a stage. -_Avoid_: batch size, micro batch size per GPU - -**Job list**: -The ordered forwards and backwards that one stage runs in one step, delivered to it in a single call. -_Avoid_: op list, command list, schedule - -**1F1B**: -The job-list order in which a stage runs its warm-up forwards and then alternates one forward with one backward. -_Avoid_: interleaved schedule, PipeDream - -**Bubble**: -The share of a step during which a stage sits idle, waiting for a neighbouring stage. -_Avoid_: pipeline stall, idle time - -**Apply**: -The optimizer update at the end of a step. It starts on any stage only after every stage has finished all its backwards. -_Avoid_: optimizer step, update - -### Model - -**GDN layer**: -A Gated DeltaNet decoder layer: Qwen3.5's linear-attention layer type. Qwen3.5-4B has 24 of them next to 8 full-attention layers. -_Avoid_: linear layer, DeltaNet, SSM layer - -**Remainder master**: -Exact fp32 master weights kept as the bf16 weights plus the 16 bits the rounding dropped, 2 bytes per parameter instead of 4. -_Avoid_: bf16 master (that one is not exact), compressed master - -**Untied output layer**: -The last stage's own copy of the output-layer weight, which the original model shares with the input embedding on stage 0. -_Avoid_: lm head copy, duplicated embedding - -### Failure - -**Rebuild**: -Recovery that replaces every stage worker and reloads the last checkpoint, while the driver and the Ray cluster keep running. -_Avoid_: restart, failover, elastic recovery - -### Data and loss - -**Replayed data**: -The rows that Megatron-Bridge exported, given to rdsp in the same order and the same microbatch groups, so that both systems train on identical input. -_Avoid_: shared dataset, same data - -**Real token**: -A position that holds an actual token of the row: an image, prompt or answer token. -_Avoid_: valid token, non-pad token - -**Answer token**: -A real token from the row's answer. It is the only kind of token with a label, so it is the only kind that counts in the loss. -_Avoid_: caption token, supervised token, label token - -**Padding**: -Positions added after a row's last real token so that the rows in a microbatch share one length. They are computed, but they never count in the loss. -_Avoid_: pad tokens, filler - -**Positions per real token**: -The number of positions computed, divided by the number of real tokens. It measures how much compute goes to padding. -_Avoid_: padding ratio, efficiency - -**Token-mean loss**: -A step's loss taken as the plain average over every answer token in the step, whichever microbatch or GPU holds the token. -_Avoid_: per-token loss, global mean - -**Microbatch-mean loss**: -A step's training loss taken as the average of each rank-microbatch's own answer-token average: each data-parallel rank's share of a microbatch is averaged on its own. Tokens in rank-microbatches with fewer answer tokens count for more. The reported loss is still the token mean. -_Avoid_: per-microbatch loss, mean of means - -### Comparison - -**Recipe comparison**: -A benchmark with the same layout, data, batch, microbatch count, optimizer and loss on both systems. Each system keeps its own padding, cut and kernels. -_Avoid_: same settings, apples-to-apples, fair comparison - -**Equal-work comparison**: -A recipe comparison in which both systems also compute the same token positions. -_Avoid_: same settings, apples-to-apples diff --git a/training/rdsp/README.md b/training/rdsp/README.md index dd1863114..157004811 100644 --- a/training/rdsp/README.md +++ b/training/rdsp/README.md @@ -17,9 +17,9 @@ Qwen3.5 vision-language models on H100 GPUs, trained on CORD-v2. Median time per - 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 choosing how many of its layers to recompute. 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. +- 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. -One run per configuration. Settings and commands for each number: [docs/REPRODUCE.md](docs/REPRODUCE.md). Earlier Qwen3.5-2B and 4B results on 8 GPUs: [docs/BENCHMARK_RESULTS.md](docs/BENCHMARK_RESULTS.md). +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). ## Install @@ -29,7 +29,7 @@ Linux, CUDA GPUs, Python 3.12. On a fresh node: bash bench/setup_node.sh ``` -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. To install by hand, or without the container: [docs/GETTING_STARTED.md](docs/GETTING_STARTED.md#install). +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. @@ -40,7 +40,7 @@ Importing `ray_deepspeed_pipeline` doesn't import Ray or DeepSpeed; only the sta ./recipes/qwen35-2b-tp2pp2dp2.sh --steps 200 # extra flags override the recipe ``` -`recipes/` has one script per benchmarked layout, plus a text-only Qwen3 recipe. [docs/GETTING_STARTED.md](docs/GETTING_STARTED.md) covers the flags, your own data, and common failures. +`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. ## Python API @@ -67,7 +67,7 @@ loss = engine.train_batch(data_iter) # consumes exactly M (inputs, labels) ent 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. Every public name, what it guarantees and what it raises are listed in [docs/CONTRACTS.md](docs/CONTRACTS.md). `train_vl.py` is a complete training script. +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 @@ -82,8 +82,8 @@ Vision encoder placement, how the cuts are chosen, memory, and the reasoning beh | 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`). Qwen3, Qwen3-MoE and Qwen3.5-VL validated on GPU. | -| `CausalLMStage` | Llama, Qwen3, Qwen3-MoE | GPU-validated in every layout in CONTRACTS.md | +| `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. @@ -91,20 +91,18 @@ TP inside a stage uses the model's AutoTP plan. Configs without one get a plan f ## Tests ```bash -pytest -q # CPU: full runtime on Ray with a stub engine (~500 tests); GPU tests skip +pytest -q # CPU: full runtime on Ray with a stub engine (about 630 tests); GPU tests skip ruff check . ``` -The GPU tests (parity against the unsplit model, checkpoint round trip, rank-kill recovery) run on Modal: `scripts/modal_tests.py`. +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. ## Docs | | | |---|---| -| [GETTING_STARTED](docs/GETTING_STARTED.md) | Install, terms, recipes, flags, your own data, common failures | -| [REPRODUCE](docs/REPRODUCE.md) | Rerun the benchmarks | +| [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 | -| [CONTRACTS](docs/CONTRACTS.md) | Public API guarantees, errors, supported layouts | | [ENGINEERING](docs/ENGINEERING.md) | Design | ## Limitations diff --git a/training/rdsp/bench/README.md b/training/rdsp/bench/README.md new file mode 100644 index 000000000..b7b31f67b --- /dev/null +++ b/training/rdsp/bench/README.md @@ -0,0 +1,27 @@ +# 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-