Skip to content

Commit aa200f7

Browse files
committed
Move auxiliary ctx functions to sdtype_adapter.cpp
1 parent a994812 commit aa200f7

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

otherarch/sdcpp/sdtype_adapter.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,27 @@ static bool sd_is_quiet = false;
134134
static std::string sdmodelfilename = "";
135135
static bool photomaker_enabled = false;
136136

137+
static void set_sd_vae_tiling(sd_ctx_t* ctx, bool tiling)
138+
{
139+
ctx->sd->vae_tiling = tiling;
140+
}
141+
142+
static int get_loaded_sd_version(sd_ctx_t* ctx)
143+
{
144+
return ctx->sd->version;
145+
}
146+
147+
static bool loaded_model_is_chroma(sd_ctx_t* ctx)
148+
{
149+
if (ctx != nullptr && ctx->sd != nullptr) {
150+
auto maybe_flux = std::dynamic_pointer_cast<FluxModel>(ctx->sd->diffusion_model);
151+
if (maybe_flux != nullptr) {
152+
return maybe_flux->flux.flux_params.is_chroma;
153+
}
154+
}
155+
return false;
156+
}
157+
137158
bool sdtype_load_model(const sd_load_model_inputs inputs) {
138159
sd_is_quiet = inputs.quiet;
139160
set_sd_quiet(sd_is_quiet);
@@ -485,7 +506,7 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
485506
auto loadedsdver = get_loaded_sd_version(sd_ctx);
486507
if (loadedsdver == SDVersion::VERSION_FLUX)
487508
{
488-
if (!sd_loaded_chroma()) {
509+
if (!loaded_model_is_chroma(sd_ctx)) {
489510
sd_params->cfg_scale = 1; //non chroma clamp cfg scale
490511
}
491512
if (sampler == "euler a" || sampler == "k_euler_a" || sampler == "euler_a") {
@@ -667,7 +688,7 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
667688
}
668689

669690
std::vector<sd_image_t> kontext_imgs;
670-
if(extra_image_data.size()>0 && loadedsdver==SDVersion::VERSION_FLUX && !sd_loaded_chroma())
691+
if(extra_image_data.size()>0 && loadedsdver==SDVersion::VERSION_FLUX && !loaded_model_is_chroma(sd_ctx))
671692
{
672693
for(int i=0;i<extra_image_data.size();++i)
673694
{

otherarch/sdcpp/stable-diffusion.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
// #define STB_IMAGE_WRITE_STATIC
2828
// #include "stb_image_write.h"
2929

30-
static bool is_loaded_chroma = false;
31-
3230
const char* model_version_to_str[] = {
3331
"SD 1.x",
3432
"SD 1.x Inpaint",
@@ -191,7 +189,6 @@ class StableDiffusionGGML {
191189

192190
init_backend();
193191

194-
is_loaded_chroma = false;
195192
std::string taesd_path_fixed = taesd_path;
196193

197194
ModelLoader model_loader;
@@ -393,7 +390,6 @@ class StableDiffusionGGML {
393390
for (auto pair : model_loader.tensor_storages_types) {
394391
if (pair.first.find("distilled_guidance_layer.in_proj.weight") != std::string::npos) {
395392
is_chroma = true;
396-
is_loaded_chroma = true;
397393
break;
398394
}
399395
}
@@ -1702,22 +1698,6 @@ void free_sd_ctx(sd_ctx_t* sd_ctx) {
17021698
free(sd_ctx);
17031699
}
17041700

1705-
void set_sd_vae_tiling(sd_ctx_t* ctx, bool tiling)
1706-
{
1707-
ctx->sd->vae_tiling = tiling;
1708-
}
1709-
1710-
int get_loaded_sd_version(sd_ctx_t* ctx)
1711-
{
1712-
return ctx->sd->version;
1713-
}
1714-
1715-
//kcpp hack to check if chroma
1716-
bool sd_loaded_chroma()
1717-
{
1718-
return is_loaded_chroma;
1719-
}
1720-
17211701
sd_image_t* generate_image_internal(sd_ctx_t* sd_ctx,
17221702
struct ggml_context* work_ctx,
17231703
ggml_tensor* init_latent,

0 commit comments

Comments
 (0)