From a0f0097e52adaa8e6b0c49b418ea74c4d16c67a0 Mon Sep 17 00:00:00 2001 From: CalamitousFelicitousness Date: Tue, 15 Sep 2026 03:52:04 +0100 Subject: [PATCH] refactor(lora): make the fused chunk slicer public The fidelity CLI slices fused saves the way try_load_lora does. --- modules/lora/native_adapter.py | 4 ++-- test/test-minimax-native-adapters.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/lora/native_adapter.py b/modules/lora/native_adapter.py index 01c130c95..42810913f 100644 --- a/modules/lora/native_adapter.py +++ b/modules/lora/native_adapter.py @@ -525,7 +525,7 @@ def slice_chunk_rows(t, chunk: ChunkSpec): return t.contiguous() -def _slice_lora_chunk(w, chunk: ChunkSpec): +def slice_lora_chunk(w, chunk: ChunkSpec): """Return a shallow copy of ``w`` with ``lora_up.weight`` sliced per ``chunk``; a dense bias follows a pure reorder.""" out = dict(w) out["lora_up.weight"] = slice_chunk_rows(w["lora_up.weight"], chunk) @@ -640,7 +640,7 @@ def try_load_lora(name, network_on_disk, lora_scale, *, skipped += 1 continue fused_out = w["lora_up.weight"].shape[0] - target_w = _slice_lora_chunk(w, chunk) + target_w = slice_lora_chunk(w, chunk) target_w = slice_dora_scale(target_w, chunk, fused_out) if target_w is None: log.warning(f'Network load: type=LoRA name="{name}" arch={arch_name} key={network_key} per-input DoRA on fused target skipped (unsupported)') diff --git a/test/test-minimax-native-adapters.py b/test/test-minimax-native-adapters.py index 8b375f239..81e293fa5 100644 --- a/test/test-minimax-native-adapters.py +++ b/test/test-minimax-native-adapters.py @@ -370,7 +370,7 @@ def native_mapping(state_dict, network_alpha=None): if 'lora_down.weight' not in w or 'lora_up.weight' not in w: continue for path, chunk in native_adapter.resolve_group_targets(M.resolve_targets, prefix, base): - target = native_adapter._slice_lora_chunk(w, chunk) if chunk is not None else w # pylint: disable=protected-access + target = native_adapter.slice_lora_chunk(w, chunk) if chunk is not None else w alpha = network_alpha if 'alpha' not in target else float(target['alpha']) scale = 1.0 if alpha is None else alpha / target['lora_down.weight'].shape[0] out[path] = (target['lora_down.weight'], target['lora_up.weight'], scale)