nemo_rl.models.generation.megatron.token_capture#
Megatron Inference (MInf) hooks for NeMo-Gym token capture.
The Megatron generation worker installs these two adapters on the dynamic inference engine of the model-parallel coordinator:
TQMegatronPromptPreparerresolves a Gym-authorizedstaging_chainprefix from TransferQueue and splices it into the rendered prompt before the engine admits the request.TQMegatronTokenStagercanonicalizes the finished completion through Gym’s capture core and writes the same TQ row the vLLM worker writes.
Both reach TransferQueue only through the backend-neutral TQTokenSink /
TQTokenSource in nemo_rl.data_plane.tq_token_sink; this module is
the Megatron analog of the capture glue in vllm_worker_async.py.
Module Contents#
Classes#
Resolve a Gym-authorized staged prefix before MInf admits a request. |
|
Canonicalize one admitted MInf completion through Gym’s capture core. |
API#
- class nemo_rl.models.generation.megatron.token_capture.TQMegatronPromptPreparer( )#
Resolve a Gym-authorized staged prefix before MInf admits a request.
Mirrors the vLLM worker:
prepare_promptresolves the prefix through the sharedresolve_admission_prefix/ChainPrefixCachepair, then splices it with the sharedreplace_prefix_tokensusing the rendered prior-turn tokens and EOS id the Megatron endpoint carried inoffload_params.Initialization
- prepare_prompt(
- prompt: str | list[int] | torch.Tensor,
- *,
- offload_params: dict[str, Any] | None = None,
Fetch a chained prefix, splice it into the prompt, and update admission.
- class nemo_rl.models.generation.megatron.token_capture.TQMegatronTokenStager( )#
Canonicalize one admitted MInf completion through Gym’s capture core.
MInf owns the exact prompt/output material and its per-request policy epoch. Gym owns the lineage admission carried opaquely as
ng_capture. This adapter joins them before the response leaves MInf, writes the same canonical TQ row as vLLM, and returns lightweight commit coordinates.Initialization
- property epoch_span_count: int#
Number of staged calls whose generation spanned more than one policy epoch.
- _weight_version(finished_metadata: Any) int#
Stamp the policy epoch the request was admitted under.
The engine records
policy_epochas(token_index, epoch)boundaries: one at admission, plus one appended on everyset_generation_epochwhile the request is active, so a request that straddles a refit carries several. vLLM stamps the version in effect atbegin_calland never re-checks, so the admission epoch (first boundary) is the matching choice here. Spans are counted and logged rather than masked;_abort_stale_inflightis skipped on the Gym path (#2625), so they are routine under async rollouts.
- stage(
- uid: str,
- payload: Any,
- *,
- finished_metadata: Any,
- offload_params: dict[str, Any] | None = None,
Stage an admitted request, or decline ordinary non-capture traffic.
- _stage_admitted(
- payload: Any,
- *,
- capture_payload: Any,
- finished_metadata: Any,
Validate and stage traffic that carries a Gym capture admission.