From 04470c1745e5675edfe54c1c9f4fa6e889bb93a6 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 18 Feb 2025 01:01:44 -0500 Subject: [PATCH] speedup --- app_config.yaml | 4 +++- crates/desktop/src-tauri/src/endpoints/sd.rs | 22 +++++++------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/app_config.yaml b/app_config.yaml index 44bf9a0579..924b3516dc 100644 --- a/app_config.yaml +++ b/app_config.yaml @@ -1,5 +1,7 @@ image_width: 512 image_height: 512 -scheduler_steps: 15 +#scheduler_steps: 15 +# NB(bt): It looks like we can get down to 2 sampling steps, perhaps ? +scheduler_steps: 2 scheduler_samples: 1 diff --git a/crates/desktop/src-tauri/src/endpoints/sd.rs b/crates/desktop/src-tauri/src/endpoints/sd.rs index 54cb724a8d..c7d5c1f7dd 100644 --- a/crates/desktop/src-tauri/src/endpoints/sd.rs +++ b/crates/desktop/src-tauri/src/endpoints/sd.rs @@ -88,8 +88,11 @@ pub fn run(args: Args<'_>) -> Result { let init_latent_dist : DiagonalGaussianDistribution = args.model_cache.vae_encode(&input_image)?; + // TODO(bt,2025-02-18): This takes a little bit to generate. println!("Generating latents from input image..."); - let latents = (init_latent_dist.sample()? * vae_scale)?.to_device(&args.configs.device)?; + let latents = (init_latent_dist.sample()? * vae_scale)?; + + //.to_device(&args.configs.device)?; println!("Initial latents shape: {:?}", latents.shape()); @@ -128,21 +131,13 @@ pub fn run(args: Args<'_>) -> Result { continue; } - println!("Processing step {}/{}", timestep_index + 1, timesteps.len()); - let latent_model_input = latents.clone(); + println!("Processing step {}/{} @ timestamp = {}", timestep_index + 1, timesteps.len(), timestep); - println!("Latent input shape: {:?}", latent_model_input.shape()); - - println!("Scaling model input..."); - let latent_model_input = scheduler.scale_model_input(latent_model_input, timestep)?; - - println!("Scaled input shape: {:?}", latent_model_input.shape()); - - println!("Running UNet inference with timestep {}...", timestep); + // TODO(bt,2025-08-18): Do we have to clone the tensor? + let latent_model_input = scheduler.scale_model_input(latents.clone(), timestep)?; let noise_pred = match args.model_cache.unet_inference(&latent_model_input, timestep as f64, &text_embeddings) { Ok(pred) => { - println!("UNet inference successful"); pred }, Err(e) => { @@ -150,11 +145,8 @@ pub fn run(args: Args<'_>) -> Result { return Err(anyhow::anyhow!("UNet inference failed: {}", e)); }, }; - println!("Noise prediction shape: {:?}", noise_pred.shape()); - println!("Applying scheduler step..."); latents = scheduler.step(&noise_pred, timestep, &latents)?; - println!("Step {}/{} completed", timestep_index + 1, timesteps.len()); } println!("Diffusion process completed, decoding image...");