Fix autocast_adapter_dtype=False for quantized models #2891
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.
What does this PR do?
Fixes the issue where
autocast_adapter_dtype=Falsewas being ignored when using quantized models with BitsAndBytes.Fixes #2889
Problem
When a model is quantized using BitsAndBytes (e.g., 4-bit quantization), LoRA adapters were always initialized with
float32dtype, even when:autocast_adapter_dtype=Falsewas explicitly specifiedfloat16This caused unexpected behavior and potential performance/memory issues.
Solution
Added a
_get_weight_dtype()helper method to theLoraLayerclass that:compute_dtypeattribute (present in BitsAndBytes quantized layers)weight.dtypefor regular layerslora_Aandlora_BLinear Layers inupdate_layer()Testing
✅ Verified the fix works correctly with custom test script:
compute_dtype=float16) -> LoRA params arefloat16dtype=float16) -> LoRA params arefloat16autocast_adapter_dtype=True) still works as expected✅ Ran 131 LoRA config tests locally - all passed