Repository navigation
Studio video: compare streamed frames without chunk-sized temporaries (H3 export stalls) - #16024
Merged
Merged
Conversation
np.array_equal allocated a bool array the size of each streamed chunk. numpy madvises allocations over 4 MiB for transparent huge pages, and on a host whose memory is fragmented by pinned weights every such fault ran direct reclaim plus compaction that failed. On MiniMax-H3 1344x768x124 (A100-40) this made the streamed export compare take 115-152 s. The compare now walks the chunk in 1 MiB uint64 slices into a reused 128 KiB scratch, so it allocates nothing per slice and decides exactly like np.array_equal. UNSLOTH_STUDIO_VIDEO_STREAM_COMPARE_SLICED=0 restores the old compare.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
This was referenced Oct 29, 2026
danielhanchen
added a commit
that referenced
this pull request
Oct 29, 2026
`Repo tests (CPU, rest-2)` is red on main since #15996 (Use via API button on the Train page). It now fails on unrelated PRs, for example #16024: ``` test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding[5] AssertionError: 1 file reads in the test trees touch a checked-in file with the platform default encoding ... 'studio/backend/tests/test_training_api_snippet_contract.py:19: read_text()' ``` The new snippet contract test reads its JSON fixture `fixtures/training_api_job_bodies.json` with `read_text()`. On Windows that decodes as cp1252, so the test breaks as soon as the fixture gains a non-ASCII byte. The guard is right and the test was wrong. The fix is `read_text(encoding = "utf-8")`. ## Verification - `tests/test_source_read_encoding.py`: fails on main (the one site above), 16 passed here. - `studio/backend/tests/test_training_api_snippet_contract.py`: 12 passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On MiniMax-H3 1344x768x124 (A100-40), the export of a finished clip sometimes took 115-184 s instead of about 1-2 s. The time goes into the frame compare that decides whether the streamed mp4 can be handed out (
StreamEncode._matches,np.array_equalper chunk).Cause:
np.array_equalallocates a bool array the size of the chunk (about 55 MB per H3 chunk). numpy marks allocations of 4 MiB and up for transparent huge pages, so every fault into that array tries to build a 2 MiB page on the spot. After an H3 load the host holds about 45 GB of small pinned pages spread through memory plus the page cache of the weights, so almost no 2 MiB block can be freed: each fault runs direct reclaim and a failed compaction, then falls back to a small page.Measured on the live H3 A100 host with the real
_matchescode:Background pinning and the GIL are not the cause:
pin_plainhad finished minutes before the exports started (it only left memory fragmented), and a 4 Hz Python sampler thread kept its full rate through a 183 s export.Change
_frames_equalcompares each chunk in 1 MiB slices (as uint64 words) into one reused 128 KiB bool buffer, so the compare allocates nothing per slice and never reaches the huge-page fault path. It decides exactly asnp.array_equal: shape, dtype, the trailing bytes, and non-contiguous inputs (those fall back tonp.array_equal).UNSLOTH_STUDIO_VIDEO_STREAM_COMPARE_SLICED=0brings back the whole-chunknp.array_equal.Results
H3 1344x768x124 on an A100-40, base and head alternating (S F S F), a fresh Studio home per arm, page cache prewarmed before each arm, a cold render plus 2 more per arm (8 steps; the export does not depend on the step count):
Frames: the final frames are identical in all four arms, and the cold render's streamed mp4 is byte-identical across arms and to the stock (non-streamed) export of the same frames. In the CPU microbench the mp4 and decoded-frame md5 match across base, head, the kill switch and the no-huge-page control on L4 and A100.
Tests
studio/backend/tests/test_video_stream_encode_compare.py(9 CPU tests): equality and every mismatch case againstnp.array_equal, the kill switch, and a tracemalloc check that the compare allocates under 512 KiB (a whole chunk with the kill switch). All pass on head and fail on base.test_video_stream_encode.pyandtest_video_decode_oom_retry.py: 29 passed, 1 skipped.test_a_compiled_decode_runs_the_chunk_hook_as_one_eager_island[cpu]and one test intest_integrated_gpu_no_host_pin.pyfail the same way on base.Not proven