#16309·Speech

Cache-aware streaming pipeline runs out of slots when streams end with delete_state() instead of an is_last request

Author: kzosCreated Sep 28, 2026Updated Sep 30, 2026
Labelscommunity-request

Describe the bug

In CacheAwareRNNTPipeline, a stream's feature-bufferer slot and encoder-cache slot are returned only while a request with is_last=True is processed: BatchedCacheFeatureBufferer.update frees a slot only for a frame with is_last (cache_feature_bufferer.py L194), and CacheAwareContextManager.reset_slots only for streams whose eos flag is set (context_manager.py L158). delete_state() drops the stream's state and leaves both slots taken, and close_session() does not return them either. A caller that ends its streams with delete_state() therefore uses up all num_slots (256 in cache_aware_rnnt.yaml), and the next stream fails with RuntimeError: No free slots available.

The in-tree simulstream adapter ends every stream this way: process_chunk() sends is_last=False on every chunk (simulstream_pipeline_adapter.py L311) and end_of_stream() calls delete_state() (L417). So a NeMoStreamingPipelineAdapter process on the cache-aware pipeline fails on its 257th stream (see "Additional context").

Steps/Code to reproduce bug

From the repository root, on CPU:

python
import torch
from omegaconf import OmegaConf

from nemo.collections.asr.inference.factory.pipeline_builder import PipelineBuilder
from nemo.collections.asr.inference.streaming.framing.request import Frame
from nemo.collections.asr.inference.streaming.framing.request_options import ASRRequestOptions

IS_LAST = False  # True for the control

cfg = OmegaConf.load("examples/asr/conf/asr_streaming_inference/cache_aware_rnnt.yaml")
cfg.asr.model_name = "nvidia/nemotron-speech-streaming-en-0.6b"
cfg.asr.device = "cpu"
cfg.asr.compute_dtype = "float32"
cfg.enable_itn = False
cfg.enable_nmt = False

pipeline = PipelineBuilder.build_pipeline(cfg)
pipeline.open_session()
n = int(16000 * (cfg.streaming.att_context_size[1] + 1) * 0.08)  # one 1.12 s chunk, as the simulstream adapter sends
torch.manual_seed(0)


def free_slots():  # (encoder-cache slots, feature-bufferer slots)
    return pipeline.context_manager.free_slots.qsize(), pipeline.bufferer.available_slots.qsize()


print("free slots at start:", free_slots())
try:
    for stream_id in range(300):
        frame = Frame(
            samples=0.01 * torch.randn(n),
            stream_id=stream_id,
            is_first=True,
            is_last=IS_LAST,
            length=n,
            options=ASRRequestOptions(),
        )
        pipeline.transcribe_step([frame])
        pipeline.delete_state(stream_id)
        if stream_id + 1 in (1, 128, 256, 300):
            print(f"after stream {stream_id + 1}: free slots {free_slots()}")
except RuntimeError as e:
    print(f"stream {stream_id + 1}: RuntimeError: {e}")
pipeline.close_session()
print("after close_session():", free_slots())

Output with IS_LAST = False (each stream ends through delete_state()):

free slots at start: (256, 256)
after stream 1: free slots (255, 255)
after stream 128: free slots (128, 128)
after stream 256: free slots (0, 0)
stream 257: RuntimeError: No free slots available
after close_session(): (0, 0)

Output with IS_LAST = True, the control:

free slots at start: (256, 256)
after stream 1: free slots (256, 256)
after stream 128: free slots (256, 256)
after stream 256: free slots (256, 256)
after stream 300: free slots (256, 256)
after close_session(): (256, 256)

The error is raised in BatchedCacheFeatureBufferer.update (cache_feature_bufferer.py L187). The context manager's slots (the first number) run out at the same time, and it has its own copy of this check at context_manager.py L178. No biasing request is involved.

Expected behavior

A stream ended with delete_state() gives its slots back, as a stream ended with an is_last request does, or at least close_session() returns every slot.

I see two possible directions and have tried neither: release the stream's slots in the cache-aware pipeline's delete_state(), or have the adapter end each stream with an is_last=True request. From reading the code, the second would release the slots through the existing is_last path, but I have not measured what it does to the adapter's output at the end of a stream.

Environment overview (please complete the following information)

  • Environment location: Bare-metal, CPU only
  • Method of NeMo install: from source, main at cf724ac33

Environment details

  • OS version: Ubuntu 22.04.5 LTS
  • PyTorch version: 2.11.0
  • Python version: 3.12.13

Additional context

Through the simulstream adapter itself (with a stub for the simulstream package, which I do not have installed), driving one-chunk streams of synthetic noise, each with a per-stream biasing request, on the cache-aware pipeline fails the same way at the 257th stream.

The buffered pipeline (buffered_rnnt.yaml) driven the same way through the adapter did not fail within 300 streams, but its BatchedAudioBufferer held 300 per-stream bufferers after 300 streams, and still did after close_session().

Found while working on #16308, which makes delete_state() release the stream's per-stream biasing model. That PR does not change the slot behaviour described here: the 257th stream fails the same way with it applied.