Skip to content

Studio video: refuse a NaN render on the native MiniMax-H3 route - #15394

Merged
danielhanchen merged 2 commits into
mainfrom
studio-h3-native-nonfinite
Oct 26, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-h3-native-nonfinite

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

The MiniMax-H3 native route (stable-diffusion.cpp sd-server / sd-cli) now refuses a NaN render with the same NonFiniteFramesError message the Diffusers path uses (#15339, #15374), instead of saving a black clip. The check is behind the existing UNSLOTH_VIDEO_NONFINITE_CHECK kill switch.

Why a check on the returned clip

sd.cpp has no NaN / inf check of its own. A NaN render logs nothing unusual, exits 0, and writes the clip. Studio only gets an encoded container back (MJPEG + PCM in AVI from sd-server, VP8 + PCM in WebM from sd-cli), so there is no float clip to check.

What a NaN render turns into:

  • The VAE tails clamp on the device. Video is clamped to [0, 1], audio to [-1, 1].
  • ggml's clamp maps NaN differently per backend. On CUDA (fminf / fmaxf) NaN becomes the lower bound. On the CPU backend (MIN / MAX macros) it becomes the upper bound. This was measured against ggml on both backends.
  • The whole clip is affected. The H3 DiT attends text, video and audio tokens jointly, so a NaN there reaches every token. Every frame comes out flat black (or white on CPU), and the PCM soundtrack is one constant full-scale level (-32767 / 32767).

A flat-frame check alone is not safe. A legitimate night scene a few levels above black decodes almost flat after the lossy MJPEG / VP8 encode. The soundtrack is what tells the two apart: no generated soundtrack is a single full-scale DC level for the whole clip.

Change

  • h3_native_clip_is_nan_render(path) (video_minimax_h3.py, torch-free). It flags a clip only when it has an audio track whose every sample is one full-scale level, and every frame is exactly black (or white). It reads the audio first, so a normal clip costs one PCM decode.
  • _generate_h3_native runs it before inspect_video, which covers both the server and the CLI routes. A match raises NonFiniteFramesError(NON_FINITE_FRAMES_MSG), which video_failure_detail already maps for the UI. A probe that cannot read the clip never fails the render.

These clips are always kept: flat black with real or silent audio, a dark clip, a clip without audio, and real frames over a broken soundtrack.

Tests

tests/test_h3_native_nonfinite.py writes clips the way sd.cpp writes them, in both containers.

  • On main: 5 failed, 18 passed. The 4 NaN fingerprints and the end-to-end refusal fail; the keep cases pass.
  • On this branch, all pass.
  • pytest -n 4 over the new file, test_video_backend.py, test_video_static_skip.py, tests/test_sd_cpp*.py and tests/test_h3_native_*.py: 2205 passed, 1 skipped.

Limits

  • Not caught: a NaN only in the video VAE (flat frames over real audio look like a real black clip, so it is kept), a partial NaN such as one bad tile, and a render without audio. A finiteness check inside stable-diffusion.cpp would be the complete fix.
  • No full H3 NaN render was run. The fingerprint comes from the sd.cpp source, ggml clamp behaviour measured on CPU and CUDA, and clips written by sd.cpp's own container writers.

…ing it

sd.cpp has no NaN check and exits 0 on a NaN render. Its VAE tails clamp on the
device, and ggml's clamp maps NaN to the lower bound on CUDA and to the upper one
on the CPU backend, so the clip comes back as flat black (or white) frames over a
constant full-scale PCM soundtrack. Refuse exactly that fingerprint with the
existing NonFiniteFramesError message, behind UNSLOTH_VIDEO_NONFINITE_CHECK. A
flat black clip with real or silent audio, a dark clip, and a clip without audio
are kept; an unreadable clip never fails the render.
@danielhanchen danielhanchen self-assigned this Oct 26, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T16:25:42.952089Z 01d59bf 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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 01d59bf952

ℹ️ 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 d5126dd into main Oct 26, 2026
32 of 42 checks passed
@danielhanchen
danielhanchen deleted the studio-h3-native-nonfinite branch October 26, 2026 17:08
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