Repository navigation
feat: support Diffusers-format MiniMax-H3 LoRAs #2159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1024,6 +1024,24 @@ static std::string convert_ming_image_dit_name(std::string name) { | |
| return name; | ||
| } | ||
|
|
||
| std::string convert_diffusers_dit_to_original_minimax_h3(std::string name) { | ||
| static const std::vector<std::pair<std::string, std::string>> prefix_map = { | ||
| {"transformer_blocks.", "blocks."}, | ||
| {"token_refiner.refiner_blocks.", "token_refiner.blocks."}, | ||
| }; | ||
| static const std::vector<std::pair<std::string, std::string>> name_map = { | ||
| {".attn.to_q.weight", ".attn.qkv_proj.weight"}, | ||
| {".attn.to_k.weight", ".attn.qkv_proj.weight.1"}, | ||
| {".attn.to_v.weight", ".attn.qkv_proj.weight.2"}, | ||
| {".attn.to_out.0.", ".attn.out_proj."}, | ||
| {".ff.net.0.proj.", ".mlp.fc1."}, | ||
| {".ff.net.2.", ".mlp.fc2."}, | ||
| }; | ||
| replace_with_prefix_map(name, prefix_map); | ||
| replace_with_name_map(name, name_map); | ||
| return name; | ||
| } | ||
|
|
||
|
Comment on lines
+1027
to
+1044
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: rg -n -i 'adaln_proj|minimax_h3|norm_out\.linear|final_layer' src | head -80Repository: leejet/stable-diffusion.cpp Length of output: 8798 🏁 Script executed: set -o pipefail
printf '%s\n' '--- candidate files ---'
rg --files src/model | rg -i 'minimax|h3'
printf '%s\n' '--- exact symbols and mappings ---'
rg -n -F --glob '*.{cpp,h,hpp}' -e 'adaln_proj' -e 'norm_out.linear' -e 'convert_diffusers_dit_to_original_minimax_h3' -e 'convert_diffusion_model_name' -e 'tensor_name' -e 'source_version' src/model src/name_conversion.cpp src/name_conversion.h
printf '%s\n' '--- adapter and conversion excerpts ---'
sed -n '1,180p' src/model/adapter/lora.hpp
sed -n '930,1080p' src/name_conversion.cppRepository: leejet/stable-diffusion.cpp Length of output: 25275 🏁 Script executed: set -o pipefail
printf '%s\n' '--- MiniMax-H3 model registration and execution ---'
nl -ba src/model/diffusion/minimax_h3.hpp | sed -n '340,510p'
printf '%s\n' '--- conversion helper definitions and convert_tensor_name ---'
rg -n -F --glob 'src/name_conversion.cpp' -e 'replace_with_prefix_map' -e 'replace_with_name_map' -e 'std::string convert_tensor_name' -e 'convert_diffusion_model_name' -e 'source_version'
nl -ba src/name_conversion.cpp | sed -n '1,90p'
nl -ba src/name_conversion.cpp | sed -n '1530,1750p'
printf '%s\n' '--- LoRA matching, application, and unused reporting ---'
nl -ba src/model/adapter/lora.hpp | sed -n '200,275p'
nl -ba src/model/adapter/lora.hpp | sed -n '550,625p'
nl -ba src/model/adapter/lora.hpp | sed -n '940,1025p'Repository: leejet/stable-diffusion.cpp Length of output: 43148 🏁 Script executed: set -o pipefail
printf '%s\n' '--- AdaLayerNormModulation and MiniMax-H3 owner registration ---'
rg -n -F --glob 'src/model/diffusion/minimax_h3.hpp' -e 'struct AdaLayerNormModulation' -e 'class AdaLayerNormModulation' -e 'blocks["final_layer"]' -e 'register' -e 'tensor_storage_map' -e 'load_tensors'
rg -n -F --glob 'src/model/**/*.hpp' -e 'struct AdaLayerNormModulation' -e 'class AdaLayerNormModulation'
nl -ba src/model/diffusion/minimax_h3.hpp | sed -n '1,150p'
nl -ba src/model/diffusion/minimax_h3.hpp | sed -n '490,760p'
printf '%s\n' '--- conversion tail and unused LoRA reporting ---'
nl -ba src/name_conversion.cpp | sed -n '1710,1810p'
nl -ba src/model/adapter/lora.hpp | sed -n '1018,1075p'Repository: leejet/stable-diffusion.cpp Length of output: 33501 🏁 Script executed: set -o pipefail
printf '%s\n' '--- recursive block naming and modulation declaration ---'
rg -n -F --glob 'src/model/diffusion/model.hpp' -e 'struct GGMLBlock' -e 'init_params' -e 'blocks' -e 'params'
nl -ba src/model/diffusion/model.hpp | sed -n '1,180p'
nl -ba src/model/diffusion/minimax_h3.hpp | sed -n '250,340p'
printf '%s\n' '--- MiniMax-H3 model loading entrypoint ---'
rg -n -F --glob 'src' -e 'MiniMaxH3Transformer3DModel' -e 'VERSION_MINIMAX_H3' -e 'LoraModel' | head -100Repository: leejet/stable-diffusion.cpp Length of output: 14147 🏁 Script executed: set -o pipefail
printf '%s\n' '--- GGMLBlock definition and recursive parameter naming ---'
rg -n -F --glob '*.{h,hpp,cpp}' -e 'struct GGMLBlock' -e 'class GGMLBlock' -e 'GGMLBlock::init_params' -e 'void init_params' src | head -80
printf '%s\n' '--- candidate definition excerpts ---'
for f in $(rg -l -F --glob '*.{h,hpp,cpp}' -e 'struct GGMLBlock' -e 'class GGMLBlock' -e 'GGMLBlock::init_params' src | head -10); do
echo "FILE:$f"
nl -ba "$f" | sed -n '1,240p'
doneRepository: leejet/stable-diffusion.cpp Length of output: 42228 Map the MiniMax-H3 final-layer LoRA target.
Suggested fix {".ff.net.0.proj.", ".mlp.fc1."},
{".ff.net.2.", ".mlp.fc2."},
+ {"norm_out.linear.", "final_layer.adaln_proj.linear."},🤖 Prompt for AI Agents |
||
| std::string convert_diffusion_model_name(std::string name, std::string prefix, SDVersion version) { | ||
| if (sd_version_is_sd1(version) || sd_version_is_sd2(version)) { | ||
| name = convert_diffusers_unet_to_original_sd1(name); | ||
|
|
@@ -1047,6 +1065,8 @@ std::string convert_diffusion_model_name(std::string name, std::string prefix, S | |
| name = convert_diffusers_dit_to_original_krea2(name); | ||
| } else if (sd_version_is_pixart(version)) { | ||
| name = convert_diffusers_dit_to_original_pixart(name); | ||
| } else if (sd_version_is_minimax_h3(version)) { | ||
| name = convert_diffusers_dit_to_original_minimax_h3(name); | ||
| } | ||
| return name; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Reject odd-sized up tensors before splitting them.
If a marked MiniMax-H3 up tensor has an odd
ne[1], either diff path callsggml_ext_chunkand hits its divisibility assertion. The loader permits that shape, and the later compatibility checks cannot prevent the abort. Validate the marked tensor’s output dimension before building either graph. Return an error or skip the incompatible LoRA pair instead of terminating the process.Also applies to: 763-763
🤖 Prompt for AI Agents