mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-08-10 06:07:58 +00:00
Compare commits
3 Commits
e92e86fb11
...
e31a86ce91
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e31a86ce91 | ||
|
|
735a4ef520 | ||
|
|
af92790ffc |
@ -1008,7 +1008,7 @@ ArgOptions SDGenerationParams::get_options() {
|
|||||||
&hires_upscaler},
|
&hires_upscaler},
|
||||||
{"",
|
{"",
|
||||||
"--extra-sample-args",
|
"--extra-sample-args",
|
||||||
"extra sampler/scheduler/guidance args, key=value list. CFG supports guidance_schedule; APG supports apg_eta, apg_momentum, apg_norm_threshold, apg_norm_threshold_smoothing; SLG supports slg_uncond; lcm supports noise_clip_std, noise_scale_start, noise_scale_end; flux supports base_shift, max_shift; ltx2 supports max_shift, base_shift, stretch, terminal; euler_ge supports gamma;; logit_normal supports mu, std, logsnr_min, logsnr_max, resolution_aware",
|
"extra sampler/scheduler/guidance args, key=value list. CFG supports guidance_schedule; APG supports apg_eta, apg_momentum, apg_norm_threshold, apg_norm_threshold_smoothing; SLG supports slg_uncond; lcm supports noise_clip_std, noise_scale_start, noise_scale_end; flux supports base_shift, max_shift; ltx2 supports max_shift, base_shift, stretch, terminal; euler_ge supports gamma; beta scheduler supports alpha, beta; logit_normal supports mu, std, logsnr_min, logsnr_max, resolution_aware",
|
||||||
(int)',',
|
(int)',',
|
||||||
&extra_sample_args},
|
&extra_sample_args},
|
||||||
{"",
|
{"",
|
||||||
|
|||||||
@ -56,7 +56,7 @@ tokenize_photomaker_trigger(FrozenCLIPEmbedderWithCustomWords& clip_conditioner,
|
|||||||
true);
|
true);
|
||||||
std::vector<bool> class_token_mask;
|
std::vector<bool> class_token_mask;
|
||||||
for (int i = 0; i < tokens.size(); i++) {
|
for (int i = 0; i < tokens.size(); i++) {
|
||||||
class_token_mask.push_back(class_idx + 1 <= i && i < class_idx + 1 + trigger_token_count);
|
class_token_mask.push_back(class_idx >= 0 && class_idx + 1 <= i && i < class_idx + 1 + trigger_token_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_tuple(tokens, weights, class_token_mask);
|
return std::make_tuple(tokens, weights, class_token_mask);
|
||||||
|
|||||||
@ -1449,12 +1449,21 @@ std::string convert_tensor_name(std::string name, SDVersion version) {
|
|||||||
{"te2.", "cond_stage_model.1.transformer."},
|
{"te2.", "cond_stage_model.1.transformer."},
|
||||||
{"te1.", "cond_stage_model.transformer."},
|
{"te1.", "cond_stage_model.transformer."},
|
||||||
{"te3.", "text_encoders.t5xxl.transformer."},
|
{"te3.", "text_encoders.t5xxl.transformer."},
|
||||||
|
{"clip_vision.", "cond_stage_model.transformer."},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (sd_version_is_flux(version)) {
|
if (sd_version_is_flux(version)) {
|
||||||
prefix_map["te1."] = "text_encoders.clip_l.transformer.";
|
prefix_map["te1."] = "text_encoders.clip_l.transformer.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sd_version_is_unet(version)) {
|
||||||
|
prefix_map["clip_l."] = "cond_stage_model.transformer.";
|
||||||
|
prefix_map["clip_g."] = "cond_stage_model.1.transformer.";
|
||||||
|
} else {
|
||||||
|
prefix_map["clip_l."] = "text_encoders.clip_l.transformer.";
|
||||||
|
prefix_map["clip_g."] = "text_encoders.clip_g.transformer.";
|
||||||
|
}
|
||||||
|
|
||||||
replace_with_prefix_map(name, prefix_map);
|
replace_with_prefix_map(name, prefix_map);
|
||||||
|
|
||||||
if (sd_version_is_boogu_image(version) || sd_version_is_krea2(version) || sd_version_is_mage_flow(version)) {
|
if (sd_version_is_boogu_image(version) || sd_version_is_krea2(version) || sd_version_is_mage_flow(version)) {
|
||||||
|
|||||||
@ -306,8 +306,33 @@ struct KarrasScheduler : SigmaScheduler {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct BetaScheduler : SigmaScheduler {
|
struct BetaScheduler : SigmaScheduler {
|
||||||
static constexpr double alpha = 0.6;
|
double alpha = 0.6;
|
||||||
static constexpr double beta = 0.6;
|
double beta = 0.6;
|
||||||
|
|
||||||
|
explicit BetaScheduler(const char* extra_sample_args = nullptr) {
|
||||||
|
parse_extra_sample_args(extra_sample_args);
|
||||||
|
LOG_DEBUG("Beta scheduler: alpha=%.4f, beta=%.4f", alpha, beta);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_extra_sample_args(const char* extra_sample_args) {
|
||||||
|
for (const auto& [key, value] : parse_key_value_args(extra_sample_args, "beta scheduler arg")) {
|
||||||
|
if (key == "alpha") {
|
||||||
|
float parsed;
|
||||||
|
if (!parse_strict_float(value, parsed) || parsed <= 0.0) {
|
||||||
|
LOG_WARN("ignoring invalid beta scheduler arg '%s=%s'", key.c_str(), value.c_str());
|
||||||
|
} else {
|
||||||
|
alpha = static_cast<double>(parsed);
|
||||||
|
}
|
||||||
|
} else if (key == "beta") {
|
||||||
|
float parsed;
|
||||||
|
if (!parse_strict_float(value, parsed) || parsed <= 0.0) {
|
||||||
|
LOG_WARN("ignoring invalid beta scheduler arg '%s=%s'", key.c_str(), value.c_str());
|
||||||
|
} else {
|
||||||
|
beta = static_cast<double>(parsed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static double log_beta(double a, double b) {
|
static double log_beta(double a, double b) {
|
||||||
return std::lgamma(a) + std::lgamma(b) - std::lgamma(a + b);
|
return std::lgamma(a) + std::lgamma(b) - std::lgamma(a + b);
|
||||||
@ -1032,7 +1057,7 @@ struct Denoiser {
|
|||||||
break;
|
break;
|
||||||
case BETA_SCHEDULER:
|
case BETA_SCHEDULER:
|
||||||
LOG_INFO("get_sigmas with Beta scheduler");
|
LOG_INFO("get_sigmas with Beta scheduler");
|
||||||
scheduler = std::make_shared<BetaScheduler>();
|
scheduler = std::make_shared<BetaScheduler>(extra_sample_args);
|
||||||
break;
|
break;
|
||||||
case EXPONENTIAL_SCHEDULER:
|
case EXPONENTIAL_SCHEDULER:
|
||||||
LOG_INFO("get_sigmas exponential scheduler");
|
LOG_INFO("get_sigmas exponential scheduler");
|
||||||
|
|||||||
@ -762,28 +762,23 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_unet = sd_version_is_unet(model_loader.get_sd_version());
|
|
||||||
|
|
||||||
if (strlen(SAFE_STR(sd_ctx_params->clip_l_path)) > 0) {
|
if (strlen(SAFE_STR(sd_ctx_params->clip_l_path)) > 0) {
|
||||||
LOG_INFO("loading clip_l from '%s'", sd_ctx_params->clip_l_path);
|
LOG_INFO("loading clip_l from '%s'", sd_ctx_params->clip_l_path);
|
||||||
std::string prefix = is_unet ? "cond_stage_model.transformer." : "text_encoders.clip_l.transformer.";
|
if (!model_loader.init_from_file(sd_ctx_params->clip_l_path, "clip_l.")) {
|
||||||
if (!model_loader.init_from_file(sd_ctx_params->clip_l_path, prefix)) {
|
|
||||||
LOG_WARN("loading clip_l from '%s' failed", sd_ctx_params->clip_l_path);
|
LOG_WARN("loading clip_l from '%s' failed", sd_ctx_params->clip_l_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(SAFE_STR(sd_ctx_params->clip_g_path)) > 0) {
|
if (strlen(SAFE_STR(sd_ctx_params->clip_g_path)) > 0) {
|
||||||
LOG_INFO("loading clip_g from '%s'", sd_ctx_params->clip_g_path);
|
LOG_INFO("loading clip_g from '%s'", sd_ctx_params->clip_g_path);
|
||||||
std::string prefix = is_unet ? "cond_stage_model.1.transformer." : "text_encoders.clip_g.transformer.";
|
if (!model_loader.init_from_file(sd_ctx_params->clip_g_path, "clip_g.")) {
|
||||||
if (!model_loader.init_from_file(sd_ctx_params->clip_g_path, prefix)) {
|
|
||||||
LOG_WARN("loading clip_g from '%s' failed", sd_ctx_params->clip_g_path);
|
LOG_WARN("loading clip_g from '%s' failed", sd_ctx_params->clip_g_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(SAFE_STR(sd_ctx_params->clip_vision_path)) > 0) {
|
if (strlen(SAFE_STR(sd_ctx_params->clip_vision_path)) > 0) {
|
||||||
LOG_INFO("loading clip_vision from '%s'", sd_ctx_params->clip_vision_path);
|
LOG_INFO("loading clip_vision from '%s'", sd_ctx_params->clip_vision_path);
|
||||||
std::string prefix = "cond_stage_model.transformer.";
|
if (!model_loader.init_from_file(sd_ctx_params->clip_vision_path, "clip_vision.")) {
|
||||||
if (!model_loader.init_from_file(sd_ctx_params->clip_vision_path, prefix)) {
|
|
||||||
LOG_WARN("loading clip_vision from '%s' failed", sd_ctx_params->clip_vision_path);
|
LOG_WARN("loading clip_vision from '%s' failed", sd_ctx_params->clip_vision_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user