Skip to content

studio: lift the H3 binary preflight into its own method - #8570

Closed
danielhanchen wants to merge 1 commit into
mainfrom
fix/h3-preflight-before-download
Closed

danielhanchen wants to merge 1 commit into
mainfrom
fix/h3-preflight-before-download

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Lifts the MiniMax-H3 binary preflight out of _run_load_h3_native into its own _h3_native_binary method. Pure refactor, no behaviour change.

Why this PR shrank

It originally moved the preflight in front of the four-file download. #8560 shipped that, along with the refusal when no binary can be produced, the cancellation checks either side of the ensure, and a post-download re-vet that covers identity, capability and the accelerator reading for user-supplied builds as well as managed ones. All of that is on main, so it has been dropped from here and the branch rewritten against main.

What is left is the structural half. _run_load_h3_native is about assets, and the block that acquires the sd-cli, installs it, probes its device list and decides native_device now sits at the top of it. Nothing in that block reads a resolved path, so it reads better as a named method returning the three values the rest of the load needs.

Validation

  • test_sd_cpp_h3_matrix.py (168 cases over platform x GPU vendor x binary state) passes unmodified, which is the evidence the move changes nothing: those cases pin the cancellation ordering, the download-count on every refusal, the accelerator fallback and the device-probe count.
  • test_video_backend.py, test_sd_cpp_backend.py, test_sd_cpp_engine.py: 530 passed. The one failure, test_a_quantized_reference_load_resolves_the_reference_denoiser, fails on main too and is environmental (the installed diffusers lacks the bundled H3 revision).
  • Ruff and the kwarg-spacing format hook clean.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 55079a9101

ℹ️ 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".

Comment thread studio/backend/core/inference/video.py Outdated
Comment on lines +1576 to +1578
native_device, listed_accelerator, binary = self._h3_native_binary(
cancel_event = cancel_event
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor cancellation before acquiring sd-cli

When unload() sets the load's cancellation event before this worker reaches the call—or while acquisition is running—the new ordering still enters ensure_h3_sd_cpp_binary, whose installer does not consume cancel_event and may download/extract an entire prebuilt before the later asset-loop check notices cancellation. Previously, an already-cancelled H3 load stopped at the first asset-loop check before reaching binary installation. Check the event before this call and make the acquisition path cancellable so cancelling a load does not leave a potentially minutes-long background download running.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, fixed in cf6c648. _h3_native_binary now raises VIDEO_CANCELLED_MSG when cancel_event is already set, restoring the stop the download loop's own first check used to provide. Making the install itself consume cancel_event is a separate change: ensure_h3_sd_cpp_binary and the prebuilt installer take no cancel token, and that was equally true before this reorder, so this fix is scoped to the case the reorder actually regressed. Regression test: test_h3_native_load_stops_on_an_already_cancelled_load_before_acquiring.

Comment thread studio/backend/core/inference/video.py Outdated
Comment on lines +1576 to +1578
native_device, listed_accelerator, binary = self._h3_native_binary(
cancel_event = cancel_event
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Publish H3 companion repos before acquiring sd-cli

When sd-cli installation takes time and a user deletes H3_GGUF_REPO or H3_COMPONENT_REPO concurrently, this new call runs before _loading.asset_repos is populated, so the cached-model deletion guard can admit the delete and reserve it before the H3 download begins. Publishing the repos later does not revoke an already-started deletion, which can then remove cached or newly resolved files underneath this load. Move the companion-repo publication ahead of binary acquisition while leaving the byte estimate update where it is.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, fixed in cf6c648. The base_repo and asset_repos claim now happens before _h3_native_binary, so the delete-cached guard cannot admit a delete of the H3 companion repos during an install that may run for minutes. The byte estimate stays where it was, since the sizes are not known any earlier. Regression test: test_h3_native_load_claims_the_companion_repos_before_acquiring_the_binary, which asserts the claim is already visible inside the acquisition.

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Aug 12, 2026
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Aug 12, 2026
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Aug 12, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: cf6c64859a

ℹ️ 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

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c2e5dd38c4

ℹ️ 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".

Comment thread studio/backend/core/inference/video.py Outdated
Comment on lines +1590 to +1592
native_device, listed_accelerator, binary = self._h3_native_binary(
cancel_event = cancel_event
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Re-vet unmanaged binaries after the download

When SD_CLI_PATH/UNSLOTH_SD_CPP_PATH points to a user-supplied binary that is replaced while the tens-of-GB bundle downloads, this early check vets the old file, but the final check only calls sd_cpp_supports_minimax_h3 and compares accelerator support when is_managed_binary(binary) is true. The replacement therefore needs only to pass engine.version() before its identity is committed, so an older or differently accelerated external build can make the load report ready and then fail generation or violate device accounting. Re-run the capability/device checks for unmanaged binaries after the download as well.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, fixed in 372da2c. The is_managed_binary guard was sound while the vet sat immediately above the re-vet, since only an install can replace a copy we own, but vetting before the download turns that window into the whole bundle. _h3_native_binary now returns the identity of the file its answers came from, and the re-vet re-opens both the capability and the accelerator question whenever that identity changed, managed or not. Gating on identity rather than probing unconditionally keeps the ordinary case free, since an unchanged file cannot have changed its answers. Regression test: test_h3_native_load_rejects_a_user_binary_swapped_during_the_download, which swaps the binary from inside the download callback.

@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: 372da2c00c

ℹ️ 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 added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Aug 12, 2026
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Aug 13, 2026
@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. Swish!

Reviewed commit: d099ab4e02

ℹ️ 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

Copy link
Copy Markdown
Member Author

Status check on this PR's CI, since the board looks far worse than it is.

gh pr checks renders cancelled runs in the same column as failed ones. Every one of the 37 red checks at head d099ab4e is cancelled, not failed:

31653664547: Backend CI      | completed | cancelled | d099ab4e | 00:12:58Z
31653664741: Security audit  | completed | cancelled | d099ab4e | 00:12:58Z
31653664614: Windows GGUF CI | completed | cancelled | d099ab4e | 00:12:58Z
... 15 of 15 workflows, all cancelled

--log-failed is empty for all of them and the job objects come back with "steps":[], so no step ever ran. The uniform 47-54s durations are time-to-cancel, not time-to-failure. The three "passing" checks are just the jobs that finished inside that window. The same sweep hit unrelated branches in the same few minutes, so it was queue-wide, not about this PR.

The last head with a completed CI set is 372da2c0: 14 of 15 workflows green, and Backend CI failing identically on Python 3.10 through 3.13 with

tests/test_desktop_auth.py::test_health_response_reports_desktop_capability_fields
  ImportError: cannot import name 'openai_codex_auth_router' from 'routes' (unknown location)
tests/test_external_provider_usage_chunk.py::test_other_providers_do_not_get_the_continuation_flags[openai-...]
  ValueError: Responses event type is missing
tests/test_gemini_provider.py::test_openai_responses_forced_function_tool_choice_drops_hosted_tools
  ValueError: Responses event type is missing

That is main's own defect, reproduced on a clean checkout with no PR applied, and it is what #8590 and #8608 fix. This PR is blocked behind those two merging, not broken.

Local runs on this head:

tests/test_video_backend.py + the H3 tests: 1 failed, 310 passed
the PR's own H3 selection:                  75 passed, 144 deselected, exit 0
ruff:                                        All checks passed

The single local failure, test_a_quantized_reference_load_resolves_the_reference_denoiser, is not this PR's: it arrived with #8329, the PR diff does not touch it, it reproduces on clean main here, and CI passed it at 372da2c0. It gates on a bundled diffusers revision, so it is a local environment gap.

Stated plainly: head d099ab4e has never had a completed CI run, so "this PR is clean" rests on the green set at 372da2c0 plus local runs of the changed files. The delta between those heads is a merge of main plus a 7-line test string swap, which I read in full. That is inference, not a green board.

_run_load_h3_native is about assets, and the block that acquires the sd-cli, installs it,
probes its device list and decides native_device now sits at the top of it because #8560
moved that work in front of the download. Nothing in the block reads a resolved path, so
it reads better as _h3_native_binary returning the three values the rest of the load needs.

Pure move. The behaviour it encodes -- the entry and exit cancellation checks, the
accelerator fallback, the refusal when no binary could be produced -- is unchanged, which
the 168 platform x GPU vendor cases in test_sd_cpp_h3_matrix.py pin without modification.
@danielhanchen
danielhanchen force-pushed the fix/h3-preflight-before-download branch from d099ab4 to 781ea7e Compare August 13, 2026 06:58
@danielhanchen danielhanchen changed the title studio: vet the H3 sd-cli before downloading the H3 bundle studio: lift the H3 binary preflight into its own method Aug 13, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

Rewritten against main now that #8560 has landed.

The reordering this PR opened for is on main, along with several things that turned out to be needed alongside it: the refusal when no binary can be produced, cancellation checks either side of the ensure, and a post-download re-vet that covers identity, capability and the accelerator reading for user-supplied builds rather than only managed ones. Keeping those here would have been a duplicate, so the branch has been reduced to the structural half it also carried, and force-pushed.

What remains is the extraction of the acquisition block into _h3_native_binary. The 168 cases in test_sd_cpp_h3_matrix.py pass unmodified, which is what makes it a pure move rather than a rewrite: they pin the cancellation ordering, the download count on every refusal path, the accelerator fallback and the device-probe count.

@danielhanchen

Copy link
Copy Markdown
Member Author

Superseded by #8560, which landed the preflight hoist and the cancel check with the same reasoning, and also did the unmanaged re-vet. #8560's version of that last one is better than mine: it drops the is_managed_binary test outright rather than gating on a changed identity, checks sd.cpp identity as well as the H3 marker (--ref-video alone is a plain option name an unrelated tool could expose), and uses a verdict form for the accelerator probe that does not fold 'could not tell' into True, which removes a false-refusal my version still carried.

The one thing left over is the companion-repo claim ordering: asset_repos is still set after the preflight on main, so the delete-cached guard is blind for the whole prebuilt install. That is now #8657, cut fresh from main with its regression test.

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