#3825·peft

OSFLayer.merge() skips check_adapters_to_merge(), double-applies the delta on re-merge

Author: AmirF194Created Sep 27, 2026Updated Sep 28, 2026

System Info

peft main (0.21.1.dev0), torch 2.14.0+cpu, Python 3.12, Linux (CPU-only).

Who can help?

@benjaminbossan

Reproduction

Every merge-capable tuner filters adapter_names through check_adapters_to_merge() before merging (lora, ia3, hra, boft, adalora and others all call it, e.g. src/peft/tuners/lora/layer.py:965). OSFLayer.merge() (src/peft/tuners/osf/layer.py:240, added in #2685) skips that call and merges unconditionally, so calling merge() a second time on an adapter that's already merged applies the delta again instead of warning and no-oping.

python
import torch, torch.nn as nn
from peft import get_peft_model
from peft.tuners.osf.config import OSFConfig

base = nn.Linear(16, 16, bias=False)
orig = base.weight.data.clone()
model = get_peft_model(nn.ModuleDict({"default": base}), OSFConfig(target_modules=["default"], effective_rank=4, init_weights=False))
layer = model.base_model.model["default"]
delta = layer.get_delta_weight("default")

layer.merge()
print("after 1st merge:", layer.merged_adapters)  # ['default'], weight == orig + delta

layer.merge()
print("after 2nd merge:", layer.merged_adapters)  # ['default', 'default']
print((layer.get_base_layer().weight.data - (orig + 2 * delta)).abs().max())  # ~0, delta applied twice

tests/testing_common.py::_test_merge_layers_is_idempotent is the generic test that would normally catch this, but it skips OSFConfig entirely via _skip_if_merging_not_supported (line ~88), with the reason "merge/unmerge are not implemented". That's only true for unmerge (which does warn and no-op); merge is fully implemented and reachable through the public merge_adapter()/merge_and_unload() API, so the one test built for exactly this case silently exempts OSF.

Expected behavior

OSFLayer.merge() should call check_adapters_to_merge() like every other tuner, so a second merge() on an already-merged adapter warns and skips instead of double-applying the weight delta. The test skip reason should also be narrowed to unmerge-only so the idempotency test actually covers OSF's merge path.

I can open a PR for this (add the guard, narrow the test skip) once someone's confirmed the direction.