fix: correct MiniMax H3 reference audio encoding - #1886
Conversation
|
Same settings and assets as in #1882 repro: output.mp4Voice matches the reference now at least so it's much better than before, but the speech is still incoherent, which I believe should not happen if the model is asked to reuse the audio exactly... |
|
Thanks for testing this. I downloaded the result and compared it with the original reference from #1882. Whisper Large-v3 transcribes the reference as:
It transcribes the new generated result approximately as:
So I agree that the generated transcript is still incoherent. The fact that the voice now matches the reference is useful confirmation that the repaired reference latent is reaching Ref2VA; the remaining transcript behavior is separate from the stereo encoder corruption fixed here. At present, For generated speech, including the literal sentence in the text prompt should improve semantic adherence, for example:
Using the prompt guide's I think H3's transcript adherence can still be investigated separately. This PR is intentionally narrower: it restores the C++ audio encoder to near-numerical parity with the official PyTorch encoder and fixes the corrupted reference conditioning. It does not implement deterministic soundtrack copying or guarantee exact generated speech. |
|
Even if I edit the prompt file to replace my typo If I add I'm thinking maybe there is an issue either with the way the reference audio latents are ordered or with their positionnal encodings, but i cannot find what exactly. |
|
i found something: diff --git a/src/model/diffusion/minimax_h3.hpp b/src/model/diffusion/minimax_h3.hpp
index d0683166..c9175769 100644
--- a/src/model/diffusion/minimax_h3.hpp
+++ b/src/model/diffusion/minimax_h3.hpp
@@ -835,6 +835,18 @@ namespace MiniMaxH3 {
}
};
+ auto append_condition_audio_positions = [&](int64_t length,
+ float cursor,
+ float w_low,
+ float w_high) {
+ for (int64_t t = 0; t < length; ++t) {
+ for (int channel = 0; channel < 2; ++channel) {
+ float w = channel == 0 ? w_low : w_high;
+ append_position(cursor + static_cast<float>(t) * 2.0f, 0.f, w);
+ }
+ }
+ };
+
float cursor = static_cast<float>(text_len);
if (reference_blocks.empty()) {
float video_duration = 0.f;
@@ -888,7 +900,7 @@ namespace MiniMaxH3 {
w_high = axes.second.back();
}
int64_t count = ref_audio->shape()[0] * 2;
- append_audio_positions(ref_audio->shape()[0], cursor, w_low, w_high);
+ append_condition_audio_positions(ref_audio->shape()[0], cursor, w_low, w_high);
layout.sequence_segments.push_back({row,
row + count,
SequenceKind::CONDITION_AUDIO,output-dirtyfix.mp4Of course this is most likely not the correct way to fix this issue, but that's a clue to whatever is going on. Maybe w_high is not correct for audio? |
Summary
Fix MiniMax-H3 stereo reference-audio encoding so the C++ audio VAE matches the official PyTorch implementation.
The current encoder reshapes stereo into a batched
conv1dinput. On the tested GGML Metal backend, convolution output storage interleaves the stream dimension with feature channels, while later layers read each stream's feature channels as contiguous. This corrupts the reference latent before Ref2VA conditioning.This change:
zero_k_biasin causal attention.Fixes #1882.
Verification
Tested on Apple M4 Max with the Metal backend and
minimax_h3_audio_vae_fp32.safetensors.Cross-decoding isolated the failure to C++ encoding:
For the same 3.04-second stereo WAV, fixed C++ versus PyTorch normalized latents:
122 x 2 x 32 x 10.99998370.00043430.45343020.4534051The original latent correlation was approximately
-0.066.A clean checkout at
de298c2builds successfully with:A clean-checkout 4-step Ref2VA smoke test also completed successfully, although its generated output was music and is not used as speech-quality evidence. The latent parity and cross-decoding results above came from an instrumented build of the same encoder implementation. Separate longer repaired-input tests produced intelligible, input-dependent generated speech. H3 still generates a new target soundtrack; this patch does not claim waveform copying or exact transcript preservation.
Scope
This is focused on MiniMax-H3 reference-audio encoding. T2AV primarily exercises the audio decoder and therefore does not expose this encoder defect.
AI assistance
AI tools assisted with investigation and patch preparation. I reviewed the changed lines and validated the implementation against the official PyTorch encoder, cross-decoding, a clean build, and end-to-end runs.