From fd724d8be7454807b20b903f5aa686dcb1f66653 Mon Sep 17 00:00:00 2001 From: abhay-codes07 Date: Sun, 12 Jul 2026 17:51:13 +0530 Subject: [PATCH] Fix BOFT adapter silently dropping LoRAs without an alpha key When a BOFT LoRA has no '{key}.alpha' entry, load_lora passes alpha=None. BOFTAdapter.calculate_weight then hit 'if alpha > 0' with alpha=None, raising a TypeError that the broad except in the caller swallowed, so the weight was returned unchanged and the LoRA had no effect. Guard alpha the same way OFTAdapter already does (None means no constraint). --- comfy/weight_adapter/boft.py | 2 ++ .../comfy_test/weight_adapter_boft_test.py | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests-unit/comfy_test/weight_adapter_boft_test.py diff --git a/comfy/weight_adapter/boft.py b/comfy/weight_adapter/boft.py index 02a8dc130..fc2e77464 100644 --- a/comfy/weight_adapter/boft.py +++ b/comfy/weight_adapter/boft.py @@ -60,6 +60,8 @@ class BOFTAdapter(WeightAdapterBase): blocks = v[0] rescale = v[1] alpha = v[2] + if alpha is None: + alpha = 0 dora_scale = v[3] blocks = comfy.model_management.cast_to_device( diff --git a/tests-unit/comfy_test/weight_adapter_boft_test.py b/tests-unit/comfy_test/weight_adapter_boft_test.py new file mode 100644 index 000000000..600badfb3 --- /dev/null +++ b/tests-unit/comfy_test/weight_adapter_boft_test.py @@ -0,0 +1,32 @@ +import torch +from comfy.cli_args import args as cli_args + +if not torch.cuda.is_available(): + cli_args.cpu = True + +from comfy.weight_adapter.boft import BOFTAdapter + + +def _apply(alpha): + torch.manual_seed(0) + blocks = torch.randn(1, 2, 2, 2) * 0.1 + weight = torch.eye(4) + adapter = BOFTAdapter("w", (blocks, None, alpha, None)) + out = adapter.calculate_weight( + weight.clone(), "w", 1.0, 1.0, 0, lambda x: x, + intermediate_dtype=torch.float32, original_weight=None, + ) + return out, weight + + +class TestBOFTAdapter: + def test_applies_when_alpha_missing(self): + # a BOFT LoRA without an ".alpha" key arrives with alpha=None; it must still + # apply the rotation (None means "no constraint"), like the OFT adapter. + out, weight = _apply(None) + assert not torch.equal(out, weight) + + def test_missing_alpha_matches_zero_alpha(self): + out_none, _ = _apply(None) + out_zero, _ = _apply(0) + assert torch.allclose(out_none, out_zero)