Repository navigation
Studio: keep diffusion LoRA loading working on torchao 0.18 with peft 0.18 - #12494
Merged
Merged
Conversation
Member
Author
|
@codex review |
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. |
|
Codex Review: Didn't find any major issues. Nice work! 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 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
Studio's diffusion and video processes load LoRAs through
pipe.load_lora_weights, which goes through peft's LoRA dispatch table. peft 0.18.1 (Studio's pin inextras-no-deps.txt) runsdispatch_torchaofor every target beforedispatch_default, and that dispatcher doesfrom torchao.quantization import LinearActivationQuantizedTensor. torchao 0.18.0 deleted that class, and_select_torchao_specinstalls 0.18.0 on torch 2.12 and later. So on those installs every diffusion LoRA load raises:#11168 fixed this for
import unsloth(fix_peft_torchao_missing_tensor_subclassinunsloth/import_fixes.py), but the diffusion process deliberately never runsunsloth/__init__, so that fix never reaches it. It surfaced on #12476's Backend CI run (test_guard_holds_through_a_lora_injected_after_install), the first Studio test to inject a real LoRA with peft 0.18.1 and torchao 0.18.0 installed.Reproduced outside Studio with torch 2.12.1+cpu, peft 0.18.1, torchao 0.18.0:
peft.inject_adapter_in_model(LoraConfig(target_modules=["0"]), nn.Sequential(nn.Linear(8, 8)))raises the same ImportError.Change
studio/backend/core/inference/diffusion_torchao_patches.py, which already holds Studio's copy of unsloth's torchao int_mm fix for the same reason:_peft_torchao_tensor_subclassesand_guard_peft_torchao_dispatcherfromunsloth/import_fixes.py. On the removed-class ImportError only, the wrapper redoes the isinstance check against the subclasses torchao still ships, so a plain Linear falls through to peft's ordinary LoRA layer and anAffineQuantizedTensorweight still getsTorchaoLoraLinear. Any other ImportError still raises. Both copies mark their wrapper__unsloth_patched__, so whichever runs second leaves the first alone.install_peft_torchao_dispatch_guard(): patches both bindings (peft.tuners.lora.torchaoandpeft.tuners.lora.model, which imports the function by value) if peft's LoRA module is loaded, otherwise installs a meta path finder that patches it when it is. peft is not imported eagerly.install_torchao_int_mm_patch()calls it first, independent ofUNSLOTH_TORCHAO_INT_MM_FIX. That installer is already called at import bydiffusion.py,video.py,diffusion_transformer_quant.py,diffusion_train_common.pyand the torch warmup.Tests
studio/backend/tests/test_diffusion_peft_torchao_guard.py:unsloth/import_fixes.pyapart from the warning's speaker, so the copies cannot drift;Noneinstead of an ImportError, both peft bindings point at one wrapper, and a second pass is a no-op;AffineQuantizedTensorweight still getsTorchaoLoraLinearwith its kwargs;install_torchao_int_mm_patch()installs the guard even withUNSLOTH_TORCHAO_INT_MM_FIX=0;Sabotage, in a torch 2.12.1 / peft 0.18.1 / torchao 0.18.0 venv:
install_torchao_int_mm_patch_patch_peft_torchao_dispatchersmade a no-opA local slice of
studio/backend/tests -k "torchao or peft or lora or diffusion_patch or prewarm"produces the same failure and error set on main and on this branch, all of them local environment issues unrelated to this change.