@@ -513,7 +513,6 @@ class StableDiffusionGGML {
513513 clip_vision = std::make_shared<FrozenCLIPVisionEmbedder>(backend,
514514 offload_params_to_cpu,
515515 tensor_storage_map);
516- clip_vision->alloc_params_buffer ();
517516 clip_vision->get_param_tensors (tensors);
518517 }
519518 } else if (sd_version_is_qwen_image (version)) {
@@ -580,18 +579,15 @@ class StableDiffusionGGML {
580579 }
581580 }
582581
583- cond_stage_model->alloc_params_buffer ();
584582 cond_stage_model->get_param_tensors (tensors);
585583
586- diffusion_model->alloc_params_buffer ();
587584 diffusion_model->get_param_tensors (tensors);
588585
589586 if (sd_version_is_unet_edit (version)) {
590587 vae_decode_only = false ;
591588 }
592589
593590 if (high_noise_diffusion_model) {
594- high_noise_diffusion_model->alloc_params_buffer ();
595591 high_noise_diffusion_model->get_param_tensors (tensors);
596592 }
597593
@@ -663,17 +659,14 @@ class StableDiffusionGGML {
663659 } else if (use_tae && !tae_preview_only) {
664660 LOG_INFO (" using TAE for encoding / decoding" );
665661 first_stage_model = create_tae ();
666- first_stage_model->alloc_params_buffer ();
667662 first_stage_model->get_param_tensors (tensors, " tae" );
668663 } else {
669664 LOG_INFO (" using VAE for encoding / decoding" );
670665 first_stage_model = create_vae ();
671- first_stage_model->alloc_params_buffer ();
672666 first_stage_model->get_param_tensors (tensors, " first_stage_model" );
673667 if (use_tae && tae_preview_only) {
674668 LOG_INFO (" using TAE for preview" );
675669 preview_vae = create_tae ();
676- preview_vae->alloc_params_buffer ();
677670 preview_vae->get_param_tensors (tensors, " tae" );
678671 }
679672 }
@@ -739,10 +732,6 @@ class StableDiffusionGGML {
739732 }
740733 }
741734 if (use_pmid) {
742- if (!pmid_model->alloc_params_buffer ()) {
743- LOG_ERROR (" pmid model params buffer allocation failed" );
744- return false ;
745- }
746735 pmid_model->get_param_tensors (tensors, " pmid" );
747736 }
748737
@@ -819,6 +808,33 @@ class StableDiffusionGGML {
819808 if (version == VERSION_SVD) {
820809 ignore_tensors.insert (" conditioner.embedders.3" );
821810 }
811+
812+ if (clip_vision) {
813+ clip_vision->alloc_params_buffer ();
814+ }
815+ if (cond_stage_model) {
816+ cond_stage_model->alloc_params_buffer ();
817+ }
818+ if (diffusion_model) {
819+ diffusion_model->alloc_params_buffer ();
820+ }
821+ if (high_noise_diffusion_model) {
822+ high_noise_diffusion_model->alloc_params_buffer ();
823+ }
824+ if (first_stage_model) {
825+ first_stage_model->alloc_params_buffer ();
826+ }
827+ if (preview_vae) {
828+ preview_vae->alloc_params_buffer ();
829+ }
830+ if (use_pmid && pmid_model) {
831+ if (!pmid_model->alloc_params_buffer ()) {
832+ LOG_ERROR (" pmid model params buffer allocation failed" );
833+ ggml_free (ctx);
834+ return false ;
835+ }
836+ }
837+
822838 bool success = model_loader.load_tensors (tensors, ignore_tensors, n_threads, sd_ctx_params->enable_mmap );
823839 if (!success) {
824840 LOG_ERROR (" load tensors from model loader failed" );
0 commit comments