fix: map Qwen Image 2.1 LoRAs to fused MLP weights (#2057)

This commit is contained in:
leejet 2026-09-25 16:30:34 +08:00 committed by GitHub
parent 5e7b29131e
commit 510bccf330
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -163,6 +163,27 @@ struct LoraModel : public GGMLRunner {
lora_tensors = std::move(new_lora_tensors); lora_tensors = std::move(new_lora_tensors);
} }
std::unordered_map<std::string, ggml_tensor*> new_lora_tensors;
for (const auto& [old_name, tensor] : lora_tensors) {
std::string new_name = old_name;
if (starts_with(old_name, "lora.model.diffusion_model.transformer_blocks.")) {
// Qwen Image 2.1 stores the gate before the projection in fused MLP weights.
for (const auto& suffix : {std::string(".img_mlp.gate_layer.weight."), std::string(".img_mlp.proj.weight.")}) {
size_t pos = old_name.find(suffix);
if (pos == std::string::npos) {
continue;
}
std::string fused_name = old_name.substr(5, pos - 5) + ".img_mlp.gate_up.weight";
if (model_tensor_names.find(fused_name) != model_tensor_names.end()) {
new_name = "lora." + fused_name + (suffix == ".img_mlp.proj.weight." ? ".1." : ".") + old_name.substr(pos + suffix.size());
}
break;
}
}
new_lora_tensors[new_name] = tensor;
}
lora_tensors = std::move(new_lora_tensors);
} }
ggml_tensor* get_lora_weight_diff(const std::string& model_tensor_name, ggml_context* ctx, ggml_backend_t backend) { ggml_tensor* get_lora_weight_diff(const std::string& model_tensor_name, ggml_context* ctx, ggml_backend_t backend) {