Skip to content

Use _cast_input_dtype in vera Linear.forward#3172

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

Use _cast_input_dtype in vera Linear.forward#3172
Chessing234 wants to merge 1 commit into
huggingface:mainfrom
Chessing234:fix/vera-forward-cast-input-dtype

Conversation

@Chessing234
Copy link
Copy Markdown
Contributor

Bug

Linear.forward in src/peft/tuners/vera/layer.py:283 casts the input to the adapter's dtype with a raw x.to(lambda_d.dtype):

dropout = self.vera_dropout[active_adapter]
x = x.to(lambda_d.dtype)
result = result + lambda_b * F.linear(lambda_d * F.linear(dropout(x), sliced_A), sliced_B)

This bypasses BaseTunerLayer._cast_input_dtype, which is the method that consults cast_input_dtype_enabled (toggled by the peft.helpers.disable_lora_input_dtype_casting context manager introduced in #2353 and generalized to non-LoRA tuners in #2433).

Root cause

#2433 consolidated dtype handling across additive tuners onto self._cast_input_dtype. Every comparable tuner's forward uses the helper:

  • lora/layer.py:967x = self._cast_input_dtype(x, lora_A.weight.dtype)
  • fourierft/layer.py:183 (after Use _cast_input_dtype in FourierFTLinear.forward #3170)
  • waveft/layer.py:283x = self._cast_input_dtype(x, delta_w.dtype)
  • psoft/layer.py:447x_cast = self._cast_input_dtype(x, A.dtype)
  • hra/layer.py:260, 445x = self._cast_input_dtype(x, new_weight.dtype)

VeRA was missed in that sweep, so toggling disable_lora_input_dtype_casting silently has no effect on VeRA layers — the cast still happens unconditionally.

Fix

Route the cast through self._cast_input_dtype to match the established pattern. Behavior is identical when the context manager is not used (both call x.to(dtype)); the difference is that users can now opt out as documented.

`vera/layer.py` Linear.forward casts the input to the adapter's dtype
with a raw `x.to(lambda_d.dtype)` call, bypassing
`BaseTunerLayer._cast_input_dtype` — the helper that consults
`cast_input_dtype_enabled` (toggled by
`peft.helpers.disable_lora_input_dtype_casting`, introduced in huggingface#2353
and generalized to non-LoRA tuners in huggingface#2433).

Every other additive tuner routes the cast through `self._cast_input_dtype`:

- `lora/layer.py:967` — `x = self._cast_input_dtype(x, lora_A.weight.dtype)`
- `fourierft/layer.py:183` (after huggingface#3170)
- `waveft/layer.py:283` — `x = self._cast_input_dtype(x, delta_w.dtype)`
- `psoft/layer.py:447` — `x_cast = self._cast_input_dtype(x, A.dtype)`
- `hra/layer.py:260,445` — `x = self._cast_input_dtype(x, new_weight.dtype)`

VeRA was missed when huggingface#2433 consolidated that helper. Switch the raw
cast to `self._cast_input_dtype` to match the established pattern so
users can opt out via the documented context manager. Behavior is
unchanged when the context manager isn't used (both code paths call
`x.to(dtype)`).
@github-actions
Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

@github-actions github-actions Bot closed this May 25, 2026
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.

1 participant