Repository navigation
[WS2][CUDA][MiniMax-H3] weight-sharded full model: each TP rank loads only its projection shards, bitwise against the single-GPU run (RFC #420 final_distributed_h3_run) - #732
Conversation
run_tp_block_rows takes an optional shards mapping; given one, the sharded projections (Q/K/V, attention output, FFN hidden/gate halves, FFN output) use those tensors instead of cutting them from the full weights on each call. A block carrying _rlk_tp_shards passes them on and refuses a grid whose (tp, tp_rank) differs from the one they were cut for. parallel_model_execution gains strict_boundaries (default True), passed to full_model_execution, so the boundary modules can stay on the provider on GPUs the strict boundary rows do not support. Signed-off-by: Wenbo Ji <[email protected]>
load_sharded_model builds MiniMaxH3Transformer3DModel with parameters on meta, loads every other parameter in full as stored, and reads each sharded projection's shard through a safetensors slice, with the bounds of parallel.shard_rows / shard_cols. The full projection weights stay on meta and are never read; the shards are stored on each block. CPU tests on a tiny sharded checkpoint: for tp 1/2/4/8 and every rank the loaded parameters equal from_pretrained (dtype and bytes), the projection weights stay on meta, and every stored shard equals the harness's cut of the full weight. cut_shard refuses the shapes the harness refuses. Signed-off-by: Wenbo Ji <[email protected]>
--sharded frees the full model after the canonical run and runs the grid on load_sharded_model, so the bitwise comparison against the canonical run covers ranks that never hold the full projection weights. The report records resident parameter bytes for both models and the peak during the grid run. --provider-boundaries keeps the boundary modules on the provider in both runs (the strict boundary rows need SM90). Signed-off-by: Wenbo Ji <[email protected]>
…er-boundaries) Signed-off-by: Wenbo Ji <[email protected]>
… the grid load_sharded_model builds the model under accelerate.init_empty_weights (include_buffers=False), a declared dependency, instead of its own copy of that context manager. F.linear with a meta weight returns a meta tensor instead of raising, so a sharded model called outside parallel_model_execution would run on with no values. Each projection left on meta now carries a forward pre-hook that raises; the parallel blocks read the stored shards and never call those modules. Tested on CPU; the loader tests skip without accelerate, which from_pretrained also needs. Signed-off-by: Wenbo Ji <[email protected]>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
… feat/h3-sharded-model at 8132b97) Signed-off-by: Wenbo Ji <[email protected]>
|
🔍 OpenCodeReview found 2 issue(s) in this PR.
📄
|
|
@fusheng-ji The automated OCR review has completed. Please review and address all automated review bot findings, then push your updates. Maintainers will begin manual review after the bot findings have been addressed. |
The projection shards are cut from the stored tensor's own shape, so a checkpoint whose projection differs from the model's was cut without complaint and failed only later, if at all. load_sharded_model now refuses a stored projection whose shape is not the model's parameter shape, naming it, before any shard is cut. Signed-off-by: Wenbo Ji <[email protected]>
…parallel-lora Signed-off-by: Wenbo Ji <[email protected]>
…e67d5d on H100: 23 runs with strict boundaries, 16 bitwise, 4 inject controls caught at block 17; suites: nothing fails only at RL-Align#733 Signed-off-by: Wenbo Ji <[email protected]>
… (7 of RL-Align#732, 12 of RL-Align#733), not 16 Signed-off-by: Wenbo Ji <[email protected]>
…L-Align#735) on H100 pending/h3-hopper-final-run: round 1 (RL-Align#732 / RL-Align#733 strict grids, RL-Align#735 strict rollout, RL-Align#731 on RL-Align#730 PR A steps) and round 2 (RL-Align#731 / RL-Align#735 tests at their round-2 heads, RL-Align#733's two ring-attention tests). Redacted; the binary call captures are left out. Signed-off-by: Wenbo Ji <[email protected]>
…quest time) and RL-Align#743 (row time) Drawn from the numbers already published with those PRs. Signed-off-by: Wenbo Ji <[email protected]>
… feat/h3-sharded-model at 8132b97) Signed-off-by: Wenbo Ji <[email protected]>
…L-Align#735) on H100 pending/h3-hopper-final-run: round 1 (RL-Align#732 / RL-Align#733 strict grids, RL-Align#735 strict rollout, RL-Align#731 on RL-Align#730 PR A steps) and round 2 (RL-Align#731 / RL-Align#735 tests at their round-2 heads, RL-Align#733's two ring-attention tests). Redacted; the binary call captures are left out. Signed-off-by: Wenbo Ji <[email protected]>
…quest time) and RL-Align#743 (row time) Drawn from the numbers already published with those PRs. Signed-off-by: Wenbo Ji <[email protected]>
… feat/h3-sharded-model at 8132b97) Signed-off-by: Wenbo Ji <[email protected]>
…L-Align#735) on H100 pending/h3-hopper-final-run: round 1 (RL-Align#732 / RL-Align#733 strict grids, RL-Align#735 strict rollout, RL-Align#731 on RL-Align#730 PR A steps) and round 2 (RL-Align#731 / RL-Align#735 tests at their round-2 heads, RL-Align#733's two ring-attention tests). Redacted; the binary call captures are left out. Signed-off-by: Wenbo Ji <[email protected]>
…quest time) and RL-Align#743 (row time) Drawn from the numbers already published with those PRs. Signed-off-by: Wenbo Ji <[email protected]>
What
Sharded loading (
rl_engine/validation/models/h3_sharded_load.py):load_sharded_model(transformer_dir, tp, tp_rank, device):MiniMaxH3Transformer3DModelfrom its config underaccelerate.init_empty_weights(include_buffers=False): parameters onmeta, buffers made for real;ff.net.0.proj, andff.net.2through a safetensors slice, so the rest of those weights is never read;(tp, tp_rank)they were cut for. The full projection weights stay onmeta, and those projections raise if called:F.linearwith ametaweight returns ametatensor instead of failing, so without the hook a sharded model called outside the grid would run on with no values.The shard bounds are those of
parallel.shard_rows/shard_cols(cut_shardruns their checks on ametastand-in first), so the shards are the bytes [WS2][CUDA][MiniMax-H3] ws2 full model: ring context parallel, CP weight gradients and the 50-block H3 on TP x CP x SP, bitwise against the single-GPU run (RFC #420 follow-up 3/3) #701's harness cuts.Grid blocks use the stored shards (
h3_tp.run_tp_block_rows(..., shards=),h3_parallel_model): a block that carries shards passes them to the block rows instead of cutting them from the full weights, and refuses a grid whose(tp, tp_rank)differs from theirs. Without stored shards nothing changes.Runner (
tools/validation/models/h3_parallel_full_model.py):--sharded: after the canonical run (full model,Grid(1, 1)), the full model is freed and each rank loads the sharded model and runs its grid. The comparison is [WS2][CUDA][MiniMax-H3] ws2 full model: ring context parallel, CP weight gradients and the 50-block H3 on TP x CP x SP, bitwise against the single-GPU run (RFC #420 follow-up 3/3) #701's: video / audio velocity, the three input gradients, every block output and output gradient (first_drift), and the 350 weight-shard gradient digests. The report records the bytes each rank holds for both models and the peak during the grid run.--provider-boundariesleaves the boundary modules (patch and audio projections, heads, time embedder, final norm) on the provider in both runs (parallel_model_execution(..., strict_boundaries=False)), for GPUs the strict boundary rows do not support: the video projections need SM90.Docs:
docs/operators/h3-parallel.mddescribes the sharded run, and its Limits line about the runner is rewritten.6cfb8a57strict_boundariesoption3654dc4bload_sharded_model, with CPU testsa1945c33--sharded,--provider-boundaries7bf809c98132b974accelerate.init_empty_weightsinstead of a copy of it; projections left onmetarefuse to run outside the gridPrior art & reuse decision
MiniMaxH3Transformer3DModel._tp_plan,hooks.tensor_parallel._local_shard)f53d5520, 0.40.0.dev0) has no TP plan. It also turns the parameters intoDTensors whose forward hooks all-reduce through NCCL, while the H3 blocks here runh3-parallel-v1on plain tensors. It shardsadaln_proj.linearand the refiner blocks too, whichh3-parallel-v1does not.tp_plan="auto", vLLM weight loadersinit_empty_weights(include_buffers=False)8132b974).parallel.shard_rows/shard_cols,run_tp_block_rows, the runner)Decision: accelerate builds the empty model; the loader reads safetensors slices with
parallel's bounds and keeps the shards as plain tensors on the block; Diffusers 0.43's slicing is the cross-check below.Direct bitwise comparison with Diffusers 0.43's slicing
On the released checkpoint (
MiniMax-H3@42ed227, 50 blocks), for TP 2 / 4 / 8 and every rank, each checkpoint weight's shard fromh3_sharded_load.cut_shard(hidden and gate concatenated forff.net.0.proj) against_local_shardof Diffusers 0.43.0 under its_tp_plan(colwiseQ / K / V,rowwiseattention output andff.net.2,PackedColwiseParallel([1, 1])forff.net.0.proj), both read from the same safetensors slices: 4200 compared, 0 differ (50 blocks x 6 weights x 14 rank positions; CPU, torch 2.14.0). Script and report:diffusers-local-shard/.Results (B200 / Blackwell, 1 node x 8 GPUs)
Measured at head
8132b974in the repo environment: torch 2.13.0+cu130, the repo's H3 provider pin (Diffusersf53d5520, 0.40.0.dev0), 8 x B200 (cc 10.0) on one node,--attention h3_full,--provider-boundaries(see Status). In every run each rank first runs the canonical model (full checkpoint,Grid(1, 1)), then frees it, loads the sharded model for its own(tp, tp_rank), and runs its grid. Per rank, the comparison covers 8 checks: video and audio velocity, the three input gradients, every block output and output gradient, and the 350 weight-shard gradient digests. Reports:grids/.Weights held per rank. The bytes come from
resident_param_bytes: the loaded parameters plus the stored shards. They follow the checkpoint's split exactly:adaln_proj.linear;So each rank holds 25.84 + 35.89 / TP GiB, against 61.73 GiB for the full model. "Peak" is the most memory allocated on the rank during the grid's forward and backward (
parallel_peak_bytes, weights included). The Size column gives the requested size; the harness packs size 928 into 1008 rows, while 40 and 925 stay as they are.Negative controls. In each control one rank adds a perturbation to one row of block 17's output, on the sharded model. The harness must report that exact row as the first difference.
--inject(block:row:rank)17:700:217:5:3In both controls every rank reports
all_bitwise: false, and the weight-shard gradient digests differ. The first backward difference is atblock.49.grad, where backward starts, because the changed row reaches every later block. Nothing differs before block 17.Results (H100 / Hopper, strict boundaries)
On H100 the boundary modules run their strict SM90 rows (#646), not the provider: no
--provider-boundaries. Measured at6c7e424con 2, 4 and 2 x 4 H100 80GB, torch 2.13.0+cu130, the H3 provider pin (round1/strict/S1/).Grid(1, 1), every rankblock.17on every rankEvery run reports
strict_boundaries: trueand no missing shard. Suite (tests/models/minimax_h3, 2 + 2 H100): 1416 passed, 144 skipped, and 2 ring-attention tests failed only because that command did not setRL_KERNEL_H3_WEIGHTS; with it set, both pass (round2/H5-733/, run on #733's head, which contains this PR).Memory per rank, B200 and H100
The weights held per rank are the same on both GPUs; the peak in the grid run differs by at most 0.15 GiB (the H100 values are rounded to 0.1 GiB). Every layout holds about half of the full model at TP4 and TP8 (34.81 and 30.33 GiB against 61.73 GiB).
Status
6c7e424c: measured at8132b974ontest-h3bb2a3ee1(Results, Tests). The maintainers have since mergedtest-h3in (ad93cdb0), and6c7e424c(History) makes the loader refuse a stored projection of the wrong shape, which the released checkpoint does not have. Every commit is signed off.--provider-boundaries), because the strict video projections need SM90 ([WS1][CUDA][MiniMax-H3] Add FP32 video output projection #646). The blocks run the stricth3-parallel-v1rows either way, and the canonical run uses the same boundaries, so the comparison is unchanged. On H100 the strict-boundary runs are bitwise on every layout (Results above).History
8132b974replaced the loader's own meta-device context manager with accelerate's and closed a silent path: a sharded model called outside the grid ran onmetatensors.6c7e424c: the projection shards were cut from the stored tensor's own shape, so a checkpoint whose projection differed from the model's was cut without complaint; the loader now refuses it, naming the tensor, before any shard is cut. Each finding has a reply.6c7e424c(Results).Tests
_Cbuilt in the checkout)pytest tests/models/minimax_h3at head8132b974pytest tests/models/minimax_h3at basetest-h3bb2a3ee1test_h3_token_refiner.py::test_nodes_accuracy_repeat_batch_and_isolated[1-257], which fails on B200 at base. The 10 extra passes are the new test file.test_h3_sharded_load.py,test_h3_parallel_model.py,test_h3_parallel.pytest_h3_sharded_load.pymypy --ignore-missing-imports rl_engine/(Python 3.10)New tests (
tests/models/minimax_h3/test_h3_sharded_load.py, CPU; skipped without Diffusers):cut_shardequalsparallel.shard_rows/shard_cols(and the two halves of a fused weight) for TP 1 / 2 / 4 / 8 and every rank, and refuses the shapes the harness refuses;from_pretrained(torch_dtype=bfloat16)in dtype and bytes, the buffers too, the projection weights stay onmeta, and every stored shard equals the harness's cut of the full weight;metaraise (8132b974).The checkpoint tests need Diffusers with the H3 transformer and accelerate and skip without them; CI has no Diffusers, so there only the
cut_shardtests run.Scope / Known limitations
adaln_proj.linear(24.23 GiB in all, about 0.48 GiB per block; Results), the norms, embedders, refiner and boundary projections. Shardingadaln_projis not part ofh3-parallel-v1.load_sharded_modelalone.parallel_model_executionwith the grid it was loaded for; another grid is refused, and outside the grid its projections raise.Summary by CodeRabbit