peft icon indicating copy to clipboard operation
peft copied to clipboard

Adding support for Conv1d

Open EskildAndersen opened this issue 9 months ago • 4 comments

Feature request

Can you add support for nn.Conv1d in dora? Like this issue did for LoRA: https://github.com/huggingface/peft/issues/2241.

It would be very valuable my masters thesis.

Motivation

Yes I want to use DoRA along with LoRA

Your contribution

Maybe

EskildAndersen avatar Mar 21 '25 08:03 EskildAndersen

Hi, thanks for taking an interest in Conv1d support for DoRA.

We're currently refactoring how LoRA variations such as DoRA are implemented (https://github.com/huggingface/peft/pull/2443). Once this is done we can think about adding support for Conv1d.

Maybe you're interested in providing an implementation?

githubnemo avatar Mar 21 '25 16:03 githubnemo

#2443 is now merged. With the new abstraction in place, it should be easier than before to add support for nn.Conv1d. Are you interested in taking this @EskildAndersen?

githubnemo avatar Apr 01 '25 12:04 githubnemo

It should just be adding :

class DoraConv1dLayer(_DoraConvNdLayer): def __init__(self, fan_in_fan_out): super().__init__(fan_in_fan_out) self.conv_fn = F.conv1d

to dora.py and alter

if weight.data.ndim >= 3: lora_weight = torch.mm(lora_B.flatten(start_dim=1), lora_A.flatten(start_dim=1)) lora_weight = lora_weight.reshape(weight.shape) else: lora_weight = lora_B @ lora_A

so that >= is 3 instaed of 4, since Conv1d weights are 3D: [out_channels, in_channels, kernel_size]. Lastly in layer.py we should not raise notimplemented error but the new DoraConv1dLayer:

`class Conv1d(_ConvNd): # Lora implemented in a conv1d layer def init(self, *args, **kwargs): super().init(*args, **kwargs) if not self._kernel_dim == 3: raise ValueError(f"Conv1d layer kernel must have 3 dimensions, not {self._kernel_dim}") self.conv_fn = F.conv1d

def _get_dora_layer_class(self):
    return DoraConv1dLayer

`

EskildAndersen avatar Apr 21 '25 09:04 EskildAndersen

@EskildAndersen I think it's easiest for us to review your proposed changes if you create a draft PR and commit your changes. Could you please do that?

BenjaminBossan avatar Apr 22 '25 13:04 BenjaminBossan

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[bot] avatar May 16 '25 15:05 github-actions[bot]

This should be done with https://github.com/huggingface/peft/pull/2531. Closing. Thanks!

githubnemo avatar May 21 '25 22:05 githubnemo