From 139ff56aeb1a6bbf0ed742f936a7a96bebccfa30 Mon Sep 17 00:00:00 2001 From: Laurent Mazare Date: Mon, 28 Oct 2024 22:45:02 +0100 Subject: [PATCH] Reduce memory usage for sd 3.5. (#2582) --- candle-examples/examples/stable-diffusion-3/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/candle-examples/examples/stable-diffusion-3/main.rs b/candle-examples/examples/stable-diffusion-3/main.rs index 01b09101a1..d0bf4bb803 100644 --- a/candle-examples/examples/stable-diffusion-3/main.rs +++ b/candle-examples/examples/stable-diffusion-3/main.rs @@ -180,6 +180,8 @@ fn main() -> Result<()> { let (context, y) = triple.encode_text_to_embedding(prompt.as_str(), &device)?; let (context_uncond, y_uncond) = triple.encode_text_to_embedding(uncond_prompt.as_str(), &device)?; + // Drop the text model early to avoid using too much memory. + drop(triple); let context = Tensor::cat(&[context, context_uncond], 0)?; let y = Tensor::cat(&[y, y_uncond], 0)?;