Repository navigation
Add padding to chunked inference - #42
Conversation
|
[P1] Handle padding that reaches before the file start
For example, with Please derive the crop offset from the actual padded start after applying the edge handling, e.g. |
This commit is expected to fail, so the bug can be confirmed before any fix
lands. Check out this commit and run:
python -m unittest discover -s tests
The suite reports one failure: with 0.5 s chunks, a 0.1 s overlap and 0.5 s
of padding, an identity model differs from its own input on 27.8% of
samples. The fix follows in the next commit.
|
Thanks for the review @JusperLee ! I added the regression test (that does fail at the moment). The fix I have in mind: Before inferenceReplace And save the After inferenceDerive the crop offset using Working on the fix, let me know if you have any issues with this. |
|
The fix is up.
|
What
A new
--chunk-pad-secondsoption (default 0) for chunked inference: each chunk's model input is extended with that much surrounding audio on each side, and the model's output for the extension is discarded. Chunk layout, overlap, crossfade, and the number of forward passes are unchanged; each pass grows fromchunktochunk + 2 × padsamples.--chunk-pad-seconds 0reproduces the current output bit-exactly.Why
The model's output is wrong near the edges of its input. Restoring the same audio twice with different chunk positions and subtracting the two outputs: they match bit for bit except within ~0.5 s of an input edge, where the difference reaches the level of the music itself at the trailing edge (about −25 dB at the leading edge). The extent is ~0.5 s whether the chunk is 4, 6, or 10 s long.
Chunked inference crossfades exactly those regions into every seam. On the repository's 6 s fixture tiled to 20 s, with 6 s chunks and a 1 s overlap, SNR against a single unchunked pass collapses at every chunk boundary:
The remaining dips common to both traces are numerical differences between the CUDA reference and these MPS renders; padding 1.0 and 2.0 agree with each other past 120 dB at those spots. These still need to be investigated.
How
Padding is real neighboring audio, and the file's own edges take none: the first padded chunk begins at the file start, and the last one ends at the file end, extending further left instead. Both file edges therefore come out exactly as an unchunked pass produces them.
1s is the recommended value: it clears the measured ~0.5 s edge extent with margin, and costs one third more samples per forward pass at 6 s chunks.
Tests
infover the outer 0.05 s of every input, run throughrun_inferencewith--chunk-pad-seconds 0.05), and that when--chunk-pad-seconds 0with the same modelinfvalues make it to the output.--chunk-pad-seconds 0compared sample-for-sample againstmain's output on the released checkpoint (20 s render): identical.python -m unittest discover -s tests -v: 22/22 passed.python -m py_compile inference.py tests/test_inference.py: passed.python -m pip check: passed.git diff --check: passed.