Skip to content

Studio MiniMax-H3: bound reference audio resampling memory for rates coprime with 32 kHz - #18569

Merged
danielhanchen merged 1 commit into
mainfrom
fix-recheck-resample-memory
Nov 20, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix-recheck-resample-memory

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

#17764 added resample_h3_audio, which converts MiniMax-H3 reference audio to 32 kHz before either engine (Diffusers or sd.cpp) sees it. It builds the sinc filter as one dense table of shape [new, 1, 2 * width + orig], where orig and new are the two rates divided by their gcd. For common rates the table is tiny (44.1 kHz is [320, 1, 459]), but a rate that shares almost no factor with 32 kHz makes it enormous regardless of clip length. A valid WAV at 44,099 Hz gives [32000, 1, 44117], 5.3 GiB per float32 intermediate, and the filter construction holds several of them at once. Resampling 1,024 samples (23 ms) of such a clip peaked at 22.2 GiB of host RAM and took 8.6 s on CPU. The rate comes straight from the uploaded container (stream.codec_context.sample_rate), so any user upload can hit it.

Change

When the dense table would exceed 4M elements (16 MiB in float32), resample_h3_audio now evaluates the same filter only on the 2 * width + 1 taps around each output sample, in chunks of 65,536 output samples. Every tap outside that window is clamped to the edge of the filter window, where the dense kernel is below 1e-20, so dropping them changes nothing beyond float rounding. The kernel values are computed with the same float32 expressions as the dense path. Memory now scales with the output length instead of the rate ratio.

Rates whose table fits under the threshold (44.1, 48, 22.05, 11.025, 16, 8, 96, 192 kHz and every other common rate) still take the existing dense path, so their output is bit for bit unchanged and still equals torchaudio's default kernel.

Tests

  • test_resampler_memory_does_not_scale_with_the_rate_ratio (44,099, 44,101, 8,001 and 32,001 Hz) runs the resampler on meta tensors and records the largest tensor any op produces, requiring it to stay under 64 MiB. It fails on main (largest intermediate 5.3 GiB at 44,099 Hz) and passes here.
  • test_windowed_resampler_matches_the_dense_kernel forces the windowed path on five rates and compares it with the reference dense implementation: within 1e-12 in float64 and within 1e-6 in float32.
  • Measured on CPU, 1,024 stereo samples at 44,099 Hz: peak RSS 22.2 GiB and 8.6 s on main, 0.01 GiB and 0.03 s here; a 15 s clip at 44,099 Hz takes 0.5 s and 0.03 GiB. Against a float64 oracle the float32 error is the same on both sides (1.42e-4 main, 1.42e-4 here, dominated by the float32 phase computation both share); main and this branch differ by at most 7.2e-7 on unit-variance input. 44.1 kHz and 22.05 kHz output is identical to main.
  • tests/test_h3_reference_recipe.py plus the H3 and video test files that import video_minimax_h3: same failing test IDs on main and on this branch, no new failures.

Not proven

  • No comparison against torchaudio.functional.resample at a coprime rate (torchaudio itself builds the same dense table, so it needs the same tens of GiB); the windowed path is checked against the dense formula instead.
  • No GPU render with a coprime-rate reference clip; the resampler runs on CPU before either engine starts.

…coprime with 32 kHz

A source rate sharing almost no factor with 32 kHz (44,099 Hz) made the dense
sinc table [32000, 1, 44117], 5.3 GiB per intermediate and over 22 GiB peak for
a 23 ms clip. Past 4M table elements, evaluate the same filter only on the
2 * width + 1 taps around each output sample, in chunks. Common rates keep the
dense path and are unchanged bit for bit.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T05:39:10.250800Z e2e3c18 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: e2e3c18c80

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit d452b9e into main Nov 20, 2026
@danielhanchen
danielhanchen deleted the fix-recheck-resample-memory branch November 20, 2026 07:36
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.

1 participant