refactor(lora): make the fused chunk slicer public

The fidelity CLI slices fused saves the way try_load_lora does.
This commit is contained in:
CalamitousFelicitousness
2026-09-15 03:52:04 +01:00
parent 5860ea9153
commit a0f0097e52
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -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)')
+1 -1
View File
@@ -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)