Repository navigation
Add batched chunk inference for long audio - #41
Conversation
|
Could the chunk-level inference process be switched to batch mode? This would significantly speed up inference. |
|
Thank you for the suggestion. I have implemented configurable chunk batching so The local CPU tests confirm batch grouping of I also tested batch sizes 1 and 2 end to end on the public 12-second fixture using MPS. Both outputs were float32 stereo at 44.1 kHz, exactly 12 seconds and finite, with maximum absolute difference If a higher default is preferable for the project's CUDA-oriented baseline, I would be happy to adjust it following your guidance. Thank you again. |
Summary
--chunk-secondsand--overlap-secondsoptions for bounded-memory long-audio inference.--chunk-batch-sizeso a fixed number of chunks can share one model forward pass.1for minimum accelerator memory; larger values are an explicit throughput/memory tradeoff.Chunk and batch behavior
Tests
python -m unittest discover -s tests -v: 20/20 passed.[2, 2, 1]batch grouping, bounded transfer lengths, final-chunk padding/crop, short-input full-file behavior, invalid settings, early batch-size validation, and short model output rejection.python -m py_compile inference.py tests/test_inference.py: passed.python -m pip check: passed.git diff --check: passed.Apple Silicon validation
MPS validation used an Apple M3, macOS 27.0, native arm64 Python 3.10, and PyTorch/TorchAudio 2.11.0. The repository's public six-second fixture was concatenated with itself locally to create a 12-second public test input; the checked-in fixture was not modified.
The earlier full-file versus sequential-chunk reference remains:
A new local-checkpoint run compared fixed chunk batch sizes:
Both batched outputs were float32 PCM, stereo, 44.1 kHz, exactly 12 seconds, and finite. Batch sizes 1 and 2 had maximum absolute difference
1.04308128356934e-06, RMSE3.84001256540259e-08, and correlation0.999999999999966. The public input SHA-256 remained unchanged.On this MPS machine, batch size 2 did not improve runtime and increased peak memory. The implementation therefore exposes batching without claiming a universal speedup. CUDA may behave differently, but CUDA hardware was not available for local validation.
Limitations and scope
Copyright and safety
Validation used only the repository's public fixture. No private music, checkpoint, WAV input/output, virtual environment, cache, or generated artifact is included in the commit.
Refs #37