From 6a60fe01c481c34d9257c08720ab84799f25480a Mon Sep 17 00:00:00 2001 From: laurent Date: Sat, 26 Oct 2024 21:51:17 +0200 Subject: [PATCH] Remove some unnecessary clones. --- .../examples/stable-diffusion-3/main.rs | 21 +++++-------------- .../examples/stable-diffusion-3/sampling.rs | 2 +- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/candle-examples/examples/stable-diffusion-3/main.rs b/candle-examples/examples/stable-diffusion-3/main.rs index 58e811c38a..19361e4325 100644 --- a/candle-examples/examples/stable-diffusion-3/main.rs +++ b/candle-examples/examples/stable-diffusion-3/main.rs @@ -203,7 +203,7 @@ fn main() -> Result<()> { // Apply TAESD3 scale factor. Seems to be significantly improving the quality of the image. // https://github.com/comfyanonymous/ComfyUI/blob/3c60ecd7a83da43d694e26a77ca6b93106891251/nodes.py#L721-L723 - autoencoder.decode(&((x.clone() / 1.5305)? + 0.0609)?)? + autoencoder.decode(&((x / 1.5305)? + 0.0609)?)? } } else { let sai_repo = { @@ -212,20 +212,12 @@ fn main() -> Result<()> { }; let model_file = sai_repo.get("sd3_medium_incl_clips_t5xxlfp16.safetensors")?; let vb_fp16 = unsafe { - candle_nn::VarBuilder::from_mmaped_safetensors( - &[model_file.clone()], - DType::F16, - &device, - )? + candle_nn::VarBuilder::from_mmaped_safetensors(&[&model_file], DType::F16, &device)? }; let (context, y) = { let vb_fp32 = unsafe { - candle_nn::VarBuilder::from_mmaped_safetensors( - &[model_file.clone()], - DType::F32, - &device, - )? + candle_nn::VarBuilder::from_mmaped_safetensors(&[model_file], DType::F32, &device)? }; let mut triple = StableDiffusion3TripleClipWithTokenizer::new( vb_fp16.pp("text_encoders"), @@ -271,15 +263,12 @@ fn main() -> Result<()> { }; { - let vb_vae = vb_fp16 - .clone() - .rename_f(sd3_vae_vb_rename) - .pp("first_stage_model"); + let vb_vae = vb_fp16.rename_f(sd3_vae_vb_rename).pp("first_stage_model"); let autoencoder = build_sd3_vae_autoencoder(vb_vae)?; // Apply TAESD3 scale factor. Seems to be significantly improving the quality of the image. // https://github.com/comfyanonymous/ComfyUI/blob/3c60ecd7a83da43d694e26a77ca6b93106891251/nodes.py#L721-L723 - autoencoder.decode(&((x.clone() / 1.5305)? + 0.0609)?)? + autoencoder.decode(&((x / 1.5305)? + 0.0609)?)? } }; let img = ((img.clamp(-1f32, 1f32)? + 1.0)? * 127.5)?.to_dtype(candle::DType::U8)?; diff --git a/candle-examples/examples/stable-diffusion-3/sampling.rs b/candle-examples/examples/stable-diffusion-3/sampling.rs index 0efd160eba..cd881b6a2f 100644 --- a/candle-examples/examples/stable-diffusion-3/sampling.rs +++ b/candle-examples/examples/stable-diffusion-3/sampling.rs @@ -30,7 +30,7 @@ pub fn euler_sample( let timestep = (*s_curr) * 1000.0; let noise_pred = mmdit.forward( - &Tensor::cat(&[x.clone(), x.clone()], 0)?, + &Tensor::cat(&[&x, &x], 0)?, &Tensor::full(timestep as f32, (2,), x.device())?.contiguous()?, y, context,