Skip to content

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 into
NVIDIA-NeMo:opt/dev-rubin-pinfrom
zongfeijing:zongfeij/trtllm-nccl-reshard-refit
Sep 21, 2026

Conversation

@zongfeijing

@zongfeijing zongfeijing commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

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

  1. converts only the experts a rank stores (initial_local_expert_ids) during FP8/MXFP8 refit (5.5-15 s -> <0.3 s per rank);
  2. adds the nccl_reshard transport to the TRT-LLM backend: the trainer sends each routed expert straight to the engine rank
    that 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;
  3. sends every generation layout concurrently on the trainer (one CUDA stream per layout, each layer materialized once);
  4. on the engine, batches the received expert stacks under a byte budget and loads them straight into their MoE modules,
    replaying the loader's MoE branch instead of a whole-model reload (which walked all 1749 modules and synchronized the
    receive stream per stack, serializing the receive loop);
  5. skips gc.collect() / torch.cuda.empty_cache() in offload_before_refit (and the mid-refit empty_cache) by default
    when 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);
  6. logs per-phase refit timings on the engines ([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)

refit bubble / step steady train step
MXFP8 rollouts, collective (before) 20.7-21.6 s 202-209 s
MXFP8 rollouts, this PR 2.5-2.8 s 176-183 s
bf16 rollouts, collective (before) 6.0 s 173-192 s
bf16 rollouts, this PR 1.6-2.1 s 171-186 s
Accuracy unchanged (pass_k 0.745-0.753 vs 0.749-0.757 before). Remaining refit time: trainer-side per-param PP broadcast + TP
gather of the non-expert tensors (~1 s), the MoE module's per-expert load loop (~1 s).

Smokes (bf16, two training steps each)

  • aggregated TP8/EP8 x 4 replicas: refit bubble 4.8 / 5.1 s (about 2.4 s of it is the pre-existing torch.compile restore), rewards 0.29 / 0.38
  • 2 context TP8 + 1 generation TP16: refit bubble 1.8 / 1.6 s, rewards 0.28 / 0.35

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_support rejects 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-existing
failures of the pin lineage (trtllm: pytest-asyncio, _engine_owner_indices, collective sync order; weight_sync: 2 regex) are
unchanged; no new failures.

Commits

  1. trtllm refit: convert only this rank's routed experts to FP8/MXFP8
  2. trtllm: 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)
  3. trtllm nccl_reshard refit: batch the received expert stacks and load them straight into their MoE modules
  4. megatron refit offload: skip gc.collect and empty_cache under nccl_reshard; time the misc producer

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]>
@zongfeijing
zongfeijing requested review from a team as code owners September 21, 2026 01:49
@copy-pr-bot

copy-pr-bot Bot commented Sep 21, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@hchings
hchings merged commit 66870b4 into NVIDIA-NeMo:opt/dev-rubin-pin Sep 21, 2026
3 of 5 checks passed
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]>
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants