mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-11-12 03:49:09 +00:00
feat: add Ming-Image Design support (#2063)
This commit is contained in:
1 parent
61a83b85cc
commit
f8890b9db3
16 files changed
+602
-41
No files matched your search
@@ -106,6 +106,7 @@ const char* model_version_to_str[] = {
|
||||
"LLaDA-Image",
|
||||
"ESRGAN",
|
||||
"PixArt",
|
||||
"Ming-Image",
|
||||
};
|
||||
|
||||
static_assert(VERSION_COUNT == sizeof(model_version_to_str) / sizeof(model_version_to_str[0]),
|
||||
@@ -1210,6 +1211,11 @@ bool StableDiffusionGGML::validate_and_load_runners() {
|
||||
LOG_VERBOSE("validating model metadata");
|
||||
|
||||
std::set<std::string> ignore_tensors;
|
||||
if (version == VERSION_MING_IMAGE) {
|
||||
ignore_tensors.insert("text_encoders.llm.vision.");
|
||||
ignore_tensors.insert("text_encoders.llm.linear_proj.");
|
||||
ignore_tensors.insert("text_encoders.llm.backbone.lm_head.");
|
||||
}
|
||||
if (use_tae && !tae_preview_only) {
|
||||
ignore_tensors.insert("first_stage_model.");
|
||||
}
|
||||
@@ -1370,6 +1376,7 @@ bool StableDiffusionGGML::build_denoiser() {
|
||||
sd_version_is_anima(version) ||
|
||||
sd_version_is_ernie_image(version) ||
|
||||
sd_version_is_z_image(version) ||
|
||||
version == VERSION_MING_IMAGE ||
|
||||
sd_version_is_llada_image(version) ||
|
||||
sd_version_is_boogu_image(version) ||
|
||||
sd_version_is_pid(version) ||
|
||||
@@ -1391,6 +1398,8 @@ bool StableDiffusionGGML::build_denoiser() {
|
||||
default_flow_shift = 3.16f;
|
||||
} else if (sd_version_is_mage_flow(version)) {
|
||||
default_flow_shift = 6.f;
|
||||
} else if (version == VERSION_MING_IMAGE) {
|
||||
default_flow_shift = INFINITY;
|
||||
} else if (sd_version_is_llada_image(version)) {
|
||||
default_flow_shift = 1.0f; // unused: LLADA_IMAGE_SCHEDULER builds a fixed grid
|
||||
} else {
|
||||
@@ -1451,6 +1460,8 @@ bool StableDiffusionGGML::build_denoiser() {
|
||||
} else if (sd_version_is_minimax_h3(version)) {
|
||||
LOG_INFO("running in MiniMax H3 AV FLOW mode");
|
||||
denoiser = std::make_shared<H3AVFlowDenoiser>(default_flow_shift, 3.f, get_latent_channel());
|
||||
} else if (version == VERSION_MING_IMAGE) {
|
||||
denoiser = std::make_shared<MingImageFlowDenoiser>();
|
||||
} else {
|
||||
LOG_INFO("running in FLOW mode");
|
||||
denoiser = std::make_shared<DiscreteFlowDenoiser>();
|
||||
@@ -2161,7 +2172,7 @@ std::vector<float> StableDiffusionGGML::prepare_sample_timesteps(float sigma,
|
||||
if (version == VERSION_HIDREAM_O1) {
|
||||
return std::vector<float>{1.0f - (t / static_cast<float>(TIMESTEPS))};
|
||||
}
|
||||
if (sd_version_is_z_image(version) || sd_version_is_ideogram4(version)) {
|
||||
if (sd_version_is_z_image(version) || sd_version_is_ideogram4(version) || version == VERSION_MING_IMAGE) {
|
||||
return std::vector<float>{1000.f - t};
|
||||
}
|
||||
return std::vector<float>{t};
|
||||
@@ -2514,6 +2525,9 @@ sd::Tensor<float> StableDiffusionGGML::sample(const std::shared_ptr<DiffusionMod
|
||||
condition.c_token_types.empty() ? nullptr : &condition.c_token_types,
|
||||
condition.c_vinput_mask.empty() ? nullptr : &condition.c_vinput_mask,
|
||||
condition.c_image_embeds.empty() ? nullptr : &condition.c_image_embeds};
|
||||
} else if (version == VERSION_MING_IMAGE) {
|
||||
diffusion_params.extra = MingImageDiffusionExtra{
|
||||
condition.extra_c_crossattns.empty() ? nullptr : &condition.extra_c_crossattns[0]};
|
||||
} else if (sd_version_is_llada_image(version)) {
|
||||
diffusion_params.extra = LLaDAImageDiffusionExtra{
|
||||
condition.extra_c_crossattns.empty() ? nullptr : &condition.extra_c_crossattns[0]};
|
||||
@@ -2748,7 +2762,7 @@ int StableDiffusionGGML::get_diffusion_model_down_factor() {
|
||||
if (sd_version_is_dit(version)) {
|
||||
if (sd_version_is_sensenova_u1(version)) {
|
||||
down_factor = 32;
|
||||
} else if (version == VERSION_QWEN_IMAGE_2_1 || sd_version_is_wan(version) || sd_version_is_lingbot_video(version) || sd_version_is_minimax_h3(version) || sd_version_is_pixart(version)) {
|
||||
} else if (version == VERSION_QWEN_IMAGE_2_1 || version == VERSION_MING_IMAGE || sd_version_is_wan(version) || sd_version_is_lingbot_video(version) || sd_version_is_minimax_h3(version) || sd_version_is_pixart(version)) {
|
||||
down_factor = 2;
|
||||
} else {
|
||||
down_factor = 1;
|
||||
@@ -2796,7 +2810,7 @@ int StableDiffusionGGML::get_latent_channel() {
|
||||
}
|
||||
|
||||
int StableDiffusionGGML::get_image_channels() const {
|
||||
return version == VERSION_QWEN_IMAGE_LAYERED || version == VERSION_QWEN_IMAGE_2_1 ? 4 : 3;
|
||||
return version == VERSION_QWEN_IMAGE_LAYERED || version == VERSION_QWEN_IMAGE_2_1 || version == VERSION_MING_IMAGE ? 4 : 3;
|
||||
}
|
||||
|
||||
int StableDiffusionGGML::get_image_seq_len(int h, int w) {
|
||||
|
||||
@@ -465,6 +465,11 @@ namespace sd::pipeline {
|
||||
// states with a zeroed prompt mask, so no extra text encode is needed.
|
||||
uncond.c_crossattn = cond.c_crossattn;
|
||||
uncond.c_vector = sd::Tensor<float>::zeros_like(cond.c_vector);
|
||||
} else if (sd->version == VERSION_MING_IMAGE) {
|
||||
uncond.c_crossattn = sd::Tensor<float>::zeros_like(cond.c_crossattn);
|
||||
for (const auto& extra : cond.extra_c_crossattns) {
|
||||
uncond.extra_c_crossattns.push_back(sd::Tensor<float>::zeros_like(extra));
|
||||
}
|
||||
} else if (sd_version_is_sensenova_u1(sd->version)) {
|
||||
auto* sensenova_conditioner = static_cast<SenseNovaU1Conditioner*>(sd->cond_stage_model.get());
|
||||
uncond = sensenova_conditioner->get_unconditional_condition(request->negative_prompt);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "model/diffusion/llada_image.hpp"
|
||||
#include "model/diffusion/ltxv.hpp"
|
||||
#include "model/diffusion/mage_flow.hpp"
|
||||
#include "model/diffusion/ming_image.hpp"
|
||||
#include "model/diffusion/minimax_h3.hpp"
|
||||
#include "model/diffusion/minit2i.hpp"
|
||||
#include "model/diffusion/mmdit.hpp"
|
||||
@@ -374,6 +375,11 @@ namespace sd::model_builders {
|
||||
tensor_storage_map,
|
||||
"model.diffusion_model",
|
||||
weight_manager);
|
||||
} else if (version == VERSION_MING_IMAGE) {
|
||||
result.conditioner = std::make_shared<MingImageEmbedder>(ctx.backends.runtime_backend(SDBackendModule::TE),
|
||||
tensor_storage_map, weight_manager, tokenizers);
|
||||
result.diffusion = std::make_shared<MingImage::MingImageRunner>(ctx.backends.runtime_backend(SDBackendModule::DIFFUSION),
|
||||
tensor_storage_map, "model.diffusion_model", weight_manager);
|
||||
} else if (sd_version_is_z_image(version)) {
|
||||
result.conditioner = std::make_shared<LLMEmbedder>(ctx.backends.runtime_backend(SDBackendModule::TE),
|
||||
tensor_storage_map,
|
||||
|
||||
Reference in new issue
Block a user