Use _cast_input_dtype in poly Linear.forward#3177
Open
Chessing234 wants to merge 1 commit intohuggingface:mainfrom
Open
Use _cast_input_dtype in poly Linear.forward#3177Chessing234 wants to merge 1 commit intohuggingface:mainfrom
Chessing234 wants to merge 1 commit intohuggingface:mainfrom
Conversation
The raw x.to(A.dtype) cast bypasses the disable_lora_input_dtype_casting context manager. Switch to the BaseTunerLayer._cast_input_dtype helper so poly respects the same casting controls as other tuners (fourierft, vera, etc.).
Member
|
@Chessing234 Thanks for the PR. Could you please check all PEFT methods for the same pattern and bundle all changes into a single PR instead of submitting one for each PEFT method individually? Thanks. |
This was referenced May 2, 2026
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.
Bug
poly.Linear.forwardcasts the input with a rawx.to(A.dtype)instead ofself._cast_input_dtype(...), bypassing thedisable_lora_input_dtype_castingcontext manager.
Root cause
BaseTunerLayerexposes_cast_input_dtype, which respects the module-levelflag for disabling input dtype casting. Most tuners use that helper, but
poly/layer.pystill uses the raw.to()call.Why the fix is correct
PolyLayerinherits fromBaseTunerLayer, soself._cast_input_dtypeisavailable on the
Linearsubclass.this brings poly in line with those tuners.
performs the same cast).
Change
src/peft/tuners/poly/layer.py:x = x.to(A.dtype)→x = self._cast_input_dtype(x, A.dtype).