Skip to navigation

nemo_gym.models.token_capture.staging.routes

View as MarkdownOpen in Claude

Portable validation, encoding, and decoding for staged routed-expert envelopes.

The envelope wire format and its codec live here because extras_digest is computed over the encoded payload: whoever defines what staged route bytes mean also defines what makes them authentic. The span-classification decision table (classify_route_span) is the pure-metadata rule for how one staged fragment contributes to a linearized row; frameworks apply it instead of mirroring it.

Module Contents

Classes

NameDescription
RoutedExpertsFragmentOne decoded [tokens][layers][topk] routed-expert fragment.

Functions

NameDescription
_validate_nested_routes-
classify_route_spanClassify how one staged fragment contributes to a linearized row.
decode_routed_expertsDecode the supported v1 base64 envelope or validate legacy nested lists.
encode_routed_expertsEncode a [tokens][layers][topk] nested list as the v1 base64 envelope.
routed_experts_token_countInspect the token dimension without materializing the route tensor.

Data

MISSING_ROUTE_SENTINEL

ROUTED_EXPERTS_ENVELOPE_VERSION

ROUTED_EXPERTS_MAGIC

RouteSpanMode

_DTYPE_FORMATS

API

class nemo_gym.models.token_capture.staging.routes.RoutedExpertsFragment(
values: list[list[list[int]]],
dtype: str,
num_layers: int,
topk: int
)
Dataclass

One decoded [tokens][layers][topk] routed-expert fragment.

dtype
str
num_layers
int
topk
int
values
list[list[list[int]]]
nemo_gym.models.token_capture.staging.routes._validate_nested_routes(
payload: typing.Any
nemo_gym.models.token_capture.staging.routes.classify_route_span(
carry_len: int,
generation_len: int,
staged_route_len: int

Classify how one staged fragment contributes to a linearized row.

full: the fragment covers the span’s whole carry+generation token range. tail: the fragment covers at least the generated suffix, whose last generation_len rows are used. sentinel: no usable fragment — the consumer fills the span with MISSING_ROUTE_SENTINEL.

nemo_gym.models.token_capture.staging.routes.decode_routed_experts(
payload: typing.Any

Decode the supported v1 base64 envelope or validate legacy nested lists.

nemo_gym.models.token_capture.staging.routes.encode_routed_experts(
values: typing.Sequence[typing.Sequence[typing.Sequence[int]]],
dtype: str = 'int16'
) -> str

Encode a [tokens][layers][topk] nested list as the v1 base64 envelope.

This is the reference inverse of decode_routed_experts for the nrlre1 wire format; array-backed producers may emit the same envelope from contiguous little-endian buffers without round-tripping through nested lists.

nemo_gym.models.token_capture.staging.routes.routed_experts_token_count(
payload: typing.Any
) -> int

Inspect the token dimension without materializing the route tensor.

nemo_gym.models.token_capture.staging.routes.MISSING_ROUTE_SENTINEL = -1
nemo_gym.models.token_capture.staging.routes.ROUTED_EXPERTS_ENVELOPE_VERSION = 1
nemo_gym.models.token_capture.staging.routes.ROUTED_EXPERTS_MAGIC = 'nrlre1'
nemo_gym.models.token_capture.staging.routes.RouteSpanMode = Literal['full', 'tail', 'sentinel']
nemo_gym.models.token_capture.staging.routes._DTYPE_FORMATS = {'int8': ('b', 1), 'int16': ('h', 2), 'int32': ('i', 4)}