-
Hi, guies. Cuda 12.0. I was editing image using Instruct pix2pix model.
I tried serveral ways from googling to fix it. But this issus is still remainging. Here are the common ways from googleing.
And also Im not sure how can i reduce batch size in my code and also other ways too. Please help me if you have exact way. Here is my source code
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Hi @alexd725. You can also try these methods to reduce memory usage. |
Beta Was this translation helpful? Give feedback.
-
To answer your questions:
This at inference is when you're using
Not your case because the model is just 3.2 GB.
This is not for inference, is for when you train a model.
These two are probably your case. You only provide a class and not how you're using it, also you don't provide the images or the prompts or what is in I'm on windows right now so I can't use import torch
from diffusers import EulerAncestralDiscreteScheduler, StableDiffusionInstructPix2PixPipeline
from diffusers.utils import load_image
model_id = "timbrooks/instruct-pix2pix"
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16, safety_checker=None)
pipe.to("cuda")
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
image = load_image("https://raw.githubusercontent.com/timothybrooks/instruct-pix2pix/main/imgs/example.jpg")
prompt = "turn him into cyborg"
while True:
images = pipe(prompt, image=image, num_inference_steps=10, image_guidance_scale=1).images
images[0].save("generated.png") The VRAM stays fixed at 4.1 GB and never gets over it. So the problem is not with diffusers but in your code, you're probably loading the model multiple times or using really big images that makes the process use over 12GB more of VRAM than the 512x512 example. |
Beta Was this translation helpful? Give feedback.
-
hi, @alexd725 : Good luck! |
Beta Was this translation helpful? Give feedback.
To answer your questions:
This at inference is when you're using
num_images_per_prompt
which is not your case.Not your case because the model is just 3.2 GB.
This is not for inference, is for when you train a model.
These two are probably your case. You only provide a class and not how you're using it, also you don't provide the images or the prompts or what is in
effects
.I'm on windows right now so I can't use
torch.compile
but if I use just the generation code and do a loop with it: