nemo_rl.models.generation.prefix_recovery.state#
Per-call capture state and the registry of a worker’s live captured calls.
Module Contents#
Classes#
A consistent copy of what one call has recorded, taken under its lock. |
|
The tokens one cut froze: the chunk to stage and the whole prefix. |
|
Append-only generated tokens for one in-flight captured request. |
|
Lifecycle changes to one call, usable only while its lifecycle is held. |
|
Time-bounded terminal evidence retained across the response/cut race. |
|
In-flight captured calls, indexed by request object and by model call ID. |
API#
- class nemo_rl.models.generation.prefix_recovery.state._CallProgress#
A consistent copy of what one call has recorded, taken under its lock.
- generated_token_ids: list[int]#
None
- generated_logprobs: list[float]#
None
- staged_token_count: int#
None
- staging_keys: tuple[str, ...]#
None
- cut_in_progress: bool#
None
- terminal_started: bool#
None
- effective_output_limit: int | None#
None
- terminal_finish_reason: Literal[stop, length] | None#
None
- terminal_stop_reason: str | int | None#
None
- observation_error: str | None#
None
- uncuttable_reason: str | None#
None
- terminal_routed_experts: torch.Tensor | None#
None
- class nemo_rl.models.generation.prefix_recovery.state._FrozenCut#
The tokens one cut froze: the chunk to stage and the whole prefix.
- chunk_key: str#
None
- chunk_sequence: int#
None
- chunk_token_ids: list[int]#
None
- chunk_logprobs: list[float]#
None
- generated_token_ids: list[int]#
None
- generated_logprobs: list[float]#
None
- class nemo_rl.models.generation.prefix_recovery.state._RequestCaptureState(
- call: Any,
- prompt_token_ids: collections.abc.Sequence[int],
- *,
- media: Any | None = None,
- resumed_generation_token_ids: collections.abc.Sequence[int] = (),
- effective_output_limit: int | None = None,
- staging_keys: collections.abc.Sequence[str] = (),
- routed_experts_dtype: torch.dtype | None = None,
- restored_routed_experts: torch.Tensor | None = None,
- restored_sampler_topk: tuple[torch.Tensor, torch.Tensor] | None = None,
Append-only generated tokens for one in-flight captured request.
Tokens are recorded lazily: a checkpoint cut reads the tokens vLLM decoded since the last record, and the finished output records the rest.
recordkeeps each position once whichever source reaches it first.Two locks guard the rest, and callers never take either directly. Every method here takes
_lockitself. Lifecycle changes (freezing, sealing or rolling back a cut, starting the terminal write) exist only on the_CallLifecyclethatlifecycle()yields while it holds_lifecycle_lock, which a cut keeps across its TQ write.call,prompt_token_ids,media,resumed_generation_token_idsand the router-replay settings never change afterbegin_call.Each successful cut stages only the tokens past the last sealed one. The ordered TQ keys remain in Gym lineage; the full list is kept locally to compute the cumulative digest advertised by the latest cut.
Initialization
- __slots__#
(‘_call’, ‘_prompt_token_ids’, ‘_media’, ‘_resumed_generation_token_ids’, ‘_routed_experts_dtype’, ‘…
- property call: Any#
- property prompt_token_ids: list[int]#
- property media: Any | None#
- property resumed_generation_token_ids: list[int]#
- property routed_experts_dtype: torch.dtype | None#
- property restored_routed_experts: torch.Tensor | None#
- property restored_sampler_topk: tuple[torch.Tensor, torch.Tensor] | None#
- property sampler_logprobs: Any#
The logprobs container the call’s recorded tokens were read from.
- property recorded_token_count: int#
- record(
- generated_token_ids: collections.abc.Sequence[int],
- generated_logprobs: collections.abc.Sequence[float],
- *,
- start: int | None = None,
- finish_reason: Any = None,
- stop_reason: Any = None,
- logprobs_container: Any = None,
Record tokens read at position
start(default: the end).A cut and the finished output both read from vLLM, so positions already recorded by the other are skipped rather than appended twice. Callers read
startfromrecorded_token_count, and tokens are never removed, so it never lies past the recorded end.finish_reasonis how vLLM finished the call, if it has.logprobs_containeris the engine container the tokens were read from, kept forsampler_logprobs.
- record_terminal_routes(routed_experts: torch.Tensor) None#
Keep the full-sequence routes of the call’s final output.
- record_error(error: str) None#
Keep the call out of cuts: its recorded tokens disagree with vLLM’s.
- mark_uncuttable(reason: str) None#
- set_effective_output_limit(limit: int) None#
Keep vLLM’s resolved output budget; a restored cut’s own one wins.
- lifecycle() collections.abc.Iterator[nemo_rl.models.generation.prefix_recovery.state._CallLifecycle]#
Own this call’s lifecycle until the block ends.
- try_lifecycle() collections.abc.Iterator[nemo_rl.models.generation.prefix_recovery.state._CallLifecycle | None]#
Like
lifecycle, but yield None at once if a cut or write owns it.
- _owned() collections.abc.Iterator[nemo_rl.models.generation.prefix_recovery.state._CallLifecycle]#
- class nemo_rl.models.generation.prefix_recovery.state._CallLifecycle( )#
Lifecycle changes to one call, usable only while its lifecycle is held.
_RequestCaptureState.lifecycleis the only way to get one, and it stops working when that block ends, likeDataPlaneMutationCut.Initialization
- __slots__#
(‘_state’, ‘_live’)
- _invalidate() None#
- property terminal_started: bool#
- property staging_keys: tuple[str, ...]#
- begin_terminal() tuple[str, ...]#
Start the call’s terminal write; return the chunk rows it retires.
- freeze(
- checkpoint_id: str,
Freeze the recorded length for a cut, if the call can be cut.
Returns what the call had recorded, and the frozen chunk and prefix, or None when the call is uncuttable, its record is inconsistent, or vLLM has not resolved its output limit.
- seal(checkpoint_id: str, staged_key: str | None) None#
Count a staged cut’s tokens as written to TQ and keep its row key.
- absorb_engine_route_pieces(
- pieces: collections.abc.Sequence[Any],
Join the engine’s new route pieces; return the request’s routes so far.
- rollback(checkpoint_id: str) None#
Abandon a cut; its tokens stay unstaged for the next one.
- _frozen_count(checkpoint_id: str) int#
- class nemo_rl.models.generation.prefix_recovery.state._CompletedCaptureState#
Time-bounded terminal evidence retained across the response/cut race.
- coords: Any#
None
- generation_token_count: int#
None
- effective_output_limit: int | None#
None
- terminal_finish_reason: Literal[stop, length] | None#
None
- terminal_stop_reason: str | int | None#
None
- completed_at_monotonic: float#
None
- class nemo_rl.models.generation.prefix_recovery.state.CaptureRegistry#
In-flight captured calls, indexed by request object and by model call ID.
The worker’s request path uses the first index; a checkpoint cut uses the second, because Gym’s inventory names calls by model call ID.
Initialization
- add(
- request: Any,
- state: nemo_rl.models.generation.prefix_recovery.state._RequestCaptureState,
- get(
- request: Any,
- __contains__(request: Any) bool#
- __len__() int#
- pop(
- request: Any,
- get_by_model_call_id(
- model_call_id: str,