Skip to content

FIX get_delta_weight for pointwise Conv3d layers in LoRA and HiRA - #3777

Merged
BenjaminBossan merged 1 commit into
huggingface:mainfrom
Nicholas022400701:fix-conv3d-pointwise-delta-weight
Sep 21, 2026
Merged

BenjaminBossan merged 1 commit into
huggingface:mainfrom
Nicholas022400701:fix-conv3d-pointwise-delta-weight

Conversation

@Nicholas022400701

Copy link
Copy Markdown
Contributor

Resolves #3768

_ConvNd.get_delta_weight in LoRA and HiRA takes the conv2d 1x1 shortcut when weight.size()[2:4] == (1, 1). That is also true for a Conv3d weight with kernel_size=1 or (1, 1, k), the squeeze(3).squeeze(2) in the shortcut then leaves the kernel dim in place and the matmul fails. For LoRA this breaks merge_adapter(), merge_and_unload() and add_weighted_adapter(), HiRA fails already in forward because it builds the forward pass from get_delta_weight.

The check now compares the whole kernel shape, weight.shape[2:] == (1, 1), so only a 4D 1x1 weight takes the shortcut and Conv3d layers go through the existing conv_fn path, which handles them correctly. Nothing changes for layers that worked before.

Tests: a pointwise Conv3d1x1 model is added to TEST_CASES in tests/test_custom_models.py for LoRA, LoRA with DoRA and HiRA. On main 45 of its 168 tests fail (all merge related tests for LoRA, the forward tests for HiRA), with this change 162 pass and 6 are skipped (the usual bf16 skips). pytest tests/test_custom_models.py -k "1x1 or Conv3d": 907 passed, 47 skipped. make style clean with ruff 0.16.4.

AI disclosure: I used an AI coding agent to help write this patch, the tests and this description. I have read the change and the tests myself and I will answer review comments personally.

Copilot AI lite review requested due to automatic review settings September 21, 2026 10:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@BenjaminBossan BenjaminBossan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this issue and adding a new test case for this, LGTM.

@BenjaminBossan
BenjaminBossan merged commit 63dfa6e into huggingface:main Sep 21, 2026
10 checks passed
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.

LoRA and HiRA get_delta_weight take the conv2d 1x1 shortcut for Conv3d layers with kernel_size 1 and crash

4 participants