Compare commits

..

No commits in common. "d3b2cb047eb3942a8d7484311a93231c860a204e" and "0e4ee04488159b81d95a9ffcd983a077fd5dcb77" have entirely different histories.

19 changed files with 51 additions and 163 deletions

View File

@ -113,7 +113,7 @@ struct Conditioner {
public:
virtual SDCondition get_learned_condition(int n_threads,
const ConditionerParams& conditioner_params) = 0;
virtual bool alloc_params_buffer() = 0;
virtual void alloc_params_buffer() = 0;
virtual void free_params_buffer() = 0;
virtual void get_param_tensors(std::map<std::string, ggml_tensor*>& tensors) = 0;
virtual size_t get_params_buffer_size() = 0;
@ -176,16 +176,11 @@ struct FrozenCLIPEmbedderWithCustomWords : public Conditioner {
}
}
bool alloc_params_buffer() override {
if (!text_model->alloc_params_buffer()) {
return false;
}
void alloc_params_buffer() override {
text_model->alloc_params_buffer();
if (sd_version_is_sdxl(version)) {
if (!text_model2->alloc_params_buffer()) {
return false;
}
text_model2->alloc_params_buffer();
}
return true;
}
void free_params_buffer() override {
@ -786,23 +781,16 @@ struct SD3CLIPEmbedder : public Conditioner {
}
}
bool alloc_params_buffer() override {
void alloc_params_buffer() override {
if (clip_l) {
if (!clip_l->alloc_params_buffer()) {
return false;
}
clip_l->alloc_params_buffer();
}
if (clip_g) {
if (!clip_g->alloc_params_buffer()) {
return false;
}
clip_g->alloc_params_buffer();
}
if (t5) {
if (!t5->alloc_params_buffer()) {
return false;
}
t5->alloc_params_buffer();
}
return true;
}
void free_params_buffer() override {
@ -1157,21 +1145,15 @@ struct FluxCLIPEmbedder : public Conditioner {
}
}
bool alloc_params_buffer() override {
void alloc_params_buffer() override {
if (clip_l) {
if (!clip_l->alloc_params_buffer()) {
return false;
}
clip_l->alloc_params_buffer();
}
if (t5) {
if (!t5->alloc_params_buffer()) {
return false;
}
t5->alloc_params_buffer();
}
return true;
}
void free_params_buffer() override {
if (clip_l) {
clip_l->free_params_buffer();
@ -1406,13 +1388,10 @@ struct T5CLIPEmbedder : public Conditioner {
}
}
bool alloc_params_buffer() override {
void alloc_params_buffer() override {
if (t5) {
if (!t5->alloc_params_buffer()) {
return false;
}
t5->alloc_params_buffer();
}
return true;
}
void free_params_buffer() override {
@ -1599,11 +1578,8 @@ struct AnimaConditioner : public Conditioner {
llm->get_param_tensors(tensors, "text_encoders.llm");
}
bool alloc_params_buffer() override {
if (!llm->alloc_params_buffer()) {
return false;
}
return true;
void alloc_params_buffer() override {
llm->alloc_params_buffer();
}
void free_params_buffer() override {
@ -1741,11 +1717,8 @@ struct LLMEmbedder : public Conditioner {
llm->get_param_tensors(tensors, "text_encoders.llm");
}
bool alloc_params_buffer() override {
if (!llm->alloc_params_buffer()) {
return false;
}
return true;
void alloc_params_buffer() override {
llm->alloc_params_buffer();
}
void free_params_buffer() override {
@ -2266,14 +2239,9 @@ struct LTXAVEmbedder : public Conditioner {
projector->get_param_tensors(tensors, "text_embedding_projection");
}
bool alloc_params_buffer() override {
if (!llm->alloc_params_buffer()) {
return false;
}
if (!projector->alloc_params_buffer()) {
return false;
}
return true;
void alloc_params_buffer() override {
llm->alloc_params_buffer();
projector->alloc_params_buffer();
}
void free_params_buffer() override {

View File

@ -457,11 +457,7 @@ struct ControlNet : public GGMLRunner {
bool load_from_file(const std::string& file_path, int n_threads) {
LOG_INFO("loading control net from '%s'", file_path.c_str());
if (!alloc_params_buffer()) {
LOG_ERROR("control net model buffer allocation failed");
return false;
}
alloc_params_buffer();
std::map<std::string, ggml_tensor*> tensors;
control_net.get_param_tensors(tensors);
std::set<std::string> ignore_tensors;

View File

@ -270,11 +270,7 @@ struct ESRGAN : public GGMLRunner {
rrdb_net = std::make_unique<RRDBNet>(detected_scale, detected_num_block, detected_num_in_ch, detected_num_out_ch, detected_num_feat, detected_num_grow_ch);
rrdb_net->init(params_ctx, {}, "");
if (!alloc_params_buffer()) {
LOG_ERROR("esrgan model buffer allocation failed");
return false;
}
alloc_params_buffer();
std::map<std::string, ggml_tensor*> esrgan_tensors;
rrdb_net->get_param_tensors(esrgan_tensors);

View File

@ -1592,11 +1592,7 @@ namespace Flux {
VERSION_FLUX2,
false);
if (!flux->alloc_params_buffer()) {
LOG_ERROR("flux model allocation failed");
return;
}
flux->alloc_params_buffer();
std::map<std::string, ggml_tensor*> tensors;
flux->get_param_tensors(tensors, "model.diffusion_model");

View File

@ -492,11 +492,8 @@ namespace HiDreamO1 {
vision_runner->get_param_tensors(tensors);
}
bool alloc_params_buffer() override {
if (!vision_runner->alloc_params_buffer()) {
return false;
}
return true;
void alloc_params_buffer() override {
vision_runner->alloc_params_buffer();
}
void free_params_buffer() override {

View File

@ -1769,11 +1769,8 @@ namespace LLM {
model.get_param_tensors(tensors, prefix);
}
bool alloc_params_buffer() {
if (!model.alloc_params_buffer()) {
return false;
}
return true;
void alloc_params_buffer() {
model.alloc_params_buffer();
}
std::tuple<std::vector<int>, std::vector<float>> tokenize(std::string text,
@ -2015,11 +2012,7 @@ namespace LLM {
"text_encoders.llm",
true);
if (!llm->alloc_params_buffer()) {
LOG_ERROR("llm model allocation failed");
return;
}
llm->alloc_params_buffer();
std::map<std::string, ggml_tensor*> tensors;
llm->get_param_tensors(tensors, "text_encoders.llm");

View File

@ -86,11 +86,7 @@ struct LoraModel : public GGMLRunner {
lora_tensors[name] = real;
}
if (!alloc_params_buffer()) {
LOG_ERROR("lora model buffer allocation failed");
return false;
}
alloc_params_buffer();
dry_run = false;
model_loader.load_tensors(on_new_tensor_cb, n_threads);

View File

@ -1068,11 +1068,7 @@ namespace LTXV {
tensor_storage_map,
prefix);
if (!ltx_audio_vae->alloc_params_buffer()) {
LOG_ERROR("ltx audio vae buffer allocation failed");
return;
}
ltx_audio_vae->alloc_params_buffer();
std::map<std::string, ggml_tensor*> tensors;
ltx_audio_vae->get_param_tensors(tensors, "");

View File

@ -1534,11 +1534,7 @@ struct LTXVideoVAE : public VAE {
true,
VERSION_LTXAV);
if (!vae->alloc_params_buffer()) {
LOG_ERROR("vae buffer allocation failed");
return;
}
vae->alloc_params_buffer();
std::map<std::string, ggml_tensor*> tensors;
vae->get_param_tensors(tensors, "first_stage_model");

View File

@ -2017,10 +2017,7 @@ namespace LTXV {
tensor_storage_map,
"model.diffusion_model");
if (!ltxav->alloc_params_buffer()) {
LOG_ERROR("ltxav buffer allocation failed");
return;
}
ltxav->alloc_params_buffer();
std::map<std::string, ggml_tensor*> tensors;
ltxav->get_param_tensors(tensors, "model.diffusion_model");

View File

@ -953,11 +953,7 @@ struct MMDiTRunner : public DiffusionModelRunner {
{
LOG_INFO("loading from '%s'", file_path.c_str());
if (!mmdit->alloc_params_buffer()) {
LOG_ERROR("mmdit embeds buffer allocation failed");
return;
}
mmdit->alloc_params_buffer();
std::map<std::string, ggml_tensor*> tensors;
mmdit->get_param_tensors(tensors, "model.diffusion_model");

View File

@ -865,13 +865,8 @@ std::vector<MmapTensorStore> ModelLoader::mmap_tensors(std::map<std::string, ggm
if (dst_tensor == nullptr)
continue;
if (tensor_storage.is_f8_e4m3 ||
tensor_storage.is_f8_e5m2 ||
tensor_storage.is_f64 ||
tensor_storage.is_i64 ||
tensor_storage.type != dst_tensor->type) {
if (tensor_storage.type != dst_tensor->type)
continue;
}
size_t tensor_size = tensor_storage.nbytes();
size_t tensor_offset = tensor_storage.offset;
@ -1004,12 +999,6 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, int n_thread
continue;
}
if (dst_tensor->data == nullptr) {
LOG_ERROR("process tensor data failed: '%s'", tensor_storage.name.c_str());
failed = true;
break;
}
// skip mmapped tensors
if (dst_tensor->buffer != nullptr && dst_tensor->buffer == fdata.mmbuffer.get()) {
continue;

View File

@ -615,10 +615,7 @@ struct PhotoMakerIDEmbed : public GGMLRunner {
};
model_loader->load_tensors(on_new_tensor_cb, n_threads);
if (!alloc_params_buffer()) {
LOG_ERROR("PhotoMaker ID embeds buffer allocation failed");
return false;
}
alloc_params_buffer();
dry_run = false;
model_loader->load_tensors(on_new_tensor_cb, n_threads);

View File

@ -705,11 +705,7 @@ namespace Qwen {
"model.diffusion_model",
VERSION_QWEN_IMAGE);
if (!qwen_image->alloc_params_buffer()) {
LOG_ERROR("qwen_image buffer allocation failed");
return;
}
qwen_image->alloc_params_buffer();
std::map<std::string, ggml_tensor*> tensors;
qwen_image->get_param_tensors(tensors, "model.diffusion_model");

View File

@ -984,20 +984,14 @@ public:
ggml_free(ctx);
return false;
}
if (cond_stage_model && !cond_stage_model->alloc_params_buffer()) {
LOG_ERROR("Conditioner model params buffer allocation failed");
ggml_free(ctx);
return false;
if (cond_stage_model) {
cond_stage_model->alloc_params_buffer();
}
if (diffusion_model && !diffusion_model->alloc_params_buffer()) {
LOG_ERROR("Diffusion model params buffer allocation failed");
ggml_free(ctx);
return false;
if (diffusion_model) {
diffusion_model->alloc_params_buffer();
}
if (high_noise_diffusion_model && !high_noise_diffusion_model->alloc_params_buffer()) {
LOG_ERROR("High noise diffusion model params buffer allocation failed");
ggml_free(ctx);
return false;
if (high_noise_diffusion_model) {
high_noise_diffusion_model->alloc_params_buffer();
}
if (first_stage_model && !first_stage_model->alloc_params_buffer()) {
LOG_ERROR("VAE params buffer allocation failed");

View File

@ -475,11 +475,8 @@ struct T5Embedder {
model.get_param_tensors(tensors, prefix);
}
bool alloc_params_buffer() {
if (!model.alloc_params_buffer()) {
return false;
}
return true;
void alloc_params_buffer() {
model.alloc_params_buffer();
}
std::tuple<std::vector<int>, std::vector<float>, std::vector<float>> tokenize(std::string text,
@ -581,10 +578,7 @@ struct T5Embedder {
std::shared_ptr<T5Embedder> t5 = std::make_shared<T5Embedder>(backend, backend, tensor_storage_map, "", true);
if (!t5->alloc_params_buffer()) {
LOG_ERROR("t5 params buffer allocation failed");
return;
}
t5->alloc_params_buffer();
std::map<std::string, ggml_tensor*> tensors;
t5->get_param_tensors(tensors, "");

View File

@ -131,10 +131,11 @@ std::vector<std::u32string> BPETokenizer::bpe(const std::u32string& token) const
}
std::vector<int> BPETokenizer::encode(const std::string& text, on_new_token_cb_t on_new_token_cb) {
std::string normalized_text = normalize(text);
std::vector<int32_t> bpe_tokens;
std::vector<std::string> token_strs;
auto splited_texts = split_with_special_tokens(text, special_tokens);
auto splited_texts = split_with_special_tokens(normalized_text, special_tokens);
for (auto& splited_text : splited_texts) {
if (is_special_token(splited_text)) {
@ -159,7 +160,7 @@ std::vector<int> BPETokenizer::encode(const std::string& text, on_new_token_cb_t
}
}
std::string token_str = normalize(token);
std::string token_str = token;
std::u32string utf32_token;
if (byte_level_bpe) {
for (int i = 0; i < token_str.length(); i++) {

View File

@ -1334,10 +1334,7 @@ namespace WAN {
{
LOG_INFO("loading from '%s'", file_path.c_str());
if (!vae->alloc_params_buffer()) {
LOG_ERROR("vae buffer allocation failed");
return;
}
vae->alloc_params_buffer();
std::map<std::string, ggml_tensor*> tensors;
vae->get_param_tensors(tensors, "first_stage_model");
@ -2371,11 +2368,7 @@ namespace WAN {
"model.diffusion_model",
VERSION_WAN2_2_TI2V);
if (!wan->alloc_params_buffer()) {
LOG_ERROR("wan buffer allocation failed");
return;
}
wan->alloc_params_buffer();
std::map<std::string, ggml_tensor*> tensors;
wan->get_param_tensors(tensors, "model.diffusion_model");

View File

@ -639,10 +639,7 @@ namespace ZImage {
"model.diffusion_model",
VERSION_QWEN_IMAGE);
if (!z_image->alloc_params_buffer()) {
LOG_ERROR("z_image buffer allocation failed");
return;
}
z_image->alloc_params_buffer();
std::map<std::string, ggml_tensor*> tensors;
z_image->get_param_tensors(tensors, "model.diffusion_model");