Support bare LoRA A/B suffixes without .weight in MiniMax H3 converter

This commit is contained in:
silveroxides
2026-10-31 19:57:42 +01:00
parent 9cda62199c
commit 6bbc566a52
2 changed files with 24 additions and 2 deletions
+2 -2
View File
@@ -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>[AB])|lora\.(?P<factor_word>down|up))(?:\.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>.+)$")
@@ -54,7 +54,7 @@ def _target_module(module: str) -> tuple[str, str | None, bool]:
Returns:
(target_module, qkv_part, is_swiglu_fc1)
"""
clean_mod = module.removeprefix("transformer.")
clean_mod = module.removeprefix("base_model.model.").removeprefix("transformer.")
match = _BLOCK_RE.fullmatch(clean_mod)
if match:
prefix = f"diffusion_model.blocks.{match.group('index')}"
+22
View File
@@ -202,3 +202,25 @@ def test_lora_down_up_suffixes_supported(converter, tmp_path):
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
def test_bare_lora_ab_without_weight_suffix_supported(converter, tmp_path):
source = tmp_path / "source_bare_ab.safetensors"
output = tmp_path / "output_bare_ab.safetensors"
original = _make_source_tensors("token_refiner.refiner_blocks.0")
modified = {
k.replace(".default.weight", ""): v
for k, v in original.items()
}
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.token_refiner.blocks.0.attn.qkv_proj.lora_A.weight" in converted
assert "diffusion_model.token_refiner.blocks.0.attn.qkv_proj.lora_B.weight" in converted
assert "diffusion_model.token_refiner.blocks.0.mlp.fc1.lora_A.weight" in converted
assert "diffusion_model.token_refiner.blocks.0.mlp.fc1.lora_B.weight" in converted