How Megatron prefill/decode engines behind Dynamo differ from one Megatron inference policy

PR #4912 (2 of 6: #4801 โ†’ #4912 โ†’ #5023 โ†’ #5024 โ†’ #5025 โ†’ #5097) ยท permalinks pinned to head 1cb4fef4 (cited code unchanged at 44035e16) ยท Megatron-LM at the repo's pin e0a4bfed

Before
backend: megatron builds one MegatronGeneration: one inference policy over the whole inference cluster, joined to the weight refit as one block.
This PR
With dynamo: true, a new sibling class builds one MegatronGeneration per prefill or decode engine, each on its own one-node cluster, and fans every refit call out to them. Rollouts stay refused until #5025.
Status
Open โ€” the engines cannot be built yet at the pinned Megatron-LM. Each engine asks Megatron-LM's config for a field it does not have. See the second page.

Two pages on this PR, one question each โ€” this one: what the new class does next to the old one. The stack's first PR has its own page: where the Dynamo switch sits.

Background. A prefill/decode split runs prompt reading and answer writing on different engines; Dynamo's frontend routes each request across them. A refit pushes new weights from the trainer into every engine after each step. Dotted words have a short explanation: hover or tap them.

The new class, MegatronDynamoGeneration, is not a subclass of MegatronGeneration. It holds several of them. megatron_generation_cls picks it when dynamo: true. The example below uses 16 trainer ranks and one inference node of 8 GPUs, split as 1 prefill engine at TP 4 and 2 decode engines at TP 2.

One policy vs. one policy per engine

Before / dynamo: false one inference policy This PR / dynamo: true one policy per prefill or decode engine backend: megatron dynamo: false mcore_generation_config: {tp: 2} backend: megatron dynamo: true 1 P : 2 D prefill_engine: {tp: 4} decode_engine: {tp: 2} megatron_generation_cls โ†’ MegatronGeneration megatron_generation_cls โ†’ MegatronDynamoGeneration Policy(cluster) one worker group over all 8 inference GPUs MegatronPolicyWorker ร— 8 one Megatron world: 8 ranks, TP 2 ร— DP 4 role_policy_config per role: dynamo off + its _dynamo_role _start_engines a one-node cluster + MegatronGeneration each prefill-0 4 GPUs, TP 4 decode-0 2 GPUs, TP 2 decode-1 2 GPUs, TP 2 worker class: MegatronPolicyWorker InferenceConfig(**kwargs) hooks return nothing extra engine: DynamicInferenceEngine serves through NeMo RL's own HTTP server Policy sees _dynamo_role โ†’ MegatronDynamoPolicyWorker InferenceConfig(**kwargs, nixl, disaggregation_role) โœ• TypeError at the pinned Megatron-LM (page 2) DynamoDynamicInferenceEngine + KV handoff init_collective one call to one worker group refit ranks: trainer 0..15 | inference 16..23 init_collective + engine_rank_offsets offsets 16, 20, 22 (16 + 4 = 20, 20 + 2 = 22) one call per engine, in engine order same as before new in this PR new, and fails at the pinned Megatron-LM Dashed boxes = one Ray worker group (one Megatron world). Underlined names link to the code.

Where they meet: each Dynamo engine is a plain MegatronGeneration built from a copied config, so the worker code is the same. They split in exactly three hooks on the worker โ€” extra config fields, which engine class to build, and where the coordinator listens. The plain worker returns the old answers; MegatronDynamoGenerationMixin returns the Dynamo ones.

๐Ÿ’ฌ review comment C3 โ€” dynamo_worker_mixin.py:80 C10 โ€” one worker class C13 โ€” names

Before (MegatronGeneration)This PR (MegatronDynamoGeneration)
Inference worlds1, over the whole inference cluster1 per engine, each on one node; engines may differ in TP
Weights at startloaded at buildnone until the first refit (skip_weight_load=True)
Refit ranksone block after the trainersengine i starts after the trainers plus the widths of engines before it
Failed suspendthe error goes uptries to resume every engine, then the error goes up
Pickled copy (sent to the controller)the whole objectrecords and worker handles only; it can drive a refit but cannot shut an engine down

The refit, as pseudocode

Before: one block

# driver / controller, one call
def init_collective(ip, port, world_size=24):
    policy.init_collective(ip, port, world_size)  # all 8 workers, ranks 16..23

This PR: one call per engine

# driver / controller, one call each, in engine order
def init_collective(ip, port, world_size=24, train_world_size=16):
    offsets = engine_rank_offsets(16)             # [16, 20, 22] from widths (4, 2, 2)
    for engine, off in zip(engines, offsets):
        engine.workers.init_collective(..., rank_offset=off)  # prefill-0: 16..19, decode-0: 20..21, decode-1: 22..23
So what. The design is clean: the plain Megatron path gains three small hooks and no Dynamo branches, and every Dynamo-only piece lives in its own class and mixin. But nothing in this PR has run on a GPU, and the engine build cannot pass at the repo's Megatron-LM pin. That fix belongs in this PR, because no later PR in the stack moves the pin.