nemo_rl.models.generation.prefix_recovery.routes#
Router-replay routes of a cut call: staged per chunk, joined on restore.
Module Contents#
Classes#
The engine’s route pieces for one request, joined as they arrive. |
Functions#
Join route pieces into one integer |
|
|
|
The routes of the chunk a cut stages: one row per chunk token. |
|
Verify each cut chunk’s routes against its digest and join them. |
API#
- nemo_rl.models.generation.prefix_recovery.routes._join_route_pieces(
- pieces: collections.abc.Sequence[Any],
Join route pieces into one integer
[rows, layers, topk]array.vLLM publishes every piece of a request as a numpy array of one dtype, so one C-level join in that dtype checks them all; anything else is checked piece by piece.
- Raises:
ValueError – a piece is not integer
[rows, layers, topk]with the others’ dimensions.
- nemo_rl.models.generation.prefix_recovery.routes._final_route_placeholder(
- layers: int,
- topk: int,
- dtype: torch.dtype,
- rows: int = 1,
rowsroute rows ofROUTE_MISSING_SENTINEL, for tokens no step routed.Cuts, restores and finished restored prefixes all build these rows here, so a staged row and its rebuild agree and the chunk digests match.
- class nemo_rl.models.generation.prefix_recovery.routes._EngineRouteCache(dtype: torch.dtype)#
The engine’s route pieces for one request, joined as they arrive.
The joined routes live in a buffer that doubles when full, so a cut copies only the pieces vLLM appended since the previous one and the total copying is linear in the request’s length. It follows the engine, not the cuts, so a rolled-back cut does not rewind it. Only the call’s lifecycle owner touches it.
Initialization
- __slots__#
(‘_dtype’, ‘_buffer’, ‘_rows’, ‘_piece_count’, ‘_last_piece’)
- absorb(pieces: collections.abc.Sequence[Any]) torch.Tensor#
Copy the engine’s new route pieces in; return the joined routes.
piecesis the request’s whole route list as vLLM holds it. vLLM only appends to it and never replaces a piece, so the pieces already joined are skipped. Returns the request’s full-sequence routes as a view of the buffer; rows already returned are never written again.- Raises:
ValueError – the list shrank, a joined piece was replaced, or a new piece is not integer
[rows, layers, topk]with this request’s model dimensions.
- nemo_rl.models.generation.prefix_recovery.routes._cut_chunk_routes(
- engine_routes: Any | None,
- *,
- dtype: torch.dtype,
- prev_len: int,
- prompt_len: int,
- restored: torch.Tensor | None,
- staged: int,
- frozen: int,
The routes of the chunk a cut stages: one row per chunk token.
engine_routesare the request’s full-sequence routes, read with the frozen tokens;stagedandfrozencount the generated tokens already staged and frozen by this cut. vLLM only appends routes, so earlier rows never change and every chunk lines up with what earlier cuts staged.A call’s routes are delta-aligned: one row per prompt token past
prev_lenand per generated token, the last being a placeholder for the final token, which no step has routed yet. The first chunk is the whole prefix so far, placeholder included; a later chunk’s first row replaces the previous chunk’s placeholder.- Returns:
The chunk’s routes, or
Nonewhen the cut stages no new tokens.- Raises:
ValueError – the routes are missing, malformed, or do not cover every frozen token.
- nemo_rl.models.generation.prefix_recovery.routes._join_chunk_routes(
- chunks: collections.abc.Sequence[Any],
- *,
- required: bool,
Verify each cut chunk’s routes against its digest and join them.
A later chunk’s first row replaces the previous chunk’s final placeholder, and a new placeholder ends the joined routes.
- Raises:
RuntimeError – routes are missing when
required, only some chunks carry them, or a chunk’s routes fail their checks.