nemo_rl.experience.route_assembly#
Shared route-plan executor for direct and deferred router replay.
One implementation turns a verified :class:RouteAssemblyPlan plus fetched
- class:
RouteFragmentpayloads into a training route tensor. The finalizer runs it eagerly in direct mode (a failure rejects the rollout before publication asroute_assembly:<reason>); the policy worker runs it after canonical publication in deferred mode (the same reason maps to the existing counted sentinel fallback). The executor owns per-span extras-digest verification against Gym’s receipt-bound commitments, span classification via Gym’s decision table, full/tail slicing, sentinel fill, and shape checks — it returns a tensor or a failure reason and never decides policy.
Module Contents#
Classes#
Which columns of a staged route fragment belong to the trained MoE layers. |
|
One staged route payload plus the metadata its extras digest binds. |
Functions#
Include the last token of the previous message. |
|
Rebuild the staged extras envelope and verify the receipt-bound digest. |
|
Assemble one canonical route tensor from staged fragments. |
Data#
API#
- nemo_rl.experience.route_assembly.ROUTE_MISSING_SENTINEL#
None
- nemo_rl.experience.route_assembly.ROUTE_FAILURE_CANONICAL_LENGTH#
‘canonical_length_mismatch’
- nemo_rl.experience.route_assembly.ROUTE_FAILURE_MISSING_FRAGMENT#
‘missing_fragment’
- nemo_rl.experience.route_assembly.ROUTE_FAILURE_INTEGRITY#
‘fragment_integrity’
- nemo_rl.experience.route_assembly.ROUTE_FAILURE_RANK#
‘fragment_rank’
- nemo_rl.experience.route_assembly.ROUTE_FAILURE_LENGTH#
‘fragment_length’
- nemo_rl.experience.route_assembly.ROUTE_FAILURE_MODEL_SHAPE#
‘fragment_model_shape’
- nemo_rl.experience.route_assembly.ROUTE_FAILURE_ASSEMBLED_LENGTH#
‘assembled_length_mismatch’
- nemo_rl.experience.route_assembly.boundary_route_rows(prev_len: int) int#
Include the last token of the previous message.
Chosen experts are only recorded for input tokens. Choice of the last generated token in the previous message was a placeholder. Rewrite it with the correct value, known from the new prefill.
- class nemo_rl.experience.route_assembly.RouteLayout#
Which columns of a staged route fragment belong to the trained MoE layers.
A fragment’s layer axis comes in one of two layouts. MInf stages one column per MoE layer (
num_moe_layerscolumns). vLLM stages one column per transformer layer (total_num_layerscolumns), so for a hybrid Mamba/attention/MoE stack the executor must pick out the MoE columns bymoe_layer_numbers. Both counts coincide for a stack where every layer is MoE, in which case no selection happens.- moe_layer_numbers: tuple[int, ...]#
None
1-based global layer numbers of the MoE layers, ascending.
- total_num_layers: int#
None
- top_k: int#
None
- __post_init__() None#
- classmethod compressed(
- *,
- num_moe_layers: int,
- top_k: int,
A MoE-only layout for callers that know only
(num_moe_layers, top_k).Direct mode learns these from the fetched fragments themselves and has no model config, so it can never need column selection.
- property num_moe_layers: int#
- property dims: tuple[int, int]#
The published
(num_moe_layers, top_k)route tensor dims.
- moe_column_indices(
- num_payload_layers: int,
Payload column for each MoE layer, in
moe_layer_numbersorder.This is the one rule both replay paths share. A MoE-only payload (MInf) maps the i-th MoE layer to column i; a full-layer payload (vLLM) maps layer number
nto columnn - 1. Any other width is unsupported and returns None.
- select_moe_columns(
- routes: torch.Tensor,
Return
routesas[T, num_moe_layers, top_k]or None if it fits neither layout.
- class nemo_rl.experience.route_assembly.RouteFragment#
One staged route payload plus the metadata its extras digest binds.
routesis the staged[staged_len, num_moe_layers, topk]tensor,encodingtheROUTE_ENCODING_*wire code the digest was committed over, andextras_metadata_jsonthe canonical non-route extras JSON staged beside it.- routes: torch.Tensor#
None
- encoding: int#
None
- extras_metadata_json: bytes#
None
- nemo_rl.experience.route_assembly.verify_route_fragment_integrity(
- fragment: nemo_rl.experience.route_assembly.RouteFragment,
- *,
- extras_digest_version: int,
- expected_extras_digest: str,
Rebuild the staged extras envelope and verify the receipt-bound digest.
- nemo_rl.experience.route_assembly.execute_route_plan(
- plan: nemo_rl.experience.route_plan.RouteAssemblyPlan,
- fragments: Mapping[str, nemo_rl.experience.route_assembly.RouteFragment],
- *,
- layout: nemo_rl.experience.route_assembly.RouteLayout,
- canonical_len: int,
Assemble one canonical route tensor from staged fragments.
- Parameters:
plan – The verified assembly plan built by the finalizer.
fragments – Fetched fragments keyed by staging key. Sentinel spans need no entry.
layout – Which fragment columns are the trained MoE layers. The policy worker supplies the real model layout (the authoritative shape check, accepting both MoE-only and full-layer fragments); the direct-mode finalizer supplies a compressed layout learned from the fetched fragments.
canonical_len – The published row’s token length.
- Returns:
(tensor, None)on success —[canonical_len, num_moe_layers, topk]int16, sentinel-filled wherever no fragment contributed — or(None, reason)with a reason from the shared vocabulary.