Repository navigation
Studio: realign the image precision contracts with the fail-closed refusal - #8257
Merged
danielhanchen merged 1 commit intoAug 9, 2026
Conversation
…fusal Four tests are red on a clean checkout of main. unslothai#8165 made a declined EXPLICIT precision refuse the load instead of falling back silently, and made the text-encoder pass return a TEQuantOutcome the loader reads .mode off. Two later squash merges carried branches cut before it: unslothai#8162 added the saved-recipe precision contracts, and unslothai#8141 added a placement test whose stub returns a bare None. Neither combination was ever run. Fixed on the test side. quantize_text_encoders is annotated -> TEQuantOutcome and every one of its seven returns constructs one, so the None at diffusion.py:3113 only exists because a test monkeypatches the function; and the route only calls assert_precision_available on the diffusers engine, which is DiffusionBackend, which defines it. Neither AttributeError is reachable in a real run, so there is no product guard to add. - opt into UNSLOTH_DIFFUSION_ALLOW_PRECISION_FALLBACK where the contract is about what the recipe records once a fallback is allowed, as the routes, backend and video suites already do - assert the decline reason unslothai#8165 records instead of the old wording naming what loaded instead. The substantive pair is untouched: off, from explicit - give _EngagedBackend the assert_precision_available gate the route now calls, and return a TEQuantOutcome from the stubbed text-encoder pass
danielhanchen
added a commit
that referenced
this pull request
Aug 9, 2026
…fusal (#8257) Four tests are red on a clean checkout of main. #8165 made a declined EXPLICIT precision refuse the load instead of falling back silently, and made the text-encoder pass return a TEQuantOutcome the loader reads .mode off. Two later squash merges carried branches cut before it: #8162 added the saved-recipe precision contracts, and #8141 added a placement test whose stub returns a bare None. Neither combination was ever run. Fixed on the test side. quantize_text_encoders is annotated -> TEQuantOutcome and every one of its seven returns constructs one, so the None at diffusion.py:3113 only exists because a test monkeypatches the function; and the route only calls assert_precision_available on the diffusers engine, which is DiffusionBackend, which defines it. Neither AttributeError is reachable in a real run, so there is no product guard to add. - opt into UNSLOTH_DIFFUSION_ALLOW_PRECISION_FALLBACK where the contract is about what the recipe records once a fallback is allowed, as the routes, backend and video suites already do - assert the decline reason #8165 records instead of the old wording naming what loaded instead. The substantive pair is untouched: off, from explicit - give _EngagedBackend the assert_precision_available gate the route now calls, and return a TEQuantOutcome from the stubbed text-encoder pass
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.
Four tests are red on a clean checkout of main, so every branch cut from it inherits them:
Root cause
#8165 ("Report the precision actually in use, and refuse an explicit one we cannot honor", merged 01:15) changed two things: a declined EXPLICIT precision now refuses the load instead of falling back silently, and
quantize_text_encodersreturns aTEQuantOutcomethe loader reads.modeoff rather than a bare mode string.Two squash merges that landed after it carried branches cut before it, so main got combinations neither PR ever ran:
test_saved_image_metadata_precision_contract.pywhole, pinned against a tree where a declined explicit precision fell back silently and where the load route had noassert_precision_availablegate.test_load_refines_component_placement_after_text_encoder_quantization, whose stubbed text-encoder pass returns a bareNone. The loader then doeste_quant = te_outcome.modeand raisesAttributeError: 'NoneType' object has no attribute 'mode'.Test side or product side?
Test side, and the two symptoms were checked separately.
AttributeError: 'NoneType' object has no attribute 'mode'atdiffusion.py:3113looks like a live crash users could hit, so it is the one worth being sure about.quantize_text_encodersis annotated-> TEQuantOutcomeand every one of its seven return statements constructs one; there is no barereturnand no path that falls off the end. Nothing in production wraps or rebinds it, andvideo.py:1562reads.modeoff the same call with no guard for the same reason. The only object that ever reaches line 3113 asNoneis the stub a test monkeypatches in. Aif te_outcome is Noneguard would be unreachable code that also weakens the return contract the outcome type exists to state.AttributeError: '_EngagedBackend' object has no attribute 'assert_precision_available'is the same shape. The route only makes that call underpending_name == ENGINE_DIFFUSERS, andengine_for(ENGINE_DIFFUSERS)returnsget_diffusion_backend(), i.e.DiffusionBackend, which defines the method atdiffusion.py:917. Reaching forgetattr(backend, "assert_precision_available", None)there would be strictly worse than the status quo: it would turn a loud failure into a silently skipped fail-closed gate.So no production code changes and no regression test, because there is no product behaviour change to regress. #8165's refusal is the newer intent and the tests simply encode the older one.
Changes
UNSLOTH_DIFFUSION_ALLOW_PRECISION_FALLBACKin the declined-request contract. That test is about what the recipe records once a fallback is allowed, so it has to ask for the build it is describing, the same waytest_diffusion_routes.py,test_diffusion_backend.py,test_video_routes.pyandtest_video_backend.pywere already adapted for Report the precision actually in use, and refuse an explicit one we cannot honor #8165offfrom anexplicitsource, andgenerate()still must not echo the declined request_EngagedBackendtheassert_precision_availablegate the route now calls, matching the fake intest_diffusion_routes.pyTEQuantOutcome(None)from the stubbed text-encoder pass, which preserves the stub's meaning (the encoders stayed dense) in the shape the function now returnsVerification
Before, on a clean detached checkout of
c7ffee7bc: 4 failed, 233 passed.After:
test_saved_image_metadata_precision_contract.py,test_diffusion_backend.py,test_diffusion_routes.pyandtest_diffusion_precision.pytogether are 347 passed, 0 failed. Both runs withpython3 -Bon a cleared__pycache__. Ruff linter and the pinned kwargs formatter are clean.Relationship to #8254
#8254 proposed this same Studio fix first, and the two Studio files here are its approach, reviewed on their merits rather than copied. This PR exists only because #8254's head branch lives on the org repo, so I cannot push to it, and because #8254 additionally carries a change to
tests/test_python39_compatibility.pythat is now obsolete: that floor red was fixed by the merged #8252, and the change conflicts with main as it stands. #8254 is left open for its author to close.