PR #4801 ยท main 5e271174 ยท #4801 1a2eca34 ยท #5025 62868966 ยท Megatron-LM e0a4bfed
Three pages on this PR, one question each. This one has everything about refit.
[8192, 4096] = [output features, input features], split by rows under TP, so a TP 2 trainer rank holds [4096, 4096], a TP 4 prefill rank [2048, 4096] and a TP 2 decode rank [4096, 4096]. Dotted words have a short explanation: hover or tap them.| backend | 1 ยท packed broadcast | 2 ยท nccl_reshard | 3 ยท mcore | who knows the layout |
|---|---|---|---|---|
| TRT-LLM P/D (main) | โ | โ MoE experts only | not offered | the generation object, per role |
| Megatron, no Dynamo (main) | โ | โ | โ | the synchronizer reads the config (_gen_layouts); MCore for 3 |
| Megatron + Dynamo P/D (this stack) | โ | โ refused | โ nccl or gloo | RefitMembership widths (offsets only); MCore for 3 |
| vLLM P/D (#4920) | โ | โ refused | n/a | its own init_collective |
Read each panel top to bottom: the trainer's rows of W at the top, what each engine rank must end up with at the bottom, and every transfer of W in between. Two families. Whole weight (1): every engine rank gets every tensor and drops the rows it does not hold, so the engine's TP does not matter to the sender. Only rank numbers are needed. Shard to shard (2 and 3): an M-to-N transfer, like one DTensor to another, where each piece goes only to the ranks that hold it. Building those groups and the send plan needs the parallel layout of both the trainer and the engines. The two shard-to-shard ways differ only in who knows that layout. nccl_reshard gets it from NeMo RL: TRT-LLM's get_nccl_reshard_layouts() returns one layout per role, and the synchronizer builds one group per role and trainer PP stage. mcore gets it from Megatron-Core: every rank shares its own parallel groups in one all-gather, so NeMo RL passes only rank offsets. Behind Dynamo, nccl_reshard is refused by a config check, and would also fail: the synchronizer reads generation.worker_group, which MegatronDynamoGeneration raises on, and it reads one shared layout from config, not one per role.
Details that change the picture. nccl_reshard sends only part of the model shard to shard: MoE experts on TRT-LLM, plus dense layers on Megatron. The rest still goes whole over the misc group. mcore sends every parameter shard to shard, as Megatron's own shards rather than HF tensors. Its mcore_generation_config.refit_backend (nccl, gloo, nccl_m2n, nvshmem) only picks how the bytes move; the plan is the same for all four (copy service). Defaults: refit_transport: null everywhere, which means the packed broadcast when not colocated and CUDA IPC when colocated. Colocated Megatron must set mcore (check). Behind Dynamo, the stack allows mcore because "each engine joins the refit group at its own offset" (commit 3843ef69). It gives no reason for refusing nccl_reshard.
With the packed broadcast, each engine only needs to know where its ranks start: the sum of the widths before it. In the figure, prefill P0 starts at r8, D0 at r12 = 8 + 4, D1 at r14 = 8 + 4 + 2.
# the one key that makes engine widths differ (Megatron + Dynamo) policy.generation: disaggregation: {enabled: true, num_prefill_engines: 1, num_decode_engines: 2} mcore_generation_config: {tensor_model_parallel_size: 2} dynamo_cfg: prefill_engine: {tensor_model_parallel_size: 4} # widths (4, 2, 2); TRT-LLM: trtllm_cfg.prefill_engine
Refit plan, before (main)
# driver, weight synchronizer: plan the refit group (also after a shard dies) def plan_refit_membership(surviving, dp_size, total_workers, trainers): width = total_workers // dp_size # one width for every shard prefix = {s: i * width for i, s in enumerate(surviving)} # ranks after the trainers return Membership(world=trainers + len(surviving) * width, prefix, width) # driver, fan out the new group vLLM: leader = workers[shard * width] # first worker of the shard Megatron: ranks for workers[shard * width : + width]
Refit plan, after (this PR)
# driver, same place; example: 8 trainer ranks, shards (4, 2, 2), shard 0 dead def plan_refit_membership(surviving, dp_size, total_workers, trainers, shard_widths=None): # no caller passes it in this PR widths = shard_widths or (total_workers // dp_size,) * dp_size # (4, 2, 2) prefix = {s: i * width for i, s in enumerate(surviving)} for s in sorted(surviving): prefix[s] = next; next += widths[s] # {1: 0, 2: 2} return Membership(world=trainers + next, prefix, widths) # world = 8 + 4 = 12 def worker_offset(shard): return sum(widths[:shard]) # 0, 4, 6: dead shards count vLLM: leader = workers[membership.worker_offset(shard)] # equal widths on every vLLM fleet Megatron: ranks for workers[worker_offset(shard) : + widths[shard]]
# the same running total, computed in three places today TRT-LLM (main): _engine_owner_indices = prefix sums of engine TP # [0, 4, 6] vLLM P/D (#4920): rank_prefix = prefix sums in init_collective # [0, 4, 6] Megatron (#4801): RefitMembership.worker_offset(engine) # [0, 4, 6], engine = refit shard
If an engine dies, survivors are packed together again (prefixes {1: 0, 2: 2}), but for Megatron + Dynamo #5025 refuses anything but the full fleet, so only vLLM uses that case, with equal widths.
๐ฌ C11 โ dynamo_config.py:179
Nothing below is implemented. Keep TRT-LLM's shape: each generation object describes its own layout, one entry per role, and shared code builds every group and plan from that one description. It is plain data, so it can be tested without GPUs. It works the same for vLLM, TRT-LLM and Megatron, with or without P/D or Dynamo. Membership is left to track only which replicas are alive. Megatron-Core's own plan is neat, since each rank describes itself and nothing can drift from the real model, but it only works Megatron to Megatron, and it has no refit deadline and no rebuild path. Keep it as an optional fast path, fed by the same layouts.
# proposed: one method per backend, everything else written once class GenerationInterface: def refit_layouts(self) -> list[RefitLayout] # one per role RefitLayout(role, tp, ep, etp, pp, engines, rank_prefixes, world) # TRT-LLM's layout dict, typed # shared code, backend-neutral offsets = prefix sums over refit_layouts() # packed broadcast groups = one per (layout, trainer PP stage) # nccl_reshard, as today mcore = prepare_swap_model_weights(dst_rank_offset=offset, ...) # Megatron only; offsets from the same layouts membership = which replicas are alive # liveness only, as TRT-LLM keeps it
The packed broadcast is the one transport every backend shares, so it is the fair comparison. Same example, three designs, top to bottom: what each step knows and passes on.
What #4801's change touches. The shared refit plan (RefitMembership) feeds vLLM and plain Megatron, for the packed broadcast and for nccl_reshard. Their engines all have equal widths, so the result is unchanged. TRT-LLM never reads it, and mcore on plain Megatron does not use it either. The only caller that passes uneven widths is Megatron + Dynamo, and all it reads back is each engine's starting rank (engine_rank_offsets), for both the packed broadcast and mcore.
Where RefitMembership fits. It is an existing fleet-health class on main (membership.py): which inference shards are alive, and where each starts, so the synchronizer can rebuild the refit group after a shard dies. #4801 adds one width per shard to it, but the only user of uneven widths, Megatron + Dynamo, reads back just the starting ranks (engine_rank_offsets). In the proposal, membership goes back to meaning only "which engines are alive", the widths come from the layout, and the synchronizer adds up the widths of the alive engines.
Migration, without touching TRT-LLM in #4801:
shard_widths, as TRT-LLM keeps _engine_owner_indices. The shared refit code stays as on main.refit_layouts(). The synchronizer uses it when a backend has it and keeps today's behavior otherwise. TRT-LLM and Dynamo implement it from data they already hold.One list, two kinds of starting rank. The packed broadcast and mcore number engines across all of them (P0 0, D0 4, D1 6). nccl_reshard's per-role groups number them within one role (P0 0; D0 0, D1 2). TRT-LLM computes both today, in two places. One layout list gives both.
| case | packed broadcast | nccl_reshard | mcore |
|---|---|---|---|
| Megatron + Dynamo, P/D | starts [0, 4, 6] | per-role layouts give per-role groups; this unlocks it | dst_rank_offset = 8 + start; maybe num_dst_pools per role (to check) |
| no P/D (vLLM, Megatron, TRT-LLM) | one role, equal widths: 0, w, 2w | one layout | one engine set |
TRT-LLM nccl_reshard | โ | get_nccl_reshard_layouts() already is this layout; it becomes the shared method | not offered |
| rebuild after an engine dies | alive set, running total over survivors | same | no rebuild path today |
RefitMembership. One refit_layouts() method per backend would serve all three transports, let Megatron + Dynamo use nccl_reshard, and make #4801's width change unneeded. The review links work for others only after the review is published.