Compare commits

..

No commits in common. "10facffd010a2a75b8b2be9a5ff484ab8d495167" and "85e9a129882c7e3a7d037fb6902e3bd68b4b525c" have entirely different histories.

10 changed files with 78 additions and 108 deletions

View File

@ -52,7 +52,6 @@ struct FrozenCLIPEmbedderWithCustomWords : public Conditioner {
std::string trigger_word = "img"; // should be user settable std::string trigger_word = "img"; // should be user settable
std::string embd_dir; std::string embd_dir;
int32_t num_custom_embeddings = 0; int32_t num_custom_embeddings = 0;
int32_t num_custom_embeddings_2 = 0;
std::vector<uint8_t> token_embed_custom; std::vector<uint8_t> token_embed_custom;
std::vector<std::string> readed_embeddings; std::vector<std::string> readed_embeddings;
@ -132,31 +131,18 @@ struct FrozenCLIPEmbedderWithCustomWords : public Conditioner {
params.no_alloc = false; params.no_alloc = false;
struct ggml_context* embd_ctx = ggml_init(params); struct ggml_context* embd_ctx = ggml_init(params);
struct ggml_tensor* embd = NULL; struct ggml_tensor* embd = NULL;
struct ggml_tensor* embd2 = NULL; int64_t hidden_size = text_model->model.hidden_size;
auto on_load = [&](const TensorStorage& tensor_storage, ggml_tensor** dst_tensor) { auto on_load = [&](const TensorStorage& tensor_storage, ggml_tensor** dst_tensor) {
if (tensor_storage.ne[0] != text_model->model.hidden_size) { if (tensor_storage.ne[0] != hidden_size) {
if (text_model2) { LOG_DEBUG("embedding wrong hidden size, got %i, expected %i", tensor_storage.ne[0], hidden_size);
if (tensor_storage.ne[0] == text_model2->model.hidden_size) {
embd2 = ggml_new_tensor_2d(embd_ctx, tensor_storage.type, text_model2->model.hidden_size, tensor_storage.n_dims > 1 ? tensor_storage.ne[1] : 1);
*dst_tensor = embd2;
} else {
LOG_DEBUG("embedding wrong hidden size, got %i, expected %i or %i", tensor_storage.ne[0], text_model->model.hidden_size, text_model2->model.hidden_size);
return false; return false;
} }
} else { embd = ggml_new_tensor_2d(embd_ctx, tensor_storage.type, hidden_size, tensor_storage.n_dims > 1 ? tensor_storage.ne[1] : 1);
LOG_DEBUG("embedding wrong hidden size, got %i, expected %i", tensor_storage.ne[0], text_model->model.hidden_size);
return false;
}
} else {
embd = ggml_new_tensor_2d(embd_ctx, tensor_storage.type, text_model->model.hidden_size, tensor_storage.n_dims > 1 ? tensor_storage.ne[1] : 1);
*dst_tensor = embd; *dst_tensor = embd;
}
return true; return true;
}; };
model_loader.load_tensors(on_load, NULL); model_loader.load_tensors(on_load, NULL);
readed_embeddings.push_back(embd_name); readed_embeddings.push_back(embd_name);
if (embd) {
int64_t hidden_size = text_model->model.hidden_size;
token_embed_custom.resize(token_embed_custom.size() + ggml_nbytes(embd)); token_embed_custom.resize(token_embed_custom.size() + ggml_nbytes(embd));
memcpy((void*)(token_embed_custom.data() + num_custom_embeddings * hidden_size * ggml_type_size(embd->type)), memcpy((void*)(token_embed_custom.data() + num_custom_embeddings * hidden_size * ggml_type_size(embd->type)),
embd->data, embd->data,
@ -167,20 +153,6 @@ struct FrozenCLIPEmbedderWithCustomWords : public Conditioner {
num_custom_embeddings++; num_custom_embeddings++;
} }
LOG_DEBUG("embedding '%s' applied, custom embeddings: %i", embd_name.c_str(), num_custom_embeddings); LOG_DEBUG("embedding '%s' applied, custom embeddings: %i", embd_name.c_str(), num_custom_embeddings);
}
if (embd2) {
int64_t hidden_size = text_model2->model.hidden_size;
token_embed_custom.resize(token_embed_custom.size() + ggml_nbytes(embd2));
memcpy((void*)(token_embed_custom.data() + num_custom_embeddings_2 * hidden_size * ggml_type_size(embd2->type)),
embd2->data,
ggml_nbytes(embd2));
for (int i = 0; i < embd2->ne[1]; i++) {
bpe_tokens.push_back(text_model2->model.vocab_size + num_custom_embeddings_2);
// LOG_DEBUG("new custom token: %i", text_model.vocab_size + num_custom_embeddings);
num_custom_embeddings_2++;
}
LOG_DEBUG("embedding '%s' applied, custom embeddings: %i (text model 2)", embd_name.c_str(), num_custom_embeddings_2);
}
return true; return true;
} }

View File

@ -126,9 +126,9 @@ struct SDParams {
int upscale_repeats = 1; int upscale_repeats = 1;
std::vector<int> skip_layers = {7, 8, 9}; std::vector<int> skip_layers = {7, 8, 9};
float slg_scale = 0.f; float slg_scale = 0.;
float skip_layer_start = 0.01f; float skip_layer_start = 0.01;
float skip_layer_end = 0.2f; float skip_layer_end = 0.2;
}; };
void print_params(SDParams params) { void print_params(SDParams params) {
@ -931,12 +931,12 @@ int main(int argc, const char* argv[]) {
} }
} }
std::vector<uint8_t> default_mask_image_vec(params.width * params.height, 255);
if (params.mask_path != "") { if (params.mask_path != "") {
int c = 0; int c = 0;
mask_image_buffer = stbi_load(params.mask_path.c_str(), &params.width, &params.height, &c, 1); mask_image_buffer = stbi_load(params.mask_path.c_str(), &params.width, &params.height, &c, 1);
} else { } else {
mask_image_buffer = default_mask_image_vec.data(); std::vector<uint8_t> arr(params.width * params.height, 255);
mask_image_buffer = arr.data();
} }
sd_image_t mask_image = {(uint32_t)params.width, sd_image_t mask_image = {(uint32_t)params.width,
(uint32_t)params.height, (uint32_t)params.height,

2
ggml

@ -1 +1 @@
Subproject commit ff9052988b76e137bcf92bb335733933ca196ac0 Subproject commit 6fcbd60bc72ac3f7ad43f78c87e535f2e6206f58

View File

@ -329,21 +329,21 @@ const std::vector<std::vector<float>> GITS_NOISE_1_50 = {
}; };
const std::vector<const std::vector<std::vector<float>>*> GITS_NOISE = { const std::vector<const std::vector<std::vector<float>>*> GITS_NOISE = {
&GITS_NOISE_0_80, { &GITS_NOISE_0_80 },
&GITS_NOISE_0_85, { &GITS_NOISE_0_85 },
&GITS_NOISE_0_90, { &GITS_NOISE_0_90 },
&GITS_NOISE_0_95, { &GITS_NOISE_0_95 },
&GITS_NOISE_1_00, { &GITS_NOISE_1_00 },
&GITS_NOISE_1_05, { &GITS_NOISE_1_05 },
&GITS_NOISE_1_10, { &GITS_NOISE_1_10 },
&GITS_NOISE_1_15, { &GITS_NOISE_1_15 },
&GITS_NOISE_1_20, { &GITS_NOISE_1_20 },
&GITS_NOISE_1_25, { &GITS_NOISE_1_25 },
&GITS_NOISE_1_30, { &GITS_NOISE_1_30 },
&GITS_NOISE_1_35, { &GITS_NOISE_1_35 },
&GITS_NOISE_1_40, { &GITS_NOISE_1_40 },
&GITS_NOISE_1_45, { &GITS_NOISE_1_45 },
&GITS_NOISE_1_50 { &GITS_NOISE_1_50 }
}; };
#endif // GITS_NOISE_INL #endif // GITS_NOISE_INL

View File

@ -1929,6 +1929,9 @@ bool ModelLoader::load_tensors(std::map<std::string, struct ggml_tensor*>& tenso
if (pair.first.find("cond_stage_model.transformer.text_model.encoder.layers.23") != std::string::npos) { if (pair.first.find("cond_stage_model.transformer.text_model.encoder.layers.23") != std::string::npos) {
continue; continue;
} }
if (pair.first.find("alphas_cumprod") != std::string::npos) {
continue;
}
if (pair.first.find("alphas_cumprod") != std::string::npos) { if (pair.first.find("alphas_cumprod") != std::string::npos) {
continue; continue;

View File

@ -14,7 +14,6 @@
#include "ggml.h" #include "ggml.h"
#include "json.hpp" #include "json.hpp"
#include "zip.h" #include "zip.h"
#include "gguf.h"
#define SD_MAX_DIMS 5 #define SD_MAX_DIMS 5

View File

@ -1551,7 +1551,6 @@ sd_image_t* txt2img(sd_ctx_t* sd_ctx,
} }
struct ggml_init_params params; struct ggml_init_params params;
if (sd_version_is_sdxl(sd_ctx->sd->version)) { params.mem_size *= 4; }
params.mem_size = static_cast<size_t>(10 * 1024 * 1024); // 10 MB params.mem_size = static_cast<size_t>(10 * 1024 * 1024); // 10 MB
if (sd_version_is_sd3(sd_ctx->sd->version)) { if (sd_version_is_sd3(sd_ctx->sd->version)) {
params.mem_size *= 3; params.mem_size *= 3;
@ -1807,7 +1806,7 @@ sd_image_t* img2img(sd_ctx_t* sd_ctx,
size_t t2 = ggml_time_ms(); size_t t2 = ggml_time_ms();
LOG_INFO("img2img completed in %.2fs", (t2 - t0) * 1.0f / 1000); LOG_INFO("img2img completed in %.2fs", (t1 - t0) * 1.0f / 1000);
return result_images; return result_images;
} }

View File

@ -92,15 +92,12 @@ enum sd_type_t {
SD_TYPE_F64 = 28, SD_TYPE_F64 = 28,
SD_TYPE_IQ1_M = 29, SD_TYPE_IQ1_M = 29,
SD_TYPE_BF16 = 30, SD_TYPE_BF16 = 30,
// SD_TYPE_Q4_0_4_4 = 31, support has been removed from gguf files SD_TYPE_Q4_0_4_4 = 31,
// SD_TYPE_Q4_0_4_8 = 32, SD_TYPE_Q4_0_4_8 = 32,
// SD_TYPE_Q4_0_8_8 = 33, SD_TYPE_Q4_0_8_8 = 33,
SD_TYPE_TQ1_0 = 34, SD_TYPE_TQ1_0 = 34,
SD_TYPE_TQ2_0 = 35, SD_TYPE_TQ2_0 = 35,
// SD_TYPE_IQ4_NL_4_4 = 36, SD_TYPE_COUNT,
// SD_TYPE_IQ4_NL_4_8 = 37,
// SD_TYPE_IQ4_NL_8_8 = 38,
SD_TYPE_COUNT = 39,
}; };
SD_API const char* sd_type_name(enum sd_type_t type); SD_API const char* sd_type_name(enum sd_type_t type);

View File

@ -201,7 +201,7 @@ struct TinyAutoEncoder : public GGMLRunner {
bool decoder_only = true, bool decoder_only = true,
SDVersion version = VERSION_SD1) SDVersion version = VERSION_SD1)
: decode_only(decoder_only), : decode_only(decoder_only),
taesd(decoder_only, version), taesd(decode_only, version),
GGMLRunner(backend) { GGMLRunner(backend) {
taesd.init(params_ctx, tensor_types, prefix); taesd.init(params_ctx, tensor_types, prefix);
} }

View File

@ -177,7 +177,7 @@ STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const
STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data); STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data); STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data); STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality, const char* parameters = NULL); STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
#ifdef STBIW_WINDOWS_UTF8 #ifdef STBIW_WINDOWS_UTF8
STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input); STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input);