Fix partial-load device recovery across CLIP, T5, and Qwen text encoders#9034
Merged
lstein merged 1 commit intoinvoke-ai:mainfrom Apr 10, 2026
Merged
Conversation
d081450 to
7832aee
Compare
7832aee to
968ef6f
Compare
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
Fix partial-load device recovery across CLIP, T5, and Qwen text encoders.
This PR broadens the partial-load recovery work in #8959 so interrupted or partially offloaded text encoder runs do not leave later executions with mixed-device state or with inputs sent to the wrong device.
The earlier repair covered Qwen/GLM-specific paths, but other supported text encoder architectures still had similar failure modes. CLIP- and T5-based paths could still rely on
model.deviceor first-parameter device inspection, which is unreliable when a model is partially loaded. The shared loaded-model path could also leak a cache lock if repair failed during__enter__().Related Issues / Discussions
QA Instructions
Run focused backend regression tests:
pytest tests/app/invocations/test_compel.pypytest tests/app/invocations/test_sd3_text_encoder.pypytest tests/backend/flux/modules/test_conditioner.pypytest tests/backend/model_manager/load/test_loaded_model.pypytest tests/app/invocations/test_cogview4_text_encoder.pypytest tests/backend/model_manager/load/model_cache/cached_model/test_repair_required_tensors.pyA practical way to test this is to run a generation with an affected model family like SDXL, SD3, or FLUX under enough VRAM pressure that partial offloading is likely, then cancel the job while it is still running and immediately start another generation with the same model. Before this fix, follow-up runs could fail with "Expected all tensors to be on the same device" because some text encoder tensors were left on CPU while execution resumed on
cuda:0. To make the reproduction more reliable, cancel several runs back-to-back or queue the next run immediately after stopping the first. After this fix, the next run should recover cleanly without mixed-device text encoder errors.Merge Plan
Checklist
What's Newcopy (if doing a release after this PR)