From 3ed775cf76cf51b0e4d6df8cb2dc5c73c94ad9c2 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 12 Mar 2025 23:38:49 -0400 Subject: [PATCH] vae and unet from cloudflare instead of hf --- crates/desktop/src-tauri/src/ml/model_type.rs | 12 +++++ .../src/ml/stable_diffusion/lcm_pipeline.rs | 50 ++++++++----------- .../src/threads/downloader_thread.rs | 2 + 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/crates/desktop/src-tauri/src/ml/model_type.rs b/crates/desktop/src-tauri/src/ml/model_type.rs index 69b95acb09..2dd48f40b8 100644 --- a/crates/desktop/src-tauri/src/ml/model_type.rs +++ b/crates/desktop/src-tauri/src/ml/model_type.rs @@ -9,6 +9,8 @@ pub enum ModelType { SdxlTurboVae, SdxlTurboClipEncoder, SdxlTurboClipEncoder2, + SimianLuoLcmDreamshaperV7Unet, + LykonDreamshaper7Vae, } impl ModelType { @@ -19,6 +21,8 @@ impl ModelType { Self::SdxlTurboVae => "SDXL Turbo VAE", Self::SdxlTurboClipEncoder => "Clip Encoder #1", Self::SdxlTurboClipEncoder2 => "Clip Encoder #2", + Self::SimianLuoLcmDreamshaperV7Unet => "SimianLuo LCM Dreamshaper v7 UNET", + Self::LykonDreamshaper7Vae => "Lykon Dreamshaper 7 VAE", } } @@ -29,6 +33,8 @@ impl ModelType { Self::SdxlTurboVae => NotificationModelType::Vae, Self::SdxlTurboClipEncoder => NotificationModelType::ClipEncoder, Self::SdxlTurboClipEncoder2 => NotificationModelType::ClipEncoder, + Self::SimianLuoLcmDreamshaperV7Unet => NotificationModelType::Unet, + Self::LykonDreamshaper7Vae => NotificationModelType::Vae, } } @@ -39,6 +45,8 @@ impl ModelType { | Self::SdxlTurboVae | Self::SdxlTurboClipEncoder | Self::SdxlTurboClipEncoder2 => Some("stabilityai/sdxl-turbo"), + Self::SimianLuoLcmDreamshaperV7Unet => Some("SimianLuo/LCM_Dreamshaper_v7"), + Self::LykonDreamshaper7Vae => Some("Lykon/dreamshaper-7"), } } @@ -49,6 +57,8 @@ impl ModelType { Self::SdxlTurboVae => "https://pub-bc5e2bc0cdee4bb5ae8fca9d641ca0d6.r2.dev/diffusion_pytorch_model.vae.safetensors", Self::SdxlTurboClipEncoder => "https://pub-bc5e2bc0cdee4bb5ae8fca9d641ca0d6.r2.dev/clip_text_encoder.safetensors", Self::SdxlTurboClipEncoder2 => "https://pub-bc5e2bc0cdee4bb5ae8fca9d641ca0d6.r2.dev/clip_text_encoder_2.safetensors", + Self::SimianLuoLcmDreamshaperV7Unet => "https://pub-bc5e2bc0cdee4bb5ae8fca9d641ca0d6.r2.dev/simianluo_lcm_dreamshaper_v7_unet.safetensors", + Self::LykonDreamshaper7Vae => "https://pub-bc5e2bc0cdee4bb5ae8fca9d641ca0d6.r2.dev/lykon_dreamshaper_7_vae.safetensors", } } @@ -59,6 +69,8 @@ impl ModelType { Self::SdxlTurboVae => "diffusion_pytorch_model.vae.safetensors", Self::SdxlTurboClipEncoder => "clip_text_encoder.safetensors", Self::SdxlTurboClipEncoder2 => "clip_text_encoder_2.safetensors", + Self::SimianLuoLcmDreamshaperV7Unet => "simianluo_lcm_dreamshaper_v7_unet.safetensors", + Self::LykonDreamshaper7Vae => "lykon_dreamshaper_7_vae.safetensors", } } diff --git a/crates/desktop/src-tauri/src/ml/stable_diffusion/lcm_pipeline.rs b/crates/desktop/src-tauri/src/ml/stable_diffusion/lcm_pipeline.rs index 0bddd95bce..9019af72aa 100644 --- a/crates/desktop/src-tauri/src/ml/stable_diffusion/lcm_pipeline.rs +++ b/crates/desktop/src-tauri/src/ml/stable_diffusion/lcm_pipeline.rs @@ -23,6 +23,7 @@ use image::DynamicImage; use log::info; use rand::Rng; use tauri::{AppHandle, Emitter}; +use crate::ml::model_type::ModelType; use crate::state::app_dir::AppDataRoot; pub struct Args<'a> { @@ -119,31 +120,21 @@ pub fn lcm_pipeline(args: Args<'_>) -> Result { let maybe_vae = model_cache.get_vae()?; - let repo = configs.sd_version.repo(); + //let repo = configs.sd_version.repo(); + //println!(">>>>> VAE REPO = {:?}", repo); + //println!("Building VAE model from : {:?} ... (3)", repo); + //let vae_file = configs.hf_api.model(repo.to_string()).get("vae/diffusion_pytorch_model.safetensors")?; - println!("Building VAE model from : {:?} ... (3)", repo); - - let vae_file = configs.hf_api.model(repo.to_string()).get("vae/diffusion_pytorch_model.safetensors")?; + let vae_file = weights_dir.model_path(&ModelType::LykonDreamshaper7Vae); println!("Building VAE model from file {:?}...", &vae_file); - let mut notify_download_complete = false; - //if !vae_file.exists() { - if true { - notify_download_complete = true; - app.emit("notification", NotificationEvent::ModelDownloadStarted { model_name: repo, model_type: NotificationModelType::Vae })?; - } - let vae = configs.sd_config.build_vae(vae_file, &configs.device, configs.dtype)?; let vae = Arc::new(vae); model_cache.set_vae(vae.clone())?; - if notify_download_complete { - app.emit("notification", NotificationEvent::ModelDownloadComplete { model_name: repo, model_type: NotificationModelType::Vae })?; - } - let maybe_unet = model_cache.get_unet()?; let unet = match maybe_unet { @@ -160,21 +151,24 @@ pub fn lcm_pipeline(args: Args<'_>) -> Result { // model_type: ModelType::Unet, // })?; // } - let unet_weights = { - let lcm_model_repo = "SimianLuo/LCM_Dreamshaper_v7"; // LCM UNet - let unet_path = configs.hf_api.model(lcm_model_repo.to_string()).get(if use_f16 { - if lcm_model_repo == "SimianLuo/LCM_Dreamshaper_v7" { - "unet/diffusion_pytorch_model.safetensors" - } else { - "unet/diffusion_pytorch_model.fp16.safetensors" - } - } else { - "unet/diffusion_pytorch_model.safetensors" - })?; - unet_path - }; + //let unet_weights = { + // let lcm_model_repo = "SimianLuo/LCM_Dreamshaper_v7"; // LCM UNet + // let unet_path = configs.hf_api.model(lcm_model_repo.to_string()).get(if use_f16 { + // if lcm_model_repo == "SimianLuo/LCM_Dreamshaper_v7" { + // "unet/diffusion_pytorch_model.safetensors" + // } else { + // "unet/diffusion_pytorch_model.fp16.safetensors" + // } + // } else { + // "unet/diffusion_pytorch_model.safetensors" + // })?; + // unet_path + //}; + + let unet_weights = weights_dir.model_path(&ModelType::SimianLuoLcmDreamshaperV7Unet); println!(">>>>> UNET WEIGHTS = {:?}", unet_weights); + println!(">>>>> USE F16 = {:?}", use_f16); //let unet_weights = ModelFile::UnetLcm.get(unet_weights, configs.sd_version, use_f16)?; diff --git a/crates/desktop/src-tauri/src/threads/downloader_thread.rs b/crates/desktop/src-tauri/src/threads/downloader_thread.rs index 490588820d..8cf444ddde 100644 --- a/crates/desktop/src-tauri/src/threads/downloader_thread.rs +++ b/crates/desktop/src-tauri/src/threads/downloader_thread.rs @@ -45,6 +45,8 @@ pub async fn downloader_thread(app_data_root: AppDataRoot, app: AppHandle) -> ! download_queue.push_back(ModelType::SdxlTurboVae); download_queue.push_back(ModelType::SdxlTurboClipEncoder); download_queue.push_back(ModelType::SdxlTurboClipEncoder2); + download_queue.push_back(ModelType::SimianLuoLcmDreamshaperV7Unet); + download_queue.push_back(ModelType::LykonDreamshaper7Vae); let mut handles = FuturesUnordered::new();