Skip to content

Rebase serving layer on upstream nemo.collections.asr.inference pipeline framework #7

Closed

Description

@beastoin

Summary

Upstream NeMo (2025) shipped a complete production streaming inference framework at nemo.collections.asr.inference that solves many problems we fixed manually in PRs #2 and #4. We should rebase our serving layer on this framework to leverage upstream capabilities while preserving our thread-safety and performance fixes.

What upstream provides that we currently reimplement

Capability Our implementation (gpu_worker.py) Upstream (CacheAwareRNNTPipeline)
Chunk buffering Manual 5120-sample accumulation BatchedCacheFeatureBufferer with mel-spec caching
Final transcript last_partial workaround for empty final_transcript TranscribeStepOutput with structured final/partial/current_step
Endpointing Idle timeout only (no speech-based EOU) RNNTGreedyEndpointing (800ms window, configurable)
Multi-stream batching 1 stream per inference step ContinuousBatchedRequestStreamer (batch_size=64, num_slots=256)
ITN None StreamingTextProcessor with inverse text normalization
Confidence scores None Entropy/max_prob confidence estimation
Latency measurement None LAAL (Length-Aware Average Lagging)
Session lifecycle Manual dict-based sessions PipelineInterface with open/close_session, state pool
Cache management Manual encoder cache tracking CacheAwareContextManager with slot-based pooling
Prompt vectors Manual one-hot construction _build_prompt_vectors() with prompt config validation
Per-stream biasing None enable_per_stream_biasing in decoder

Key upstream files

  • nemo/collections/asr/inference/pipelines/cache_aware_rnnt_pipeline.py — main pipeline
  • nemo/collections/asr/inference/pipelines/base_pipeline.py — session lifecycle, state pool
  • nemo/collections/asr/inference/pipelines/pipeline_interface.py — interface contract
  • nemo/collections/asr/inference/model_wrappers/cache_aware_rnnt_inference_wrapper.py — model wrapper with execute_step()
  • nemo/collections/asr/inference/streaming/ — buffering, decoders, endpointing, framing, state
  • nemo/collections/asr/inference/factory/pipeline_builder.py — factory pattern
  • examples/asr/conf/asr_streaming_inference/cache_aware_rnnt.yaml — production config
  • examples/asr/asr_streaming_inference/asr_streaming_infer.py — entry point with warmup, RTFx, LAAL

What we MUST preserve from our fork

From PR #2 (batch/Parakeet thread-safety)

  1. CUDA Graph gating on Turing GPUs — cuda_graphs: false for compute capability 7.5 (T4). Upstream config already has use_cuda_graph_decoder: false but our explicit T4 config guard must remain.
  2. freeze/unfreeze race fix — transcribe() concurrent calls crash on _frozen_grad_map. Our fix bypasses under torch.inference_mode().
  3. Cross-thread CUDA tensor GC — pinned-memory tensors from RNNT decoder generators, GC on wrong thread = segfault. Our gc.disable() + controlled gc.collect() on GPU thread.
  4. Automatic GC on async thread — Python GC triggers on event loop thread, frees CUDA pinned-memory cross-thread.

From PR #4 (streaming/Nemotron framework fixes)

  1. Prompt vectors in execute_step() — multilingual model produces blank output without prompt vectors. Note: upstream's CacheAwareRNNTInferenceWrapper.execute_step() now includes this fix independently — verify parity.
  2. Mel spectrogram fragmentation — 40ms chunks produce garbled output. Note: upstream's BatchedCacheFeatureBufferer handles this — verify parity.

From PR #4 (serving layer)

  1. Buffer drain loop — process ALL buffered chunks per WS message (while loop, not if)
  2. Idle timeout reaper — background asyncio task for configurable idle timeout
  3. gc.disable() + gc.collect() pattern — module-level GC disable, gen-0 collect per batch on GPU thread, full collect every N batches
  4. Single GPU thread ownership — all CUDA operations on dedicated thread

Plan

Phase 1: Streaming rebase

  • Replace manual streaming in gpu_worker.py with CacheAwareRNNTPipeline
  • Keep WebSocket server layer (server.py, stream_engine.py) — upstream has no transport
  • Keep GPU worker thread pattern — wrap pipeline calls inside dedicated thread
  • Keep gc.disable() + controlled GC pattern
  • Verify prompt vectors work identically (upstream has the fix now)
  • Verify chunk buffering handles 40ms WebSocket chunks correctly

Phase 2: Batch path verification

Phase 3: Benchmarks (regression gate)

Phase 4: New capabilities (from upstream adoption)

  • Enable RNNTGreedyEndpointing for speech-based EOU detection
  • Enable multi-stream batched inference (up to 64 streams per step)
  • Add ITN support
  • Add confidence scores to API response
  • Add LAAL latency measurement

Non-goals

  • Do NOT touch the batch transcription path (Parakeet TDT) — it uses model.transcribe() directly, not the streaming pipeline
  • Do NOT upgrade NeMo base image or PyTorch version — NGC 26.02 (PyTorch 2.6 + CUDA 12.8) is battle-tested
  • Do NOT remove our thread-safety fixes even if upstream appears to have them — verify independently first

Activity

  1. added
    enhancement
    on Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions