Skip to content

Commit ac8f5a0

Browse files
committed
feat: add SD-Turbo support
1 parent ca33304 commit ac8f5a0

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Inference of [Stable Diffusion](https://github.com/CompVis/stable-diffusion) in
1111
- Plain C/C++ implementation based on [ggml](https://github.com/ggerganov/ggml), working in the same way as [llama.cpp](https://github.com/ggerganov/llama.cpp)
1212
- Super lightweight and without external dependencies
1313
- SD1.x and SD2.x support
14+
- [SD-Turbo](https://huggingface.co/stabilityai/sd-turbo) support
1415
- 16-bit, 32-bit float support
1516
- 4-bit, 5-bit and 8-bit integer quantization support
1617
- Accelerated memory-efficient CPU inference

model.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ std::string self_attn_names[] = {
5454
"self_attn.q_proj.weight",
5555
"self_attn.k_proj.weight",
5656
"self_attn.v_proj.weight",
57-
5857
"self_attn.q_proj.bias",
5958
"self_attn.k_proj.bias",
6059
"self_attn.v_proj.bias",
@@ -75,13 +74,16 @@ const char* unused_tensors[] = {
7574
"cond_stage_model.transformer.text_model.embeddings.position_ids",
7675
"cond_stage_model.model.logit_scale",
7776
"cond_stage_model.model.text_projection",
77+
"conditioner.embedders.0.model.logit_scale",
78+
"conditioner.embedders.0.model.text_projection",
7879
"model.diffusion_model.time_embedding.cond_proj.weight",
7980
"unet.time_embedding.cond_proj.weight",
8081
"model_ema.decay",
8182
"model_ema.num_updates",
8283
"model_ema.diffusion_model",
8384
"control_model",
8485
"embedding_manager",
86+
"denoiser.sigmas",
8587
};
8688

8789
bool is_unused_tensor(std::string name) {
@@ -126,16 +128,19 @@ std::unordered_map<std::string, std::string> vae_decoder_name_map = {
126128
};
127129

128130
std::string convert_open_clip_to_hf_clip(const std::string& name) {
129-
std::string new_name = name;
131+
std::string new_name = name;
132+
if (starts_with(new_name, "conditioner.embedders.0.")) {
133+
new_name = "cond_stage_model." + new_name.substr(strlen("conditioner.embedders.0."));
134+
}
130135
std::string open_clip_resblock_prefix = "cond_stage_model.model.transformer.resblocks.";
131136
std::string hf_clip_resblock_prefix = "cond_stage_model.transformer.text_model.encoder.layers.";
132137

133-
if (open_clip_to_hf_clip_model.find(name) != open_clip_to_hf_clip_model.end()) {
134-
new_name = open_clip_to_hf_clip_model[name];
138+
if (open_clip_to_hf_clip_model.find(new_name) != open_clip_to_hf_clip_model.end()) {
139+
new_name = open_clip_to_hf_clip_model[new_name];
135140
}
136141

137-
if (name.find(open_clip_resblock_prefix) == 0) {
138-
std::string remain = name.substr(open_clip_resblock_prefix.length());
142+
if (new_name.find(open_clip_resblock_prefix) == 0) {
143+
std::string remain = new_name.substr(open_clip_resblock_prefix.length());
139144
std::string idx = remain.substr(0, remain.find("."));
140145
std::string suffix = remain.substr(idx.length() + 1);
141146

@@ -349,7 +354,7 @@ std::string convert_diffusers_name_to_compvis(const std::string& key, char seq)
349354

350355
std::string convert_tensor_name(const std::string& name) {
351356
std::string new_name;
352-
if (starts_with(name, "cond_stage_model.model")) {
357+
if (starts_with(name, "cond_stage_model.model") || starts_with(name, "conditioner.embedders.0.model")) {
353358
new_name = convert_open_clip_to_hf_clip(name);
354359
} else if (starts_with(name, "first_stage_model.decoder")) {
355360
new_name = convert_vae_decoder_name(name);
@@ -1159,7 +1164,8 @@ SDVersion ModelLoader::get_sd_version() {
11591164
if (tensor_storage.name == "cond_stage_model.transformer.text_model.embeddings.token_embedding.weight" ||
11601165
tensor_storage.name == "cond_stage_model.model.token_embedding.weight" ||
11611166
tensor_storage.name == "text_model.embeddings.token_embedding.weight" ||
1162-
tensor_storage.name == "te.text_model.embeddings.token_embedding.weight") {
1167+
tensor_storage.name == "te.text_model.embeddings.token_embedding.weight" ||
1168+
tensor_storage.name == "conditioner.embedders.0.model.token_embedding.weight") {
11631169
token_embedding_weight = tensor_storage;
11641170
break;
11651171
}

0 commit comments

Comments
 (0)