Support lora.down and lora.up factor suffixes
This commit is contained in:
@@ -15,7 +15,7 @@ from .quantization_guard import inspect_low_bit_input
|
||||
from .uel_io import atomic_uel_writer
|
||||
|
||||
_FACTOR_RE = re.compile(
|
||||
r"^(?P<module>.+)\.lora_(?P<factor>[AB])(?:\.default)?\.weight$"
|
||||
r"^(?P<module>.+)\.(?:lora_(?P<factor_ab>[AB])|lora\.(?P<factor_word>down|up))(?:\.default)?\.weight$"
|
||||
)
|
||||
_BLOCK_RE = re.compile(r"^transformer_blocks\.(?P<index>\d+)\.(?P<tail>.+)$")
|
||||
_REFINER_RE = re.compile(r"^token_refiner\.refiner_blocks\.(?P<index>\d+)\.(?P<tail>.+)$")
|
||||
@@ -93,7 +93,9 @@ def _build_plan(keys: list[str]) -> list[_ConversionUnit]:
|
||||
f"Input is not a compatible MiniMax H3 Diffusers PEFT LoRA; unsupported key: {key}"
|
||||
)
|
||||
mod = match.group("module")
|
||||
factor = match.group("factor")
|
||||
factor = match.group("factor_ab") or (
|
||||
"A" if match.group("factor_word") == "down" else "B"
|
||||
)
|
||||
pair = factors.setdefault(mod, {})
|
||||
if factor in pair:
|
||||
raise ValueError(f"Duplicate LoRA factor for: {mod}")
|
||||
|
||||
@@ -176,3 +176,29 @@ def test_node_schema_and_execution_contract(converter, monkeypatch, tmp_path):
|
||||
assert result.args[0] == "sub/converted_h3.safetensors"
|
||||
assert "MiniMax H3 Diffusers LoRA conversion complete" in result.args[1]
|
||||
assert (loras_dir / "sub" / "converted_h3.safetensors").is_file()
|
||||
|
||||
|
||||
def test_lora_down_up_suffixes_supported(converter, tmp_path):
|
||||
source = tmp_path / "source_down_up.safetensors"
|
||||
output = tmp_path / "output_down_up.safetensors"
|
||||
|
||||
original = _make_source_tensors("transformer_blocks.0")
|
||||
# Replace .lora_A/.lora_B with .lora.down/.lora.up on attention layers (DMAD format)
|
||||
modified = {}
|
||||
for k, v in original.items():
|
||||
if ".attn." in k:
|
||||
k = k.replace(".lora_A.default.weight", ".lora.down.weight")
|
||||
k = k.replace(".lora_B.default.weight", ".lora.up.weight")
|
||||
else:
|
||||
k = k.replace(".default.weight", ".weight")
|
||||
modified[k] = v
|
||||
|
||||
save_file(modified, str(source))
|
||||
report = converter.convert_minimax_h3_diffusers_lora(str(source), str(output))
|
||||
assert "MiniMax H3 Diffusers LoRA conversion complete" in report
|
||||
converted = load_file(str(output))
|
||||
|
||||
assert "diffusion_model.blocks.0.attn.qkv_proj.lora_A.weight" in converted
|
||||
assert "diffusion_model.blocks.0.attn.qkv_proj.lora_B.weight" in converted
|
||||
assert "diffusion_model.blocks.0.mlp.fc1.lora_A.weight" in converted
|
||||
assert "diffusion_model.blocks.0.mlp.fc1.lora_B.weight" in converted
|
||||
|
||||
Reference in New Issue
Block a user