nemo_rl.models.generation.prefix_read_batcher#

Bounded, event-loop-local coalescing of blocking generation-prefix reads.

Module Contents#

Classes#

PrefixReadBatcher

Share GETs across requests without sharing request cancellation.

Data#

API#

nemo_rl.models.generation.prefix_read_batcher.LOGGER#

‘getLogger(…)’

class nemo_rl.models.generation.prefix_read_batcher.PrefixReadBatcher(
fetch: collections.abc.Callable[[list[str]], list[Any]],
*,
max_rows: int,
wait_seconds: float = 0.002,
)#

Share GETs across requests without sharing request cancellation.

The fetch callback must validate row identity and count and return requested order (TQTokenSource.fetch does all three). A GET holds at most max_rows distinct keys. Shutdown fails waiters but cannot interrupt an executing GET.

Initialization

async fetch(keys: list[str]) → list[Any]#

Read a chain in order; cancellation affects only this caller.

async _read(keys: list[str]) → dict[str, Any | Exception]#
async _run() → None#
async aclose() → None#

Close on the serving loop, including when called by the actor loop.

async _close_on_owner() → None#

Stop accepting reads and wake queued/in-flight callers immediately.