Skip to content

Fix CUDA memory buildup across files in ASR batch inference demo - #446

Closed
Ammar Hashmi (ammar-iitm) wants to merge 1 commit into
microsoft:mainfrom
ammar-iitm:fix/asr-batch-inference-memory-leak
Closed

Ammar Hashmi (ammar-iitm) wants to merge 1 commit into
microsoft:mainfrom
ammar-iitm:fix/asr-batch-inference-memory-leak

Conversation

@ammar-iitm

Copy link
Copy Markdown

Summary

  • Fixes [Bug] demo/vibevoice_asr_inference_from_file.py accumulates working memory across files in --audio_files batch #368: demo/vibevoice_asr_inference_from_file.py OOMs partway through a multi-file --audio_files run even though every file fits comfortably on its own.
  • transcribe_batch() kept inputs (including the generated KV cache) and output_ids referenced until the next loop iteration overwrote them, letting PyTorch's CUDA caching allocator accumulate cached-but-idle, fragmented memory across files.
  • After each batch, explicitly drop those tensors and call torch.cuda.empty_cache() / gc.collect() so freed memory is returned to the allocator's free pool before the next file is processed.

Test plan

  • python3 -m py_compile demo/vibevoice_asr_inference_from_file.py
  • Re-run the reporter's repro (5x 25-min m4a chunks via --audio_files on a 24GB GPU) to confirm the run no longer OOMs on the 3rd/4th file — I don't have a comparable GPU set up locally, so this needs verification from someone who can reproduce the original issue.

🤖 Generated with Claude Code

https://claude.ai/code/session_018vBGcq8YxMgbF58qx7C4cP

transcribe_batch() held onto inputs/output_ids (including the KV cache)
until the next loop iteration reassigned them, letting the CUDA caching
allocator accumulate fragmented, cached-but-idle memory across files.
On a 24GB GPU this pushed a multi-file --audio_files run to OOM partway
through, even though each file fits comfortably on its own (microsoft#368).

Explicitly drop the per-batch tensors and clear the CUDA cache after
each batch so freed memory is returned to the allocator's free pool
before the next file is processed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018vBGcq8YxMgbF58qx7C4cP
@ammar-iitm

Copy link
Copy Markdown
Author

Closing in favor of #439, which fixes the same issue (#368) in the same file and additionally handles xpu/mps device cleanup, not just cuda. Sorry for the duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] demo/vibevoice_asr_inference_from_file.py accumulates working memory across files in --audio_files batch

1 participant