nemo_rl.environments.checkpointing.interfaces#
Save and restore rollout state that lives in the environment backend.
At turn-level recovery the environment backend holds part of every unfinished
rollout: agent sessions, tool state, the turns already run. The single
controller saves and restores that state only through EnvironmentCheckpoint
and never names the backend. NeMo Gym implements it in
nemo_rl.environments.checkpointing.nemo_gym; a backend that keeps no
rollout state uses NoEnvironmentCheckpoint.
A rollout snapshot uses the interface in this order::
async with env_checkpoint.snapshot(path) as snapshot: # backend paused
async with data_plane_barrier.checkpoint() as cut:
if snapshot is not None:
await snapshot.check_against_cut(cut)
... # RL saves TQ and its own state
# backend resumed
Module Contents#
Classes#
One rollout attempt as the environment backend knows it. |
|
What an environment restore continued, so RL can match it. |
|
The backend’s part of one rollout snapshot, while the backend is paused. |
|
Rollout state an environment backend keeps between turns. |
|
For a backend that keeps no rollout state between turns. |
API#
- class nemo_rl.environments.checkpointing.interfaces.EnvironmentEpisode[source]#
One rollout attempt as the environment backend knows it.
The recovery ledger names the environment’s rollouts this way when it asks the backend to retire, forget or continue them.
.. attribute:: rollout_id
The rollout’s base ID, the same for every attempt.
.. attribute:: attempt
How many times the backend restored this rollout. 0 is the first run; a restore continues it as the next attempt.
- rollout_id: str#
None
- attempt: int#
None
- property capture_key: str#
The attempt’s key on rollout rows:
<rollout_id>-a<attempt>.Attempt 0 uses the bare rollout ID. A backend must key its rows the same way.
- next_attempt() nemo_rl.environments.checkpointing.interfaces.EnvironmentEpisode[source]#
Return the attempt the backend creates when it restores this one.
- class nemo_rl.environments.checkpointing.interfaces.RestoredEnvironmentRollouts[source]#
What an environment restore continued, so RL can match it.
.. attribute:: continued_attempts
(instance_id, rollout_id, attempt)of every rollout the backend restored. The recovery ledger continues exactly these and starts every other unfinished rollout over... attribute:: staging_keys
Token-capture staging rows the restored rollouts still reference. Restore keeps them instead of clearing them as orphans.
- continued_attempts: frozenset[tuple[str, str, int]]#
‘frozenset(…)’
- staging_keys: frozenset[str]#
‘frozenset(…)’
- class nemo_rl.environments.checkpointing.interfaces.EnvironmentSnapshot[source]#
Bases:
typing.ProtocolThe backend’s part of one rollout snapshot, while the backend is paused.
- property restarted_rollouts: int#
Rollouts the backend could not capture; they start over after a crash.
- class nemo_rl.environments.checkpointing.interfaces.EnvironmentCheckpoint[source]#
Bases:
typing.ProtocolRollout state an environment backend keeps between turns.
- property holds_rollout_state: bool#
Whether rollout snapshots must capture this backend.
True means a trainer checkpoint, which never pauses the backend, does not stand in for a rollout snapshot.
- async check_startup() None[source]#
Refuse, or warn about, a deployment that cannot recover as configured.
- snapshot(
- checkpoint_path: pathlib.Path,
Pause the backend and save its rollouts under
checkpoint_path.Yields
Nonewhen there is nothing to save. The backend resumes, and accepts new rollouts again, when the context exits.
- restored(
- checkpoint_path: pathlib.Path,
Restore the backend’s rollouts from
checkpoint_path.The restore is kept only if the context exits cleanly. On an exception the backend drops what it restored before it resumes.
Whether a failed snapshot only met a backend that was briefly unreachable.
Such a failure leaves nothing RL holds changed, so the next attempt can retry.
- class nemo_rl.environments.checkpointing.interfaces.NoEnvironmentCheckpoint[source]#
For a backend that keeps no rollout state between turns.
- property holds_rollout_state: bool#
- async snapshot(
- checkpoint_path: pathlib.Path,
- async restored(
- checkpoint_path: pathlib.Path,