Repository navigation
trtllm: shard-to-shard (nccl_reshard) refit for the TRT-LLM backend, with local-expert quantization and a reshard-aware trainer offload - #4217
Merged
hchings merged 4 commits intoSep 21, 2026
Conversation
The refit broadcast hands every generation rank the full [E, ...] routed
expert stacks, and the FP8/MXFP8 conversion in
nemo_rl/models/generation/trtllm/quantization/fp8.py cast all E experts on
every rank before TRT-LLM kept only the slots in its
initial_local_expert_ids (EP16 keeps 32 of 512). On Qwen3.5-397B that is
~5.5 s (15 s cold) of unfused fp32 casts per rank per refit, all of it on
the refit critical path because the conversion runs per bucket inside the
packed-broadcast consumer; it accounted for most of the MXFP8 refit bubble
(21 s vs 6 s in bf16).
build_local_expert_lookup(model) reads the same initial_local_expert_ids /
layer_idx attributes the loader uses (MTP experts are named mtp.layers.<i>
in the checkpoint and carry layer_idx = num_hidden_layers + i at runtime)
and returns None when an expert load balancer is active, since the balancer
may need experts outside the initial assignment. load_weights(...,
local_experts=) then gathers just those experts (one index_select) and
converts/emits them, with identical numerics; unknown prefixes and split
per-expert names are handled the same way. The backend builds the lookup in
prepare_refit_info and passes it on both the collective and the IPC paths.
Also print the traceback when update_weights_from_collective fails: the
extension swallowed the exception and printed only its message, which left a
disaggregated refit failure ('bool' object is not callable) with no frame to
act on.
Signed-off-by: Zongfei Jing <[email protected]>
The TRT-LLM backend only had the collective refit transport: trainer rank 0 packed-broadcasts the whole bf16 model to every generation rank, so each of the 24 ranks of a 1P8+1D16 Qwen3.5-397B deployment receives ~790 GB per refit (6 s bubble in bf16). vLLM's recipes default to refit_transport nccl_reshard, which moves the routed experts shard-to-shard with xferdtensor and broadcasts only the misc params. Generation side (NcclExtension): init_nccl_reshard_comm_group joins the per-PP-stage bulk communicators under the same executor-parked bracket as init_collective; prepare_nccl_reshard_refit_info restores the plan and builds one LocalParamSpec per grouped routed-expert projection whose pre allocates this rank's canonical [E_local, out, in] bf16 staging buffer and whose post converts it (FP8/MXFP8 engines quantize the local experts only, via convert_expert_projection_stack) and hands per-expert HF names to the loader. The EP slice must be exactly the module's initial_local_expert_ids, otherwise the refit fails instead of silently updating a subset; bulk params that are not grouped experts are rejected because they would need this engine's TP layout. nccl_reshard_refit receives the bulk params per stage, then the misc packed broadcast through the shared per-bucket reload, then finalizes exactly like the collective path. Engines come in one layout per role: under prefill/decode disaggregation the context (TEP8) and generation (TEP16) engines differ, and xferdtensor needs one destination mesh per transfer. TrtllmGeneration therefore exposes get_nccl_reshard_layouts() and dispatches the communicator setup and the refit plan per layout; the synchronizer builds the bulk communicators and asks the policy for a plan once per layout; the trainer keeps one bulk communicator and plan per layout, sends the bulk params once per layout and broadcasts the misc params once. Single-layout backends (vLLM, Megatron generation) keep their previous call shapes. check_nccl_reshard_refit_support and the setup gate accept the trtllm backend when every engine role is pure expert-parallel, PP is 1 and in-flight weight updates are off. The reshard receive runs in the same control_action bracket as the collective refit, so it takes the in-flight weight update too: the generation layer passes drain=not in_flight_weight_updates and the recompute flag exactly as update_weights_from_collective does. Under prefill/decode disaggregation the trainer sends the bulk expert weights to two generation layouts (context and generation engines), each behind its own communicator. Sent back to back, every trainer rank fed one destination P2P pair at a time while the second layout's receivers idled; each layer is now materialized once and enqueued to every layout on a per-layout CUDA stream so both transfers are in flight together. A single layout keeps the caller's stream unchanged, and the single-layout synchronizer call shapes (vLLM, Megatron generation) do not change: only the multi-layout path passes layout_index to the policy. Each generation engine's rank 0 prints one [refit-timing] line per refit (drain, transfer and load split into conversion and reload, finalize, recompute, compile restore) for both the collective and the nccl_reshard paths; the trainer prints its bulk send time per layout, the misc broadcast time and the offload_before_refit phases; the controller prints the sync-params / offload / transfer split around sync_weights. Signed-off-by: Zongfei Jing <[email protected]>
…them straight into their MoE modules The receiving engine converted and reloaded every received expert projection stack with its own model_loader.reload call. Each call walks the whole module tree and ends with a stream synchronize, so every stack stalled the receive loop until all transfers enqueued so far had landed, and the bulk phase kept running for seconds after the last byte arrived. Queue the converted stacks until NRL_TRTLLM_REFIT_RELOAD_BATCH_BYTES (default 2 GiB) of converted weights are pending, or the PP stage ends, and load them in one go by replaying the loader's MoE branch (preprocess_weights, filter_weights, the mapper's special-instance hook or the module's load_weights) for just the modules the stacks belong to, leaving the copies enqueued on the receive stream. Weights no MoE module owns still go through the loader; NRL_TRTLLM_REFIT_DIRECT_EXPERT_LOAD=0 restores the loader path and a batch budget of 0 restores one load per stack. The [refit-timing] line reports the accumulated host time of the bulk-path conversion and of the load calls, and the number of load calls. Signed-off-by: Zongfei Jing <[email protected]>
…shard; time the misc producer The collective transport packs the whole model through 5 GB buckets and wants every freed byte back before the refit. nccl_reshard moves the routed experts shard-to-shard and only the misc tensors through the buckets, so the 0.4-1.8 s of gc.collect and the 0.3-3 s of returning ~150 GB of freed segments to the driver (in offload_before_refit and again between the bulk transfer and the misc broadcast) were pure refit bubble; the caching allocator reuses those segments on the next step. Default them off when policy.generation.refit_transport is nccl_reshard; NRL_OFFLOAD_BEFORE_REFIT_GC and NRL_OFFLOAD_BEFORE_REFIT_EMPTY_CACHE set to 0 or 1 override either way. Report how much of the misc phase is spent producing the full tensors (PP broadcast + TP gather per param) versus the packed broadcast. Signed-off-by: Zongfei Jing <[email protected]>
shuyixiong
pushed a commit
that referenced
this pull request
Sep 23, 2026
…with local-expert quantization and a reshard-aware trainer offload (#4217) Signed-off-by: Zongfei Jing <[email protected]>
shuyixiong
pushed a commit
that referenced
this pull request
Sep 23, 2026
…with local-expert quantization and a reshard-aware trainer offload (#4217) Signed-off-by: Zongfei Jing <[email protected]>
2 of 3 tasks
3 of 4 tasks
shuyixiong
pushed a commit
that referenced
this pull request
Oct 29, 2026
…with local-expert quantization and a reshard-aware trainer offload (#4217) (cherry picked from commit 8a9efdc, adapted to main: TRT-LLM WorkerExtension refit lifecycle, prefill/decode disagg roles, spec.materialize(), no refit_payload_mode / sync_params, generation.disaggregation + trtllm_cfg.{prefill,decode}_engine in the nccl_reshard support check.) Signed-off-by: Zongfei Jing <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: shuyixiong <[email protected]>
shuyixiong
pushed a commit
that referenced
this pull request
Nov 3, 2026
…with local-expert quantization and a reshard-aware trainer offload (#4217) (cherry picked from commit 8a9efdc, adapted to main: TRT-LLM WorkerExtension refit lifecycle, prefill/decode disagg roles, spec.materialize(), no refit_payload_mode / sync_params, generation.disaggregation + trtllm_cfg.{prefill,decode}_engine in the nccl_reshard support check.) Signed-off-by: Zongfei Jing <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: shuyixiong <[email protected]>
shuyixiong
pushed a commit
that referenced
this pull request
Nov 4, 2026
…with local-expert quantization and a reshard-aware trainer offload (#4217) (cherry picked from commit 8a9efdc, adapted to main: TRT-LLM WorkerExtension refit lifecycle, prefill/decode disagg roles, spec.materialize(), no refit_payload_mode / sync_params, generation.disaggregation + trtllm_cfg.{prefill,decode}_engine in the nccl_reshard support check.) Signed-off-by: Zongfei Jing <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: shuyixiong <[email protected]>
shuyixiong
pushed a commit
that referenced
this pull request
Nov 12, 2026
…with local-expert quantization and a reshard-aware trainer offload (#4217) (cherry picked from commit 8a9efdc, adapted to main: TRT-LLM WorkerExtension refit lifecycle, prefill/decode disagg roles, spec.materialize(), no refit_payload_mode / sync_params, generation.disaggregation + trtllm_cfg.{prefill,decode}_engine in the nccl_reshard support check.) Signed-off-by: Zongfei Jing <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: shuyixiong <[email protected]>
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.
Summary
Refit of the TRT-LLM rollout engines went through the full-tensor collective broadcast: every engine rank received the whole
model (~790 GB) and converted all 512 routed experts to MXFP8 although it only stores its EP slice. This PR
initial_local_expert_ids) during FP8/MXFP8 refit (5.5-15 s -> <0.3 s per rank);nccl_reshardtransport to the TRT-LLM backend: the trainer sends each routed expert straight to the engine rankthat owns its EP slot over one communicator per PP stage, one destination layout per engine role under prefill/decode
disaggregation (context and generation engines have different TP/EP), and the non-expert tensors ride the existing packed
broadcast; in-flight weight updates are honoured like the collective path;
replaying the loader's MoE branch instead of a whole-model
reload(which walked all 1749 modules and synchronized thereceive stream per stack, serializing the receive loop);
gc.collect()/torch.cuda.empty_cache()inoffload_before_refit(and the mid-refitempty_cache) by defaultwhen the transport is
nccl_reshard: with no whole-model packing there is no memory spike to make room for, and returning~150 GB of freed segments to the driver cost 0.3-3 s per rank inside the bubble (
NRL_OFFLOAD_BEFORE_REFIT_GC/NRL_OFFLOAD_BEFORE_REFIT_EMPTY_CACHE= 0|1 override);[refit-timing]), the trainer (bulk send,misc produce,misc broadcast,[offload-timing]) and the controller.Results (Qwen3.5-397B GRPO, 1P8+1D16 disaggregated TRT-LLM, TP4 PP2 EP16 trainer, 16 nodes)
Smokes (bf16, two training steps each)
Config
policy.generation.refit_transport: nccl_reshard(TRT-LLM engines must be TEP:moe_expert_parallel_size == tensor_parallel_size,pipeline_parallel_size == 1;check_nccl_reshard_refit_supportrejects anything else). No other config change.Tests
tests/unit/models/generation/trtllm/test_trtllm_nccl_reshard.py(new: layouts, slices, local quantization, batching, direct load,synchronizer layouts, support check),
test_trtllm_fp8.py(+7 local-expert tests). On the image used here the pre-existingfailures of the pin lineage (trtllm: pytest-asyncio,
_engine_owner_indices, collective sync order; weight_sync: 2 regex) areunchanged; no new failures.
Commits
trtllm refit: convert only this rank's routed experts to FP8/MXFP8trtllm: shard-to-shard (nccl_reshard) refit for the TRT-LLM backend(backend, multi-layout synchronizer, in-flight updates, concurrent layouts on the trainer, per-phase timing)trtllm nccl_reshard refit: batch the received expert stacks and load them straight into their MoE modulesmegatron refit offload: skip gc.collect and empty_cache under nccl_reshard; time the misc producer