@@ -478,7 +478,6 @@ class StableDiffusionGGML {
478478 clip_vision = std::make_shared<FrozenCLIPVisionEmbedder>(backend,
479479 offload_params_to_cpu,
480480 tensor_storage_map);
481- clip_vision->alloc_params_buffer ();
482481 clip_vision->get_param_tensors (tensors);
483482 }
484483 } else if (sd_version_is_qwen_image (version)) {
@@ -541,18 +540,15 @@ class StableDiffusionGGML {
541540 diffusion_model->set_flash_attn_enabled (true );
542541 }
543542
544- cond_stage_model->alloc_params_buffer ();
545543 cond_stage_model->get_param_tensors (tensors);
546544
547- diffusion_model->alloc_params_buffer ();
548545 diffusion_model->get_param_tensors (tensors);
549546
550547 if (sd_version_is_unet_edit (version)) {
551548 vae_decode_only = false ;
552549 }
553550
554551 if (high_noise_diffusion_model) {
555- high_noise_diffusion_model->alloc_params_buffer ();
556552 high_noise_diffusion_model->get_param_tensors (tensors);
557553 }
558554
@@ -570,7 +566,6 @@ class StableDiffusionGGML {
570566 " first_stage_model" ,
571567 vae_decode_only,
572568 version);
573- first_stage_model->alloc_params_buffer ();
574569 first_stage_model->get_param_tensors (tensors, " first_stage_model" );
575570 } else if (version == VERSION_CHROMA_RADIANCE) {
576571 first_stage_model = std::make_shared<FakeVAE>(vae_backend,
@@ -596,7 +591,6 @@ class StableDiffusionGGML {
596591 vae_conv_2d_scale);
597592 first_stage_model->set_conv2d_scale (vae_conv_2d_scale);
598593 }
599- first_stage_model->alloc_params_buffer ();
600594 first_stage_model->get_param_tensors (tensors, " first_stage_model" );
601595 }
602596 if (use_tiny_autoencoder) {
@@ -666,10 +660,6 @@ class StableDiffusionGGML {
666660 }
667661 }
668662 if (stacked_id) {
669- if (!pmid_model->alloc_params_buffer ()) {
670- LOG_ERROR (" pmid model params buffer allocation failed" );
671- return false ;
672- }
673663 pmid_model->get_param_tensors (tensors, " pmid" );
674664 }
675665 }
@@ -710,7 +700,17 @@ class StableDiffusionGGML {
710700 if (version == VERSION_SVD) {
711701 ignore_tensors.insert (" conditioner.embedders.3" );
712702 }
713- bool success = model_loader.load_tensors (tensors, ignore_tensors, n_threads, sd_ctx_params->use_mmap );
703+
704+ auto alloc_cb = [&]() -> void {
705+ if (clip_vision) clip_vision->alloc_params_buffer ();
706+ if (cond_stage_model) cond_stage_model->alloc_params_buffer ();
707+ if (diffusion_model) diffusion_model->alloc_params_buffer ();
708+ if (high_noise_diffusion_model) high_noise_diffusion_model->alloc_params_buffer ();
709+ if (first_stage_model) first_stage_model->alloc_params_buffer ();
710+ if (pmid_model) pmid_model->alloc_params_buffer ();
711+ };
712+
713+ bool success = model_loader.load_tensors (tensors, ignore_tensors, n_threads, sd_ctx_params->use_mmap , alloc_cb);
714714 if (!success) {
715715 LOG_ERROR (" load tensors from model loader failed" );
716716 ggml_free (ctx);
0 commit comments