Skip to content

fix(pvera): use _cast_input_dtype in forward instead of raw .to()#3208

Open
Chessing234 wants to merge 1 commit into
huggingface:mainfrom
Chessing234:fix/pvera-forward-cast-input-dtype
Open

fix(pvera): use _cast_input_dtype in forward instead of raw .to()#3208
Chessing234 wants to merge 1 commit into
huggingface:mainfrom
Chessing234:fix/pvera-forward-cast-input-dtype

Conversation

@Chessing234
Copy link
Copy Markdown
Contributor

Bug

Linear.forward in src/peft/tuners/pvera/layer.py casts the input tensor with x = x.to(lambda_d.dtype). This bypasses the disable_lora_input_dtype_casting context manager provided by BaseTunerLayer, which is intended to let callers suppress dtype casting during specific operations (e.g. AMP, mixed-precision inference).

Root cause

BaseTunerLayer._cast_input_dtype checks self._disable_lora_input_dtype_casting and is a no-op when the context manager is active. A bare .to(dtype) call has no such guard.

Fix

Replace the raw cast with the inherited helper:

# before
x = x.to(lambda_d.dtype)
# after
x = self._cast_input_dtype(x, lambda_d.dtype)

This is the same pattern already applied to vera (#3172), poly (#3177), and fourierft (#3170); pvera was the only tuner that still used the raw .to() call.

@BenjaminBossan
Copy link
Copy Markdown
Member

@Chessing234 Could you please apply all changes of this type in a single PR instead of opening one for each PEFT method individually?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants