Skip to navigation

nemo_gym.rollout_correlation

View as Markdown

Module Contents

Classes

NameDescription
RolloutContextMiddlewareStrip a rollout prefix and expose it to downstream Gym calls for this request.

Functions

NameDescription
current_episode_idReturn the logical rollout and attempt carried by the current capture key.
current_rollout_id-
maybe_rollout_id_from_run_bodyBuild the capture key for a run request.
rollout_context-
scope_with_routed_pathCopy the scope for routing and share the rewritten path with outer middleware.

Data

ROLLOUT_ID_PATTERN

ROUTED_PATH_STATE_KEY

_ROLLOUT_ID

API

class nemo_gym.rollout_correlation.RolloutContextMiddleware(
app: typing.Any
)

Strip a rollout prefix and expose it to downstream Gym calls for this request.

_PREFIX
nemo_gym.rollout_correlation.RolloutContextMiddleware.__call__(
scope: dict[str, typing.Any],
receive: typing.Any,
send: typing.Any
) -> None
async
nemo_gym.rollout_correlation.current_episode_id() -> typing.Optional[nemo_gym.episode_types.EpisodeId]

Return the logical rollout and attempt carried by the current capture key.

nemo_gym.rollout_correlation.current_rollout_id() -> typing.Optional[str]
nemo_gym.rollout_correlation.maybe_rollout_id_from_run_body(
body: pydantic.BaseModel | collections.abc.Mapping[str, typing.Any] | None
) -> typing.Optional[str]

Build the capture key for a run request.

An explicit _ng_rollout_id takes precedence. Otherwise derive "{task}-{rollout}" from the task and rollout indices. Re-dispatch attempts append -a{n}. The suffix is reserved: an explicit id ending in -a<N> names attempt N of the rollout before it, as a training controller names a restored attempt, and rollout collection refuses dataset rows that use it as a plain id. Writers and consumers must use this same identity. Reused task and rollout indices produce a repeated capture key. Use an explicit id when numbering restarts across dispatches.

nemo_gym.rollout_correlation.rollout_context(
rollout_id: typing.Optional[str]
) -> collections.abc.Iterator[None]
nemo_gym.rollout_correlation.scope_with_routed_path(
scope: dict[str, typing.Any],
path: str
) -> dict[str, typing.Any]

Copy the scope for routing and share the rewritten path with outer middleware.

nemo_gym.rollout_correlation.ROLLOUT_ID_PATTERN = re.compile('^[A-Za-z0-9][A-Za-z0-9._-]*$')
nemo_gym.rollout_correlation.ROUTED_PATH_STATE_KEY = 'nemo_gym.routed_path'
nemo_gym.rollout_correlation._ROLLOUT_ID: ContextVar[Optional[str]] = ContextVar('nemo_gym_rollout_id', default=None)