Repository navigation
Studio: let peft 0.19 attach a LoRA to torchao int8 / fp8 weights of quantised single files - #17087
Merged
Merged
Conversation
…transformers peft 0.19 sends every torchao weight to TorchaoLoraLinear but requires its requantisation callback, which it only finds on a transformers hf_quantizer. A LoRA on a quantised single file (int8 / fp8 torchao weights) raised a TypeError at injection. peft 0.20 made the callback optional; give 0.19 the same default. UNSLOTH_STUDIO_PEFT_TORCHAO_OPTIONAL_CALLBACK=0 keeps the required keyword.
Codex Review Summary: ✅ CompletedThis 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. |
[skip ci]
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 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
Follow-up to #16711. With peft 0.19.x, loading a plain LoRA onto a quantised single file's int8 / fp8 transformer fails during adapter injection:
Why it fails:
TorchAOBaseTensorweight toTorchaoLoraLinear, and its constructor requires a requantisation callback.hf_quantizer. Studio builds theseInt8Tensor/Float8Tensorweights directly from the file, so the callback is never there.lora.Linear, so it works.src/peft/tuners/lora/torchao.py).Changes
diffusion_torchao_patchesgivesTorchaoLoraLinear.__init__the sameget_apply_tensor_subclass=Nonedefault that peft 0.20 has.__wrapped__.diffusion_lora_quant_merge) does its own dequantise, add and requantise.UNSLOTH_STUDIO_PEFT_TORCHAO_OPTIONAL_CALLBACK=0.Evidence (CPU, Studio's real
_int8_tensor/_fp8_tensorconstructors, diffusersload_lora_adapter)Results for
test_diffusion_lora_quant_merge.py+test_diffusion_peft_torchao_guard.py, torch 2.10 / torchao 0.18 / diffusers 0.42.1:test_a_peft_lora_merges_at_its_alpha_scaleand the new int8 / fp8 injection tests fail with the TypeError aboveThe new head tests also pass on:
The int8 injection test also checks the LoRA output against
base + B @ A x(relative error < 2%, the bf16 path). The fp8 forward is not run on CPU, because torch's CPU_scaled_mmonly takes per-tensor scales.GPU (Kaggle T4 sm75 and Colab L4 sm89; torch 2.10 / peft 0.19.1 / torchao 0.16 / diffusers 0.42.1)
Base and head ran one per T4 in the same kernel, 3 reps each. Setup: an int8 ConvRot layer of 256 x 512 on CUDA, a LoRA loaded through diffusers
load_lora_adapter, then a forward pass checked againstbase + B @ A x.TypeError: ... missing 1 required keyword-only argument: 'get_apply_tensor_subclass'TorchaoLoraLinear, rel. error 1.9e-3TypeErrorTorchaoLoraLinear, rel. error 1.9e-3