DoRA convolution dropout path ignores non-zero padding_mode during training
System Info
Reproduced on current main 0b2c727f77df4eca39f9fc102fc389d1a92e2f92 (PEFT 0.21.1.dev0), Windows, Python 3.11.15, PyTorch 2.13.0+cpu, Transformers 5.15.1, Accelerate 1.14.0. No downloaded model or accelerator is required.
Reproduction
DoRA convolution layers ignore non-zero padding_mode when recomputing the base result during training with LoRA dropout. This still occurs after #3758: that fix preserves the attributes of lora_A, but the separate recomputation in _DoraConvNdLayer.forward calls functional convolution without applying the base layer's padding mode.
import torch
from peft import LoraConfig, get_peft_model
torch.set_num_threads(1)
for mode in ("zeros", "reflect", "replicate", "circular"):
torch.manual_seed(0)
base = torch.nn.Sequential(
torch.nn.Conv2d(2, 3, 3, padding=1, padding_mode=mode, bias=False)
).double()
model = get_peft_model(base, LoraConfig(
target_modules=["0"], r=2, lora_alpha=2,
use_dora=True, lora_dropout=0.25,
)).double().train()
layer = model.get_base_model()[0]
# LoRA B is still zero; doubling magnitude makes the DoRA factor 2.
with torch.no_grad():
layer.lora_magnitude_vector["default"].weight.mul_(2)
x = torch.randn(2, 2, 5, 5, dtype=torch.float64)
torch.manual_seed(1)
actual = model(x)
torch.manual_seed(1)
dropped = layer.lora_dropout["default"](x)
expected = layer.base_layer(x) + layer.base_layer(dropped)
print(mode, (actual - expected).abs().max().item())Output:
zeros 0.0
reflect 1.1809359440712968
replicate 1.338801354885296
circular 1.3557117125062048With the zero-initialized LoRA B and magnitude factor 2, the existing DoRA formula reduces to base(x) + base(dropout(x)); both terms should use the configured padding mode. The altered magnitude makes the mismatch visible instead of hiding it behind identity initialization.
Expected behavior
All four errors should be approximately zero. The recomputed bias-free base convolution should preserve the same padding semantics as the original convolution.
A broader CPU check with nonzero adapter weights reproduces this across Conv1d/2d/3d: all nine training + reflect/replicate/circular cases disagree with the reference formula. All fifteen eval or zero-padding controls agree within floating-point tolerance. This is a forward-numerics reproduction, not a measured downstream training-quality result.
Proposed contribution
I would like to implement the fix and regression coverage for Conv1d, Conv2d, and Conv3d together, preserving the existing bias and dropout semantics. I checked the current open PRs and did not find one covering this recomputation path. Could a maintainer confirm the scope and approve me to take this on? I will wait for approval before starting the fix or opening a PR.
Source: huggingface/peft