Skip to navigation

nemo_gym.core.episode_context

View as Markdown

The episode that the current request or task belongs to.

Module Contents

Functions

NameDescription
check_rollout_id_lengthRefuse a rollout id whose capture files would pass the 255-byte file name limit at some attempt.
current_episode_idReturn the logical rollout and attempt carried by the current capture key.
current_rollout_id-
current_verifier_invocation_idReturn the enclosing verify execution, if any.
maybe_rollout_id_from_run_bodyBuild the capture key for a run request.
note_verifier_model_requestNote that the enclosing verify execution sent a request to a model server; outside one, do nothing.
rollout_context-
verifier_invocation_contextCarry one verify execution’s identity across its concurrent judge calls.
verifier_model_requestsThe model servers the enclosing verify execution has sent requests to so far.

Data

MAX_ROLLOUT_ID_LENGTH

ROLLOUT_ID_PATTERN

VERIFIER_INVOCATION_HEADER

_ROLLOUT_ID

_VERIFIER_INVOCATION_ID

_VERIFIER_MODEL_REQUESTS

API

nemo_gym.core.episode_context.check_rollout_id_length(
rollout_id: str
) -> None

Refuse a rollout id whose capture files would pass the 255-byte file name limit at some attempt.

nemo_gym.core.episode_context.current_episode_id() -> typing.Optional[nemo_gym.core.episode_types.EpisodeId]

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

nemo_gym.core.episode_context.current_rollout_id() -> typing.Optional[str]
nemo_gym.core.episode_context.current_verifier_invocation_id() -> typing.Optional[str]

Return the enclosing verify execution, if any.

nemo_gym.core.episode_context.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.core.episode_context.note_verifier_model_request(
server_name: str
) -> None

Note that the enclosing verify execution sent a request to a model server; outside one, do nothing.

nemo_gym.core.episode_context.rollout_context(
rollout_id: typing.Optional[str]
) -> collections.abc.Iterator[None]
nemo_gym.core.episode_context.verifier_invocation_context(
invocation_id: str
) -> collections.abc.Iterator[None]

Carry one verify execution’s identity across its concurrent judge calls.

nemo_gym.core.episode_context.verifier_model_requests() -> list[str]

The model servers the enclosing verify execution has sent requests to so far.

nemo_gym.core.episode_context.MAX_ROLLOUT_ID_LENGTH = 255 - len('.capture.incomplete') - len('-a9999')
nemo_gym.core.episode_context.ROLLOUT_ID_PATTERN = re.compile('^[A-Za-z0-9][A-Za-z0-9._-]*$')
nemo_gym.core.episode_context.VERIFIER_INVOCATION_HEADER = 'x-ng-verifier-invocation-id'
nemo_gym.core.episode_context._ROLLOUT_ID: ContextVar[Optional[str]] = ContextVar('nemo_gym_rollout_id', default=None)
nemo_gym.core.episode_context._VERIFIER_INVOCATION_ID: ContextVar[Optional[str]] = ContextVar('nemo_gym_verifier_invocation_id', default=None)
nemo_gym.core.episode_context._VERIFIER_MODEL_REQUESTS: ContextVar[Optional[list[str]]] = ContextVar('nemo_gym_verifier_model_requests', default=None)