mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2025-12-13 05:48:56 +00:00
fix: avoid multithreading issues in the model loader
This commit is contained in:
parent
1e5f207006
commit
567f9f14f0
@ -2427,6 +2427,7 @@ bool ModelLoader::save_to_gguf_file(const std::string& file_path, ggml_type type
|
|||||||
|
|
||||||
auto tensor_type_rules = parse_tensor_type_rules(tensor_type_rules_str);
|
auto tensor_type_rules = parse_tensor_type_rules(tensor_type_rules_str);
|
||||||
|
|
||||||
|
std::mutex tensor_mutex;
|
||||||
auto on_new_tensor_cb = [&](const TensorStorage& tensor_storage, ggml_tensor** dst_tensor) -> bool {
|
auto on_new_tensor_cb = [&](const TensorStorage& tensor_storage, ggml_tensor** dst_tensor) -> bool {
|
||||||
const std::string& name = tensor_storage.name;
|
const std::string& name = tensor_storage.name;
|
||||||
ggml_type tensor_type = tensor_storage.type;
|
ggml_type tensor_type = tensor_storage.type;
|
||||||
@ -2444,6 +2445,7 @@ bool ModelLoader::save_to_gguf_file(const std::string& file_path, ggml_type type
|
|||||||
tensor_type = dst_type;
|
tensor_type = dst_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(tensor_mutex);
|
||||||
ggml_tensor* tensor = ggml_new_tensor(ggml_ctx, tensor_type, tensor_storage.n_dims, tensor_storage.ne);
|
ggml_tensor* tensor = ggml_new_tensor(ggml_ctx, tensor_type, tensor_storage.n_dims, tensor_storage.ne);
|
||||||
if (tensor == NULL) {
|
if (tensor == NULL) {
|
||||||
LOG_ERROR("ggml_new_tensor failed");
|
LOG_ERROR("ggml_new_tensor failed");
|
||||||
|
|||||||
2
pmid.hpp
2
pmid.hpp
@ -600,6 +600,7 @@ struct PhotoMakerIDEmbed : public GGMLRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool dry_run = true;
|
bool dry_run = true;
|
||||||
|
std::mutex tensor_mutex;
|
||||||
auto on_new_tensor_cb = [&](const TensorStorage& tensor_storage, ggml_tensor** dst_tensor) -> bool {
|
auto on_new_tensor_cb = [&](const TensorStorage& tensor_storage, ggml_tensor** dst_tensor) -> bool {
|
||||||
const std::string& name = tensor_storage.name;
|
const std::string& name = tensor_storage.name;
|
||||||
|
|
||||||
@ -608,6 +609,7 @@ struct PhotoMakerIDEmbed : public GGMLRunner {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (dry_run) {
|
if (dry_run) {
|
||||||
|
std::lock_guard<std::mutex> lock(tensor_mutex);
|
||||||
struct ggml_tensor* real = ggml_new_tensor(params_ctx,
|
struct ggml_tensor* real = ggml_new_tensor(params_ctx,
|
||||||
tensor_storage.type,
|
tensor_storage.type,
|
||||||
tensor_storage.n_dims,
|
tensor_storage.n_dims,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user