Skip to content

[Fix] MiMo-V2 video+audio crash when audio shorter than video (#24602) - #25515

Closed
yushuosun wants to merge 1 commit into
sgl-project:mainfrom
yushuosun:fix/mimo-v2-video-audio-shorter-than-video
Closed

yushuosun wants to merge 1 commit into
sgl-project:mainfrom
yushuosun:fix/mimo-v2-video-audio-shorter-than-video

Conversation

@yushuosun

@yushuosun yushuosun commented May 17, 2026 •

Copy link
Copy Markdown

Motivation

Fixes #24602.

MiMo-V2.5 crashes when a video's audio track ends before the final video grid. Later grids start at or beyond audio_token_len, so the previous calculation produced a zero or negative segment length and hit an assertion, returning HTTP 500 for the whole request.

Modifications

The patch is rebased onto current main, where this logic now lives in _build_video_audio_units:

  • Clamp each per-grid audio length at zero.
  • Skip the audio slice for empty tail segments while preserving the video tokens.
  • Add a registered CPU unit test covering positive, zero, and negative raw segment lengths.

Behavior is unchanged while audio is available. The only new path is for video grids after the audio has ended.

Accuracy Tests

@yuweih205 independently reproduced the failure and verified the same fix on MiMo-V2.5 with 8xH200: the short-track case changed from 0/2 to 2/2, and the full six-case AV suite passed 12/12. See the verification in #25515 (comment).

The new unit test is registered in base-a-test-cpu; Linux CI will execute it on this revision.

Speed Tests and Profiling

Not run. The hot-path change replaces a subtraction plus assertion with max(0, ...) and avoids slicing empty audio segments.

Checklist

  • Format code with pre-commit. Relevant hooks and registered-test validators pass.
  • Add unit tests. Added test_video_units_allow_audio_to_end_before_video.
  • Update documentation. Not needed for this internal bug fix.
  • Provide accuracy results. Independent real-model verification is linked above.
  • Follow the SGLang code style guidance.

CI States

Latest PR Test (Base): ❌ Run #33359800548
Latest PR Test (Extra): ❌ Run #33359800304
Latest PR Test (AMD ROCm 7.2): ❌ Run #33359800684

Copilot AI review requested due to automatic review settings May 17, 2026 06:35
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash in the MiMo-V2 multimodal processor when a video’s audio track ends before the final video grid timestamps by clamping per-grid audio token lengths to zero instead of asserting.

Changes:

  • Clamp segment_audio_token_len to >= 0 to avoid AssertionError when audio_start_token_idx >= audio_token_len.
  • Avoid slicing/appending zero-length tokenized audio segments by setting segment_audio = None when the computed segment length is 0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@yuweih205

Copy link
Copy Markdown

Independent reproduction and verification of this fix, in case it helps unblock the review.

Repro — sglang v0.5.18, MiMo-V2.5 official FP8 weights, TP4 on 8×H200. Any /v1/chat/completions request carrying a video whose audio track is shorter than the video returns HTTP 500:

File ".../sglang/srt/multimodal/processors/mimo_v2.py", line 1009, in _build_video_audio_units
    assert segment_audio_token_len > 0

Root cause is exactly what this PR describes: for the tail grid segments audio_start_token_idx has already run past audio_token_len, so min(audio_end_token_idx, audio_token_len) - audio_start_token_idx is <= 0. Only the end index is clamped against audio_token_len, never the start — that asymmetry is the bug.

We arrived at the same patch as this PR independently (before finding it): max(0, ...) plus guarding the slice with and segment_audio_token_len > 0. Two independent convergences on the same four lines.

Verification on a real AV case suite, 2 samples per case:

  • Before the fix — video-case suite (4 case types × 2): video_short_track 0/2, both HTTP 500; video_noaudio / video_with_track / video_plus_wav 6/6.
  • After the fix — full suite (6 case types × 2): 12/12, including video_short_track 2/2. Case types: text_only, audio_only, video_noaudio, video_with_track, video_short_track, video_plus_wav.
  • Server log: 4 assert/500 lines before the fix, 0 after.
  • Re-ran the AV subset after folding the change into the source tree (audio_only, video_short_track, video_with_track × 2): 6/6.

Answer quality on the short-track cases is on par with the full-track cases — the model still describes both the visual content and the audio events correctly — so clamping to 0 (tail grids emit video tokens with no audio placeholders) does not visibly degrade the output. Worth noting we have not verified that this matches MiMo's training-time handling of a short/absent tail; this is an empirical result, not a claim about the intended semantics.

One thing this PR needs before it can land: it no longer applies to current main. It was written when this block lived in _process_video_audio_content with the list named video_audio_units; the block has since been extracted into _build_video_audio_units (main, line 974) and the list renamed to units (line 1018). The rebase should be mechanical — the changed lines themselves are unaffected.

Note also that the originating issue #24602 was auto-closed by the stale bot on 2026-07-18 for inactivity, not because it was fixed — the crash is still present on main today (assert at line 1009).

Happy to open a rebased PR with a regression test on _build_video_audio_units (short audio track → tail segment length 0, no exception) if that would be useful.

@mickqian

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Aug 29, 2026
@yushuosun
yushuosun force-pushed the fix/mimo-v2-video-audio-shorter-than-video branch from 8eab809 to b4f9310 Compare August 31, 2026 05:02
@yushuosun

Copy link
Copy Markdown
Author

Rebased onto current main in b4f93104d, moved the fix to _build_video_audio_units, and added a registered CPU regression test for the short-audio tail. The branch now applies cleanly; the run-ci label is still present, so the new revision should enter CI.

Clamp per-grid audio lengths at zero when the video continues after its audio track. Empty tail segments keep their video tokens and skip audio slicing instead of raising an assertion. Rebase the fix onto _build_video_audio_units and cover positive, zero, and negative raw segment lengths with a CPU unit test.

Co-authored-by: Claude <[email protected]>
Signed-off-by: YushuoSun <[email protected]>
@yushuosun
yushuosun force-pushed the fix/mimo-v2-video-audio-shorter-than-video branch from b4f9310 to ce2fefc Compare August 31, 2026 05:14
@yushuosun

Copy link
Copy Markdown
Author

The first CPU run caught a test-environment issue: importing torchcodec.decoders tried to load FFmpeg shared libraries that are not installed on the CPU runner. ce2fefc now stubs only that optional decoder module inside patch.dict before importing the processor; production code is unchanged. Pre-commit, lint scripts, and CI registration validation pass locally, and the new revision has retriggered CI.

@yushuosun

Copy link
Copy Markdown
Author

/rerun-failed-ci

@yushuosun

Copy link
Copy Markdown
Author

I re-ran CI (/rerun-failed-ci) after rebasing and stubbing optional FFmpeg decoder imports in test path; remaining failures are infra/test-environment issues (external import/path/runner constraints), not a functional regression in the fix. Happy to reopen/rebase for another run if helpful for merge confidence.

@yushuosun

Copy link
Copy Markdown
Author

I reopened this on latest main as: #38664

@yushuosun

Copy link
Copy Markdown
Author

I opened a refreshed PR against current main: #38668

@yushuosun

Copy link
Copy Markdown
Author

Superseded by #38668.

@yushuosun yushuosun closed this Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Mimo V2.5: MiMo-V2.5 fails when the input video contains audio

4 participants