Skip to content

Commit e6006e2

Browse files
authored
Merge branch 'leejet:master' into master
2 parents b49b8dc + 10c6501 commit e6006e2

File tree

6 files changed

+64
-39
lines changed

6 files changed

+64
-39
lines changed

conditioner.hpp

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ struct FrozenCLIPEmbedderWithCustomWords : public Conditioner {
5151

5252
std::string trigger_word = "img"; // should be user settable
5353
std::string embd_dir;
54-
int32_t num_custom_embeddings = 0;
54+
int32_t num_custom_embeddings = 0;
55+
int32_t num_custom_embeddings_2 = 0;
5556
std::vector<uint8_t> token_embed_custom;
5657
std::vector<std::string> readed_embeddings;
5758

@@ -131,28 +132,55 @@ struct FrozenCLIPEmbedderWithCustomWords : public Conditioner {
131132
params.no_alloc = false;
132133
struct ggml_context* embd_ctx = ggml_init(params);
133134
struct ggml_tensor* embd = NULL;
134-
int64_t hidden_size = text_model->model.hidden_size;
135+
struct ggml_tensor* embd2 = NULL;
135136
auto on_load = [&](const TensorStorage& tensor_storage, ggml_tensor** dst_tensor) {
136-
if (tensor_storage.ne[0] != hidden_size) {
137-
LOG_DEBUG("embedding wrong hidden size, got %i, expected %i", tensor_storage.ne[0], hidden_size);
138-
return false;
137+
if (tensor_storage.ne[0] != text_model->model.hidden_size) {
138+
if (text_model2) {
139+
if (tensor_storage.ne[0] == text_model2->model.hidden_size) {
140+
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);
141+
*dst_tensor = embd2;
142+
} else {
143+
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);
144+
return false;
145+
}
146+
} else {
147+
LOG_DEBUG("embedding wrong hidden size, got %i, expected %i", tensor_storage.ne[0], text_model->model.hidden_size);
148+
return false;
149+
}
150+
} else {
151+
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);
152+
*dst_tensor = embd;
139153
}
140-
embd = ggml_new_tensor_2d(embd_ctx, tensor_storage.type, hidden_size, tensor_storage.n_dims > 1 ? tensor_storage.ne[1] : 1);
141-
*dst_tensor = embd;
142154
return true;
143155
};
144156
model_loader.load_tensors(on_load, NULL);
145157
readed_embeddings.push_back(embd_name);
146-
token_embed_custom.resize(token_embed_custom.size() + ggml_nbytes(embd));
147-
memcpy((void*)(token_embed_custom.data() + num_custom_embeddings * hidden_size * ggml_type_size(embd->type)),
148-
embd->data,
149-
ggml_nbytes(embd));
150-
for (int i = 0; i < embd->ne[1]; i++) {
151-
bpe_tokens.push_back(text_model->model.vocab_size + num_custom_embeddings);
152-
// LOG_DEBUG("new custom token: %i", text_model.vocab_size + num_custom_embeddings);
153-
num_custom_embeddings++;
158+
if (embd) {
159+
int64_t hidden_size = text_model->model.hidden_size;
160+
token_embed_custom.resize(token_embed_custom.size() + ggml_nbytes(embd));
161+
memcpy((void*)(token_embed_custom.data() + num_custom_embeddings * hidden_size * ggml_type_size(embd->type)),
162+
embd->data,
163+
ggml_nbytes(embd));
164+
for (int i = 0; i < embd->ne[1]; i++) {
165+
bpe_tokens.push_back(text_model->model.vocab_size + num_custom_embeddings);
166+
// LOG_DEBUG("new custom token: %i", text_model.vocab_size + num_custom_embeddings);
167+
num_custom_embeddings++;
168+
}
169+
LOG_DEBUG("embedding '%s' applied, custom embeddings: %i", embd_name.c_str(), num_custom_embeddings);
170+
}
171+
if (embd2) {
172+
int64_t hidden_size = text_model2->model.hidden_size;
173+
token_embed_custom.resize(token_embed_custom.size() + ggml_nbytes(embd2));
174+
memcpy((void*)(token_embed_custom.data() + num_custom_embeddings_2 * hidden_size * ggml_type_size(embd2->type)),
175+
embd2->data,
176+
ggml_nbytes(embd2));
177+
for (int i = 0; i < embd2->ne[1]; i++) {
178+
bpe_tokens.push_back(text_model2->model.vocab_size + num_custom_embeddings_2);
179+
// LOG_DEBUG("new custom token: %i", text_model.vocab_size + num_custom_embeddings);
180+
num_custom_embeddings_2++;
181+
}
182+
LOG_DEBUG("embedding '%s' applied, custom embeddings: %i (text model 2)", embd_name.c_str(), num_custom_embeddings_2);
154183
}
155-
LOG_DEBUG("embedding '%s' applied, custom embeddings: %i", embd_name.c_str(), num_custom_embeddings);
156184
return true;
157185
}
158186

examples/cli/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ struct SDParams {
126126
int upscale_repeats = 1;
127127

128128
std::vector<int> skip_layers = {7, 8, 9};
129-
float slg_scale = 0.;
130-
float skip_layer_start = 0.01;
131-
float skip_layer_end = 0.2;
129+
float slg_scale = 0.f;
130+
float skip_layer_start = 0.01f;
131+
float skip_layer_end = 0.2f;
132132
};
133133

134134
void print_params(SDParams params) {

gits_noise.inl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -329,21 +329,21 @@ const std::vector<std::vector<float>> GITS_NOISE_1_50 = {
329329
};
330330

331331
const std::vector<const std::vector<std::vector<float>>*> GITS_NOISE = {
332-
{ &GITS_NOISE_0_80 },
333-
{ &GITS_NOISE_0_85 },
334-
{ &GITS_NOISE_0_90 },
335-
{ &GITS_NOISE_0_95 },
336-
{ &GITS_NOISE_1_00 },
337-
{ &GITS_NOISE_1_05 },
338-
{ &GITS_NOISE_1_10 },
339-
{ &GITS_NOISE_1_15 },
340-
{ &GITS_NOISE_1_20 },
341-
{ &GITS_NOISE_1_25 },
342-
{ &GITS_NOISE_1_30 },
343-
{ &GITS_NOISE_1_35 },
344-
{ &GITS_NOISE_1_40 },
345-
{ &GITS_NOISE_1_45 },
346-
{ &GITS_NOISE_1_50 }
332+
&GITS_NOISE_0_80,
333+
&GITS_NOISE_0_85,
334+
&GITS_NOISE_0_90,
335+
&GITS_NOISE_0_95,
336+
&GITS_NOISE_1_00,
337+
&GITS_NOISE_1_05,
338+
&GITS_NOISE_1_10,
339+
&GITS_NOISE_1_15,
340+
&GITS_NOISE_1_20,
341+
&GITS_NOISE_1_25,
342+
&GITS_NOISE_1_30,
343+
&GITS_NOISE_1_35,
344+
&GITS_NOISE_1_40,
345+
&GITS_NOISE_1_45,
346+
&GITS_NOISE_1_50
347347
};
348348

349349
#endif // GITS_NOISE_INL

model.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,9 +1929,6 @@ bool ModelLoader::load_tensors(std::map<std::string, struct ggml_tensor*>& tenso
19291929
if (pair.first.find("cond_stage_model.transformer.text_model.encoder.layers.23") != std::string::npos) {
19301930
continue;
19311931
}
1932-
if (pair.first.find("alphas_cumprod") != std::string::npos) {
1933-
continue;
1934-
}
19351932

19361933
if (pair.first.find("alphas_cumprod") != std::string::npos) {
19371934
continue;

stable-diffusion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ sd_image_t* img2img(sd_ctx_t* sd_ctx,
18061806

18071807
size_t t2 = ggml_time_ms();
18081808

1809-
LOG_INFO("img2img completed in %.2fs", (t1 - t0) * 1.0f / 1000);
1809+
LOG_INFO("img2img completed in %.2fs", (t2 - t0) * 1.0f / 1000);
18101810

18111811
return result_images;
18121812
}

thirdparty/stb_image_write.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const
177177
STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
178178
STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
179179
STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
180-
STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
180+
STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality, const char* parameters = NULL);
181181

182182
#ifdef STBIW_WINDOWS_UTF8
183183
STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input);

0 commit comments

Comments
 (0)