mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-10-15 05:19:28 +08:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5792c66879 | ||
|
|
39d54702a6 | ||
|
|
60889bc9a1 |
@@ -266,6 +266,7 @@ void sd_log_cb(enum sd_log_level_t level, const char* log, void* data) {
|
||||
struct LoraEntry {
|
||||
std::string name;
|
||||
std::string path;
|
||||
std::string fullpath;
|
||||
};
|
||||
|
||||
int main(int argc, const char** argv) {
|
||||
@@ -321,7 +322,8 @@ int main(int argc, const char** argv) {
|
||||
|
||||
LoraEntry e;
|
||||
e.name = p.stem().u8string();
|
||||
std::string rel = fs::relative(p, lora_dir).u8string();
|
||||
e.fullpath = p.u8string();
|
||||
std::string rel = p.lexically_relative(lora_dir).u8string();
|
||||
std::replace(rel.begin(), rel.end(), '\\', '/');
|
||||
e.path = rel;
|
||||
|
||||
@@ -340,10 +342,11 @@ int main(int argc, const char** argv) {
|
||||
}
|
||||
};
|
||||
|
||||
auto is_valid_lora_path = [&](const std::string& path) -> bool {
|
||||
auto get_lora_full_path = [&](const std::string& path) -> std::string {
|
||||
std::lock_guard<std::mutex> lock(lora_mutex);
|
||||
return std::any_of(lora_cache.begin(), lora_cache.end(),
|
||||
auto it = std::find_if(lora_cache.begin(), lora_cache.end(),
|
||||
[&](const LoraEntry& e) { return e.path == path; });
|
||||
return (it != lora_cache.end()) ? it->fullpath : "";
|
||||
};
|
||||
|
||||
httplib::Server svr;
|
||||
@@ -565,7 +568,8 @@ int main(int argc, const char** argv) {
|
||||
std::string sd_cpp_extra_args_str = extract_and_remove_sd_cpp_extra_args(prompt);
|
||||
|
||||
size_t image_count = req.form.get_file_count("image[]");
|
||||
if (image_count == 0) {
|
||||
bool has_legacy_image = req.form.has_file("image");
|
||||
if (image_count == 0 && !has_legacy_image) {
|
||||
res.status = 400;
|
||||
res.set_content(R"({"error":"at least one image[] required"})", "application/json");
|
||||
return;
|
||||
@@ -576,6 +580,10 @@ int main(int argc, const char** argv) {
|
||||
auto file = req.form.get_file("image[]", i);
|
||||
images_bytes.emplace_back(file.content.begin(), file.content.end());
|
||||
}
|
||||
if (image_count == 0 && has_legacy_image) {
|
||||
auto file = req.form.get_file("image");
|
||||
images_bytes.emplace_back(file.content.begin(), file.content.end());
|
||||
}
|
||||
|
||||
std::vector<uint8_t> mask_bytes;
|
||||
if (req.form.has_file("mask")) {
|
||||
@@ -862,11 +870,12 @@ int main(int argc, const char** argv) {
|
||||
return bad("lora.path required");
|
||||
}
|
||||
|
||||
if (!is_valid_lora_path(path)) {
|
||||
std::string fullpath = get_lora_full_path(path);
|
||||
if (fullpath.empty()) {
|
||||
return bad("invalid lora path: " + path);
|
||||
}
|
||||
|
||||
lora_path_storage.push_back(path);
|
||||
lora_path_storage.push_back(fullpath);
|
||||
sd_lora_t l;
|
||||
l.is_high_noise = is_high_noise;
|
||||
l.multiplier = multiplier;
|
||||
|
||||
+1
-1
@@ -1057,7 +1057,7 @@ SDVersion ModelLoader::get_sd_version() {
|
||||
if (tensor_storage.name.find("model.diffusion_model.transformer_blocks.0.img_mod.1.weight") != std::string::npos) {
|
||||
return VERSION_QWEN_IMAGE;
|
||||
}
|
||||
if (tensor_storage.name.find("model.diffusion_model.net.llm_adapter.blocks.0.cross_attn.q_proj.weight") != std::string::npos) {
|
||||
if (tensor_storage.name.find("llm_adapter.blocks.0.cross_attn.q_proj.weight") != std::string::npos) {
|
||||
return VERSION_ANIMA;
|
||||
}
|
||||
if (tensor_storage.name.find("model.diffusion_model.double_stream_modulation_img.lin.weight") != std::string::npos) {
|
||||
|
||||
+10
-8
@@ -653,6 +653,14 @@ std::string convert_diffusers_dit_to_original_lumina2(std::string name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string convert_other_dit_to_original_anima(std::string name) {
|
||||
static const std::string anima_net_prefix = "net.";
|
||||
if (!starts_with(name, anima_net_prefix)) {
|
||||
name = anima_net_prefix + name;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string convert_diffusion_model_name(std::string name, std::string prefix, SDVersion version) {
|
||||
if (sd_version_is_sd1(version) || sd_version_is_sd2(version)) {
|
||||
name = convert_diffusers_unet_to_original_sd1(name);
|
||||
@@ -664,6 +672,8 @@ std::string convert_diffusion_model_name(std::string name, std::string prefix, S
|
||||
name = convert_diffusers_dit_to_original_flux(name);
|
||||
} else if (sd_version_is_z_image(version)) {
|
||||
name = convert_diffusers_dit_to_original_lumina2(name);
|
||||
} else if (sd_version_is_anima(version)) {
|
||||
name = convert_other_dit_to_original_anima(name);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
@@ -1094,14 +1104,6 @@ std::string convert_tensor_name(std::string name, SDVersion version) {
|
||||
}
|
||||
}
|
||||
|
||||
if (is_lora && sd_version_is_anima(version)) {
|
||||
static const std::string anima_diffusion_prefix = "model.diffusion_model.";
|
||||
static const std::string anima_net_prefix = "model.diffusion_model.net.";
|
||||
if (starts_with(name, anima_diffusion_prefix) && !starts_with(name, anima_net_prefix)) {
|
||||
name = anima_net_prefix + name.substr(anima_diffusion_prefix.size());
|
||||
}
|
||||
}
|
||||
|
||||
// cond_stage_model
|
||||
{
|
||||
for (const auto& prefix : cond_stage_model_prefix_vec) {
|
||||
|
||||
Reference in New Issue
Block a user