Commit
·
f985b1c
1
Parent(s):
e990e13
merge conflict
Browse files- __pycache__/compel.cpython-310.pyc +0 -0
- compel_run.py +31 -0
- image.jpg +0 -0
- run_local_xl.py +19 -10
__pycache__/compel.cpython-310.pyc
ADDED
|
Binary file (552 Bytes). View file
|
|
|
compel_run.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from diffusers import DiffusionPipeline
|
| 3 |
+
from huggingface_hub import HfApi
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from compel import Compel
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
api = HfApi()
|
| 10 |
+
|
| 11 |
+
pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-0.9", variant="fp16", use_safetensors=True, torch_dtype=torch.float16).to("cuda")
|
| 12 |
+
compel = Compel(tokenizer=[pipeline.tokenizer, pipeline.tokenizer_2] , text_encoder=[pipeline.text_encoder, pipeline.text_encoder_2], use_penultimate_clip_layer=True, use_penultimate_layer_norm=False, requires_pooled=[False, True])
|
| 13 |
+
|
| 14 |
+
# upweight "ball"
|
| 15 |
+
prompt = "a cat playing with a ball-- in the forest"
|
| 16 |
+
conditioning, pooled = compel(prompt)
|
| 17 |
+
|
| 18 |
+
# generate image
|
| 19 |
+
image = pipeline(prompt_embeds=conditioning, pooled_prompt_embeds=pooled, num_inference_steps=30).images[0]
|
| 20 |
+
|
| 21 |
+
file_name = f"ball_minus_minus"
|
| 22 |
+
path = os.path.join(Path.home(), "images", f"{file_name}.png")
|
| 23 |
+
image.save(path)
|
| 24 |
+
|
| 25 |
+
api.upload_file(
|
| 26 |
+
path_or_fileobj=path,
|
| 27 |
+
path_in_repo=path.split("/")[-1],
|
| 28 |
+
repo_id="patrickvonplaten/images",
|
| 29 |
+
repo_type="dataset",
|
| 30 |
+
)
|
| 31 |
+
print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/{file_name}.png")
|
image.jpg
ADDED
|
run_local_xl.py
CHANGED
|
@@ -17,26 +17,35 @@ api = HfApi()
|
|
| 17 |
start_time = time.time()
|
| 18 |
|
| 19 |
use_refiner = bool(int(sys.argv[1]))
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
pipe.
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
if use_refiner:
|
| 27 |
-
refiner = StableDiffusionXLImg2ImgPipeline.from_single_file("https://huggingface.co/nichijoufan777/stable-diffusion-xl-refiner-0.9/blob/main/sd_xl_refiner_0.9.safetensors", torch_dtype=torch.float16)
|
| 28 |
-
refiner.to("cuda")
|
| 29 |
|
| 30 |
prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
|
| 31 |
seed_everything(0)
|
| 32 |
-
image = pipe(prompt=prompt, output_type="latent" if use_refiner else "pil").images[0]
|
| 33 |
# image = pipe(prompt=prompt, output_type="latent" if use_refiner else "pil").images[0]
|
| 34 |
|
| 35 |
if use_refiner:
|
| 36 |
-
image = refiner(prompt=prompt, image=image[None, :]).images[0]
|
| 37 |
|
| 38 |
# pipe.unet.to(memory_format=torch.channels_last)
|
| 39 |
-
# pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
| 40 |
# pipe(prompt=prompt, num_inference_steps=2).images[0]
|
| 41 |
|
| 42 |
# image = pipe(prompt=prompt, num_images_per_prompt=1, num_inference_steps=40, output_type="latent").images
|
|
|
|
| 17 |
start_time = time.time()
|
| 18 |
|
| 19 |
use_refiner = bool(int(sys.argv[1]))
|
| 20 |
+
use_diffusers = True
|
| 21 |
|
| 22 |
+
if use_diffusers:
|
| 23 |
+
start_time = time.time()
|
| 24 |
+
pipe = StableDiffusionXLPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-0.9", torch_dtype=torch.float16, variant="fp16", use_safetensors=True, local_files_only=True)
|
| 25 |
+
pipe.to("cuda")
|
| 26 |
+
|
| 27 |
+
if use_refiner:
|
| 28 |
+
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-0.9", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
| 29 |
+
refiner.to("cuda")
|
| 30 |
+
# refiner.enable_sequential_cpu_offload()
|
| 31 |
+
else:
|
| 32 |
+
pipe = StableDiffusionXLPipeline.from_single_file("https://huggingface.co/stabilityai/stable-diffusion-xl-base-0.9/blob/main/sd_xl_base_0.9.safetensors", torch_dtype=torch.float16, use_safetensors=True)
|
| 33 |
+
pipe.to("cuda")
|
| 34 |
+
|
| 35 |
+
if use_refiner:
|
| 36 |
+
refiner = StableDiffusionXLImg2ImgPipeline.from_single_file("https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-0.9/blob/main/sd_xl_refiner_0.9.safetensors", torch_dtype=torch.float16, use_safetensors=True)
|
| 37 |
+
refiner.to("cuda")
|
| 38 |
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
|
| 41 |
seed_everything(0)
|
| 42 |
+
image = pipe(prompt=prompt, num_inference_steps=2, output_type="latent" if use_refiner else "pil").images[0]
|
| 43 |
# image = pipe(prompt=prompt, output_type="latent" if use_refiner else "pil").images[0]
|
| 44 |
|
| 45 |
if use_refiner:
|
| 46 |
+
image = refiner(prompt=prompt, num_inference_steps=5, image=image[None, :]).images[0]
|
| 47 |
|
| 48 |
# pipe.unet.to(memory_format=torch.channels_last)
|
|
|
|
| 49 |
# pipe(prompt=prompt, num_inference_steps=2).images[0]
|
| 50 |
|
| 51 |
# image = pipe(prompt=prompt, num_images_per_prompt=1, num_inference_steps=40, output_type="latent").images
|