updated code with xformers for faster inf
Browse files
app.py
CHANGED
@@ -12,9 +12,9 @@ from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDisc
|
|
12 |
model_id = "timbrooks/instruct-pix2pix"
|
13 |
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16") #, safety_checker=None)
|
14 |
pipe.to("cuda")
|
15 |
-
pipe.enable_attention_slicing()
|
16 |
-
|
17 |
-
|
18 |
|
19 |
|
20 |
help_text = """ Some notes from the official [instruct-pix2pix](https://huggingface.co/spaces/timbrooks/instruct-pix2pix) Space by the authors and from the official [Diffusers docs](https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_diffusion/pix2pix) -
|
@@ -71,8 +71,8 @@ def chat(image_in, in_steps, in_guidance_scale, in_img_guidance_scale, image_hid
|
|
71 |
else:
|
72 |
seed = random.randint(0, 1000000)
|
73 |
img_name = f"./edited_image_{seed}.png"
|
74 |
-
#Resizing the image
|
75 |
-
basewidth =
|
76 |
wpercent = (basewidth/float(image_in.size[0]))
|
77 |
hsize = int((float(image_in.size[1])*float(wpercent)))
|
78 |
image_in = image_in.resize((basewidth,hsize), Image.Resampling.LANCZOS)
|
|
|
12 |
model_id = "timbrooks/instruct-pix2pix"
|
13 |
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16") #, safety_checker=None)
|
14 |
pipe.to("cuda")
|
15 |
+
#pipe.enable_attention_slicing()
|
16 |
+
pipe.enable_xformers_memory_efficient_attention()
|
17 |
+
pipe.unet.to(memory_format=torch.channels_last)
|
18 |
|
19 |
|
20 |
help_text = """ Some notes from the official [instruct-pix2pix](https://huggingface.co/spaces/timbrooks/instruct-pix2pix) Space by the authors and from the official [Diffusers docs](https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_diffusion/pix2pix) -
|
|
|
71 |
else:
|
72 |
seed = random.randint(0, 1000000)
|
73 |
img_name = f"./edited_image_{seed}.png"
|
74 |
+
#Resizing the image - 512 or 300 pixels
|
75 |
+
basewidth = 300
|
76 |
wpercent = (basewidth/float(image_in.size[0]))
|
77 |
hsize = int((float(image_in.size[1])*float(wpercent)))
|
78 |
image_in = image_in.resize((basewidth,hsize), Image.Resampling.LANCZOS)
|