patrickvonplaten
commited on
Commit
•
6c27fdd
1
Parent(s):
9478dd2
all
Browse files- README.md +40 -80
- README_t2i.py +100 -0
- README_t2i_inpaint.py +120 -0
- README_t2i_xl.py +93 -0
- aa_orig_comp (6).png +0 -0
- cd_bedroom256_lpips_onestep_sample.png +0 -0
- fuse_unfuse.py +22 -0
- if_m.py +41 -0
- image.jpg +0 -0
- img2img.py +1 -0
- init_image.png +0 -0
- light_and_shadow.safetensors +0 -3
- load_replicate.py +18 -0
- mask_image.png +0 -0
- monthly_downloads.py +12 -0
- monthly_per_class_downloads.py +14 -0
- new_loading.py +26 -0
- run_kandinsky.py +4 -33
- run_local_fuse_xl.py +17 -18
- run_local_img2img_xl.py +20 -29
- run_local_xl.py +3 -2
- run_local_xl_img2img.py +76 -0
- run_local_xl_simple.py +30 -0
- run_lora.py +5 -7
- run_muse.py +110 -0
- run_muse_256.py +111 -0
- run_sd_text.py +51 -0
- run_sdxl_text_inv.py +14 -0
- run_wuerst.py +40 -35
- run_wuerstchen.py +93 -0
- run_wuerstchen_new.py +18 -0
- run_xl.py +46 -0
- run_xl_lora.py +30 -20
- run_xl_pivotal.py +35 -0
- sd_xl_inpaint.py +10 -48
- upload_new_checkpoint.py +60 -0
README.md
CHANGED
@@ -1,98 +1,58 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
|
5 |
-
|
6 |
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
|
10 |
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
2. Run the following command
|
14 |
```
|
15 |
-
|
16 |
```
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
from diffusers import DiffusionPipeline, StableDiffusionPipeline, DDIMScheduler
|
22 |
import torch
|
|
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
prompt = "a photograph of an astronaut riding a horse"
|
28 |
-
pipe = DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16)
|
29 |
-
|
30 |
pipe = pipe.to("cuda")
|
31 |
-
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
32 |
-
torch.manual_seed(0)
|
33 |
-
image = pipe(prompt, num_inference_steps=50).images[0]
|
34 |
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
|
|
39 |
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
You can run the following script to compare against k-diffusion.
|
44 |
-
|
45 |
-
See results [here](https://huggingface.co/datasets/patrickvonplaten/images)
|
46 |
-
|
47 |
-
```python
|
48 |
-
from diffusers import StableDiffusionKDiffusionPipeline, HeunDiscreteScheduler, StableDiffusionPipeline, DPMSolverMultistepScheduler, EulerDiscreteScheduler, LMSDiscreteScheduler
|
49 |
-
import torch
|
50 |
-
import os
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
checkpoint = "stabilityai/stable-diffusion-2-1"
|
56 |
-
prompts = ["astronaut riding horse", "whale falling from sky", "magical forest", "highly photorealistic picture of johnny depp"]
|
57 |
-
prompts = 8 * ["highly photorealistic picture of johnny depp"]
|
58 |
-
#prompts = prompts[:1]
|
59 |
-
samplers = ["sample_dpmpp_2m", "sample_euler", "sample_heun", "sample_dpm_2", "sample_lms"]
|
60 |
-
#samplers = samplers[:1]
|
61 |
-
|
62 |
-
pipe = StableDiffusionKDiffusionPipeline.from_pretrained(checkpoint, torch_dtype=torch.float16, safety_checker=None)
|
63 |
-
pipe = pipe.to("cuda")
|
64 |
-
|
65 |
-
for i, prompt in enumerate(prompts):
|
66 |
-
prompt_f = f"{'_'.join(prompt.split())}_{i}"
|
67 |
-
for sampler in samplers:
|
68 |
-
pipe.set_scheduler(sampler)
|
69 |
-
torch.manual_seed(seed + i)
|
70 |
-
image = pipe(prompt, num_inference_steps=inference_steps).images[0]
|
71 |
-
checkpoint_f = f"{'--'.join(checkpoint.split('/'))}"
|
72 |
-
os.makedirs(f"/home/patrick_huggingface_co/images/{checkpoint_f}", exist_ok=True)
|
73 |
-
os.makedirs(f"/home/patrick_huggingface_co/images/{checkpoint_f}/{sampler}", exist_ok=True)
|
74 |
-
image.save(f"/home/patrick_huggingface_co/images/{checkpoint_f}/{sampler}/{prompt_f}.png")
|
75 |
-
|
76 |
-
|
77 |
-
pipe = StableDiffusionPipeline(**pipe.components)
|
78 |
-
pipe = pipe.to("cuda")
|
79 |
-
|
80 |
-
for i, prompt in enumerate(prompts):
|
81 |
-
prompt_f = f"{'_'.join(prompt.split())}_{i}"
|
82 |
-
for sampler in samplers:
|
83 |
-
if sampler == "sample_euler":
|
84 |
-
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
85 |
-
elif sampler == "sample_heun":
|
86 |
-
pipe.scheduler = HeunDiscreteScheduler.from_config(pipe.scheduler.config)
|
87 |
-
elif sampler == "sample_dpmpp_2m":
|
88 |
-
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
89 |
-
elif sampler == "sample_lms":
|
90 |
-
pipe.scheduler = LMSDiscreteScheduler.from_config(pipe.scheduler.config)
|
91 |
-
|
92 |
-
torch.manual_seed(seed + i)
|
93 |
-
image = pipe(prompt, num_inference_steps=inference_steps).images[0]
|
94 |
-
checkpoint_f = f"{'--'.join(checkpoint.split('/'))}"
|
95 |
-
os.makedirs("/home/patrick_huggingface_co/images/{checkpoint_f}", exist_ok=True)
|
96 |
-
os.makedirs(f"/home/patrick_huggingface_co/images/{checkpoint_f}/{sampler}", exist_ok=True)
|
97 |
-
image.save(f"/home/patrick_huggingface_co/images/{checkpoint_f}/{sampler}/{prompt_f}_hf.png")
|
98 |
```
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
license: creativeml-openrail-m
|
5 |
+
tags:
|
6 |
+
- stable-diffusion
|
7 |
+
- stable-diffusion-diffusers
|
8 |
+
- inpainting
|
9 |
+
- art
|
10 |
+
- artistic
|
11 |
+
- diffusers
|
12 |
+
- anime
|
13 |
+
- absolute-realism
|
14 |
+
---
|
15 |
|
16 |
+
# Absolute realism 1.6525 inpainting
|
17 |
|
18 |
+
`lykon-absolute-realism/absolute-realism-1.6525-inpainting` is a Stable Diffusion Inpainting model that has been fine-tuned on [runwayml/stable-diffusion-inpainting](https://huggingface.co/runwayml/stable-diffusion-inpainting).
|
19 |
|
20 |
+
Please consider supporting me:
|
21 |
+
- on [Patreon](https://www.patreon.com/Lykon275)
|
22 |
+
- or [buy me a coffee](https://snipfeed.co/lykon)
|
23 |
|
24 |
+
## Diffusers
|
25 |
|
26 |
+
For more general information on how to run inpainting models with 🧨 Diffusers, see [the docs](https://huggingface.co/docs/diffusers/using-diffusers/inpaint).
|
27 |
+
|
28 |
+
1. Installation
|
29 |
|
|
|
30 |
```
|
31 |
+
pip install diffusers transformers accelerate
|
32 |
```
|
33 |
|
34 |
+
2. Run
|
35 |
+
```py
|
36 |
+
from diffusers import AutoPipelineForInpainting, DEISMultistepScheduler
|
|
|
37 |
import torch
|
38 |
+
from diffusers.utils import load_image
|
39 |
|
40 |
+
pipe = AutoPipelineForInpainting.from_pretrained('lykon-absolute-realism/absolute-realism-1.6525-inpainting', torch_dtype=torch.float16, variant="fp16")
|
41 |
+
pipe.scheduler = DEISMultistepScheduler.from_config(pipe.scheduler.config)
|
|
|
|
|
|
|
|
|
42 |
pipe = pipe.to("cuda")
|
|
|
|
|
|
|
43 |
|
44 |
+
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
|
45 |
+
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
|
46 |
|
47 |
+
image = load_image(img_url)
|
48 |
+
mask_image = load_image(mask_url)
|
49 |
|
50 |
|
51 |
+
prompt = "a majestic tiger sitting on a park bench"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
+
generator = torch.manual_seed(33)
|
54 |
+
image = pipe(prompt, image=image, mask_image=mask_image, generator=generator, num_inference_steps=25).images[0]
|
55 |
+
image.save("./image.png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
```
|
57 |
+
|
58 |
+
![](./image.png)
|
README_t2i.py
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
|
3 |
+
model_name = sys.argv[1]
|
4 |
+
|
5 |
+
model_card = f"""---
|
6 |
+
language:
|
7 |
+
- en
|
8 |
+
license: creativeml-openrail-m
|
9 |
+
tags:
|
10 |
+
- stable-diffusion
|
11 |
+
- stable-diffusion-diffusers
|
12 |
+
- text-to-image
|
13 |
+
- art
|
14 |
+
- artistic
|
15 |
+
- diffusers
|
16 |
+
- absolute_realism
|
17 |
+
---
|
18 |
+
|
19 |
+
# {model_name.split("/")[-1].replace("-", " ").capitalize()}
|
20 |
+
|
21 |
+
`{model_name}` is a Stable Diffusion model that has been fine-tuned on [runwayml/stable-diffusion-v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5).
|
22 |
+
|
23 |
+
Please consider supporting me:
|
24 |
+
- on [Patreon](https://www.patreon.com/Lykon275)
|
25 |
+
- or [buy me a coffee](https://snipfeed.co/lykon)
|
26 |
+
|
27 |
+
## Diffusers
|
28 |
+
|
29 |
+
For more general information on how to run text-to-image models with 🧨 Diffusers, see [the docs](https://huggingface.co/docs/diffusers/using-diffusers/conditional_image_generation).
|
30 |
+
|
31 |
+
1. Installation
|
32 |
+
|
33 |
+
```
|
34 |
+
pip install diffusers transformers accelerate
|
35 |
+
```
|
36 |
+
|
37 |
+
2. Run
|
38 |
+
```py
|
39 |
+
from diffusers import AutoPipelineForText2Image, DEISMultistepScheduler
|
40 |
+
import torch
|
41 |
+
|
42 |
+
pipe = AutoPipelineForText2Image.from_pretrained('{model_name}', torch_dtype=torch.float16, variant="fp16")
|
43 |
+
pipe.scheduler = DEISMultistepScheduler.from_config(pipe.scheduler.config)
|
44 |
+
pipe = pipe.to("cuda")
|
45 |
+
|
46 |
+
prompt = "portrait photo of muscular bearded guy in a worn mech suit, light bokeh, intricate, steel metal, elegant, sharp focus, soft lighting, vibrant colors"
|
47 |
+
|
48 |
+
generator = torch.manual_seed(33)
|
49 |
+
image = pipe(prompt, generator=generator, num_inference_steps=25).images[0]
|
50 |
+
image.save("./image.png")
|
51 |
+
```
|
52 |
+
"""
|
53 |
+
|
54 |
+
"""
|
55 |
+
## Notes
|
56 |
+
|
57 |
+
- **Version 8** focuses on improving what V7 started. Might be harder to do photorealism compared to realism focused models, as it might be hard to do anime compared to anime focused models, but it can do both pretty well if you're skilled enough. Check the examples!
|
58 |
+
- **Version 7** improves lora support, NSFW and realism. If you're interested in "absolute" realism, try AbsoluteReality.
|
59 |
+
- **Version 6** adds more lora support and more style in general. It should also be better at generating directly at 1024 height (but be careful with it). 6.x are all improvements.
|
60 |
+
- **Version 5** is the best at photorealism and has noise offset.
|
61 |
+
- **Version 4** is much better with anime (can do them with no LoRA) and booru tags. It might be harder to control if you're used to caption style, so you might still want to use version 3.31. V4 is also better with eyes at lower resolutions. Overall is like a "fix" of V3 and shouldn't be too much different.
|
62 |
+
"""
|
63 |
+
from huggingface_hub import HfApi
|
64 |
+
api = HfApi()
|
65 |
+
|
66 |
+
read_me_path = "./README.md"
|
67 |
+
with open(read_me_path, "w") as f:
|
68 |
+
f.write(model_card)
|
69 |
+
|
70 |
+
api.upload_file(
|
71 |
+
path_or_fileobj=read_me_path,
|
72 |
+
path_in_repo=read_me_path,
|
73 |
+
repo_id=model_name,
|
74 |
+
repo_type="model",
|
75 |
+
)
|
76 |
+
|
77 |
+
from diffusers import AutoPipelineForText2Image, DEISMultistepScheduler
|
78 |
+
import torch
|
79 |
+
|
80 |
+
pipe = AutoPipelineForText2Image.from_pretrained(model_name, torch_dtype=torch.float16)
|
81 |
+
pipe.scheduler = DEISMultistepScheduler.from_config(pipe.scheduler.config)
|
82 |
+
|
83 |
+
pipe = pipe.to("cuda")
|
84 |
+
|
85 |
+
prompt = "portrait photo of muscular bearded guy in a worn mech suit, light bokeh, intricate, steel metal, elegant, sharp focus, soft lighting, vibrant colors"
|
86 |
+
|
87 |
+
generator = torch.manual_seed(33)
|
88 |
+
image = pipe(prompt, generator=generator, num_inference_steps=25).images[0]
|
89 |
+
image_path = "./image.png"
|
90 |
+
|
91 |
+
image.save(image_path)
|
92 |
+
|
93 |
+
api.upload_file(
|
94 |
+
path_or_fileobj=image_path,
|
95 |
+
path_in_repo=image_path,
|
96 |
+
repo_id=model_name,
|
97 |
+
repo_type="model",
|
98 |
+
)
|
99 |
+
|
100 |
+
pipe.push_to_hub(model_name, variant="fp16")
|
README_t2i_inpaint.py
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
|
3 |
+
model_name = sys.argv[1]
|
4 |
+
|
5 |
+
model_card = f"""---
|
6 |
+
language:
|
7 |
+
- en
|
8 |
+
license: creativeml-openrail-m
|
9 |
+
tags:
|
10 |
+
- stable-diffusion
|
11 |
+
- stable-diffusion-diffusers
|
12 |
+
- inpainting
|
13 |
+
- art
|
14 |
+
- artistic
|
15 |
+
- diffusers
|
16 |
+
- anime
|
17 |
+
- absolute-realism
|
18 |
+
---
|
19 |
+
|
20 |
+
# {model_name.split("/")[-1].replace("-", " ").capitalize()}
|
21 |
+
|
22 |
+
`{model_name}` is a Stable Diffusion Inpainting model that has been fine-tuned on [runwayml/stable-diffusion-inpainting](https://huggingface.co/runwayml/stable-diffusion-inpainting).
|
23 |
+
|
24 |
+
Please consider supporting me:
|
25 |
+
- on [Patreon](https://www.patreon.com/Lykon275)
|
26 |
+
- or [buy me a coffee](https://snipfeed.co/lykon)
|
27 |
+
|
28 |
+
## Diffusers
|
29 |
+
|
30 |
+
For more general information on how to run inpainting models with 🧨 Diffusers, see [the docs](https://huggingface.co/docs/diffusers/using-diffusers/inpaint).
|
31 |
+
|
32 |
+
1. Installation
|
33 |
+
|
34 |
+
```
|
35 |
+
pip install diffusers transformers accelerate
|
36 |
+
```
|
37 |
+
|
38 |
+
2. Run
|
39 |
+
```py
|
40 |
+
from diffusers import AutoPipelineForInpainting, DEISMultistepScheduler
|
41 |
+
import torch
|
42 |
+
from diffusers.utils import load_image
|
43 |
+
|
44 |
+
pipe = AutoPipelineForInpainting.from_pretrained('{model_name}', torch_dtype=torch.float16, variant="fp16")
|
45 |
+
pipe.scheduler = DEISMultistepScheduler.from_config(pipe.scheduler.config)
|
46 |
+
pipe = pipe.to("cuda")
|
47 |
+
|
48 |
+
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
|
49 |
+
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
|
50 |
+
|
51 |
+
image = load_image(img_url)
|
52 |
+
mask_image = load_image(mask_url)
|
53 |
+
|
54 |
+
|
55 |
+
prompt = "a majestic tiger sitting on a park bench"
|
56 |
+
|
57 |
+
generator = torch.manual_seed(33)
|
58 |
+
image = pipe(prompt, image=image, mask_image=mask_image, generator=generator, num_inference_steps=25).images[0]
|
59 |
+
image.save("./image.png")
|
60 |
+
```
|
61 |
+
|
62 |
+
![](./image.png)
|
63 |
+
"""
|
64 |
+
|
65 |
+
"""
|
66 |
+
## Notes
|
67 |
+
|
68 |
+
- **Version 8** focuses on improving what V7 started. Might be harder to do photorealism compared to realism focused models, as it might be hard to do anime compared to anime focused models, but it can do both pretty well if you're skilled enough. Check the examples!
|
69 |
+
- **Version 7** improves lora support, NSFW and realism. If you're interested in "absolute" realism, try AbsoluteReality.
|
70 |
+
- **Version 6** adds more lora support and more style in general. It should also be better at generating directly at 1024 height (but be careful with it). 6.x are all improvements.
|
71 |
+
- **Version 5** is the best at photorealism and has noise offset.
|
72 |
+
- **Version 4** is much better with anime (can do them with no LoRA) and booru tags. It might be harder to control if you're used to caption style, so you might still want to use version 3.31. V4 is also better with eyes at lower resolutions. Overall is like a "fix" of V3 and shouldn't be too much different.
|
73 |
+
"""
|
74 |
+
from huggingface_hub import HfApi
|
75 |
+
api = HfApi()
|
76 |
+
|
77 |
+
read_me_path = "./README.md"
|
78 |
+
with open(read_me_path, "w") as f:
|
79 |
+
f.write(model_card)
|
80 |
+
|
81 |
+
api.upload_file(
|
82 |
+
path_or_fileobj=read_me_path,
|
83 |
+
path_in_repo=read_me_path,
|
84 |
+
repo_id=model_name,
|
85 |
+
repo_type="model",
|
86 |
+
)
|
87 |
+
|
88 |
+
from diffusers import AutoPipelineForInpainting, DEISMultistepScheduler
|
89 |
+
import torch
|
90 |
+
from diffusers.utils import load_image
|
91 |
+
|
92 |
+
pipe = AutoPipelineForInpainting.from_pretrained(model_name, torch_dtype=torch.float16, variant="fp16")
|
93 |
+
pipe.scheduler = DEISMultistepScheduler.from_config(pipe.scheduler.config)
|
94 |
+
pipe = pipe.to("cuda")
|
95 |
+
|
96 |
+
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
|
97 |
+
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
|
98 |
+
|
99 |
+
image = load_image(img_url)
|
100 |
+
mask_image = load_image(mask_url)
|
101 |
+
|
102 |
+
|
103 |
+
prompt = "a majestic tiger sitting on a park bench"
|
104 |
+
|
105 |
+
generator = torch.manual_seed(33)
|
106 |
+
image = pipe(prompt, image=image, mask_image=mask_image, generator=generator, num_inference_steps=25).images[0]
|
107 |
+
image.save("./image.png")
|
108 |
+
|
109 |
+
image_path = "./image.png"
|
110 |
+
|
111 |
+
image.save(image_path)
|
112 |
+
|
113 |
+
api.upload_file(
|
114 |
+
path_or_fileobj=image_path,
|
115 |
+
path_in_repo=image_path,
|
116 |
+
repo_id=model_name,
|
117 |
+
repo_type="model",
|
118 |
+
)
|
119 |
+
|
120 |
+
pipe.push_to_hub(model_name, variant="fp16")
|
README_t2i_xl.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
|
3 |
+
model_name = sys.argv[1]
|
4 |
+
|
5 |
+
model_card = f"""---
|
6 |
+
language:
|
7 |
+
- en
|
8 |
+
license: openrail++
|
9 |
+
tags:
|
10 |
+
- stable-diffusion
|
11 |
+
- stable-diffusion-diffusers
|
12 |
+
- stable-diffusion-xl
|
13 |
+
- text-to-image
|
14 |
+
- art
|
15 |
+
- artistic
|
16 |
+
- diffusers
|
17 |
+
- anime
|
18 |
+
---
|
19 |
+
|
20 |
+
# {model_name.split("/")[-1].replace("-", " ").capitalize()}
|
21 |
+
|
22 |
+
`{model_name}` is a Stable Diffusion model that has been fine-tuned on [stabilityai/stable-diffusion-xl-base-1.0](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0).
|
23 |
+
|
24 |
+
Please consider supporting me:
|
25 |
+
- on [Patreon](https://www.patreon.com/Lykon275)
|
26 |
+
- or [buy me a coffee](https://snipfeed.co/lykon)
|
27 |
+
|
28 |
+
## Diffusers
|
29 |
+
|
30 |
+
For more general information on how to run text-to-image models with 🧨 Diffusers, see [the docs](https://huggingface.co/docs/diffusers/using-diffusers/conditional_image_generation).
|
31 |
+
|
32 |
+
1. Installation
|
33 |
+
|
34 |
+
```
|
35 |
+
pip install diffusers transformers accelerate
|
36 |
+
```
|
37 |
+
|
38 |
+
2. Run
|
39 |
+
```py
|
40 |
+
from diffusers import AutoPipelineForText2Image, DEISMultistepScheduler
|
41 |
+
import torch
|
42 |
+
|
43 |
+
pipe = AutoPipelineForText2Image.from_pretrained('{model_name}', torch_dtype=torch.float16, variant="fp16")
|
44 |
+
pipe.scheduler = DEISMultistepScheduler.from_config(pipe.scheduler.config)
|
45 |
+
pipe = pipe.to("cuda")
|
46 |
+
|
47 |
+
prompt = "portrait photo of muscular bearded guy in a worn mech suit, light bokeh, intricate, steel metal, elegant, sharp focus, soft lighting, vibrant colors"
|
48 |
+
|
49 |
+
generator = torch.manual_seed(0)
|
50 |
+
image = pipe(prompt, num_inference_steps=25).images[0]
|
51 |
+
image.save("./image.png")
|
52 |
+
```
|
53 |
+
|
54 |
+
![](./image.png)
|
55 |
+
"""
|
56 |
+
from huggingface_hub import HfApi
|
57 |
+
api = HfApi()
|
58 |
+
|
59 |
+
read_me_path = "./README.md"
|
60 |
+
with open(read_me_path, "w") as f:
|
61 |
+
f.write(model_card)
|
62 |
+
|
63 |
+
api.upload_file(
|
64 |
+
path_or_fileobj=read_me_path,
|
65 |
+
path_in_repo=read_me_path,
|
66 |
+
repo_id=model_name,
|
67 |
+
repo_type="model",
|
68 |
+
)
|
69 |
+
|
70 |
+
from diffusers import AutoPipelineForText2Image, DEISMultistepScheduler
|
71 |
+
import torch
|
72 |
+
|
73 |
+
pipe = AutoPipelineForText2Image.from_pretrained(model_name, torch_dtype=torch.float16)
|
74 |
+
pipe.scheduler = DEISMultistepScheduler.from_config(pipe.scheduler.config)
|
75 |
+
|
76 |
+
pipe = pipe.to("cuda")
|
77 |
+
|
78 |
+
prompt = "portrait photo of muscular bearded guy in a worn mech suit, light bokeh, intricate, steel metal, elegant, sharp focus, soft lighting, vibrant colors"
|
79 |
+
|
80 |
+
generator = torch.manual_seed(0)
|
81 |
+
image = pipe(prompt, num_inference_steps=25).images[0]
|
82 |
+
image_path = "./image.png"
|
83 |
+
|
84 |
+
image.save(image_path)
|
85 |
+
|
86 |
+
api.upload_file(
|
87 |
+
path_or_fileobj=image_path,
|
88 |
+
path_in_repo=image_path,
|
89 |
+
repo_id=model_name,
|
90 |
+
repo_type="model",
|
91 |
+
)
|
92 |
+
|
93 |
+
pipe.push_to_hub(model_name, variant="fp16")
|
aa_orig_comp (6).png
DELETED
Binary file (501 kB)
|
|
cd_bedroom256_lpips_onestep_sample.png
DELETED
Binary file (120 kB)
|
|
fuse_unfuse.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import torch
|
3 |
+
from diffusers import StableDiffusionXLPipeline
|
4 |
+
|
5 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(
|
6 |
+
"stabilityai/stable-diffusion-xl-base-1.0",
|
7 |
+
torch_dtype=torch.float16,
|
8 |
+
).to("cuda")
|
9 |
+
|
10 |
+
#Fuse/unfuse first LoRA
|
11 |
+
pipe.load_lora_weights("joachimsallstrom/aether-cloud-lora-for-sdxl")
|
12 |
+
pipe.fuse_lora()
|
13 |
+
pipe.unload_lora_weights()
|
14 |
+
pipe.unfuse_lora()
|
15 |
+
|
16 |
+
#Now it would be expected that the the LoRA has been unfused and `pipe` in the its original state, however...
|
17 |
+
|
18 |
+
#Fuse/unfuse second LoRA
|
19 |
+
pipe.load_lora_weights("jbilcke-hf/sdxl-zelda64")
|
20 |
+
pipe.fuse_lora()
|
21 |
+
pipe.unload_lora_weights()
|
22 |
+
pipe.unfuse_lora() #errors out
|
if_m.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from diffusers import DiffusionPipeline
|
3 |
+
from diffusers.utils import pt_to_pil
|
4 |
+
import torch
|
5 |
+
|
6 |
+
# stage 1
|
7 |
+
stage_1 = DiffusionPipeline.from_pretrained("DeepFloyd/IF-I-M-v1.0", variant="fp16", torch_dtype=torch.float16)
|
8 |
+
stage_1.enable_xformers_memory_efficient_attention() # remove line if torch.__version__ >= 2.0.0
|
9 |
+
stage_1.enable_model_cpu_offload()
|
10 |
+
|
11 |
+
# stage 2
|
12 |
+
stage_2 = DiffusionPipeline.from_pretrained(
|
13 |
+
"DeepFloyd/IF-II-M-v1.0", text_encoder=None, variant="fp16", torch_dtype=torch.float16
|
14 |
+
)
|
15 |
+
stage_2.enable_xformers_memory_efficient_attention() # remove line if torch.__version__ >= 2.0.0
|
16 |
+
stage_2.enable_model_cpu_offload()
|
17 |
+
|
18 |
+
# stage 3
|
19 |
+
safety_modules = {"feature_extractor": stage_1.feature_extractor, "safety_checker": stage_1.safety_checker, "watermarker": stage_1.watermarker}
|
20 |
+
stage_3 = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-x4-upscaler", **safety_modules, torch_dtype=torch.float16)
|
21 |
+
stage_3.enable_xformers_memory_efficient_attention() # remove line if torch.__version__ >= 2.0.0
|
22 |
+
stage_3.enable_model_cpu_offload()
|
23 |
+
|
24 |
+
prompt = 'a photo of a kangaroo wearing an orange hoodie and blue sunglasses standing in front of the eiffel tower holding a sign that says "very deep learning"'
|
25 |
+
|
26 |
+
# text embeds
|
27 |
+
prompt_embeds, negative_embeds = stage_1.encode_prompt(prompt)
|
28 |
+
|
29 |
+
generator = torch.manual_seed(0)
|
30 |
+
|
31 |
+
image = stage_1(prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_embeds, generator=generator, output_type="pt").images
|
32 |
+
pt_to_pil(image)[0].save("./if_stage_I.png")
|
33 |
+
|
34 |
+
image = stage_2(
|
35 |
+
image=image, prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_embeds, generator=generator, output_type="pt"
|
36 |
+
).images
|
37 |
+
pt_to_pil(image)[0].save("./if_stage_II.png")
|
38 |
+
|
39 |
+
image = stage_3(prompt=prompt, image=image, generator=generator, noise_level=100).images
|
40 |
+
image[0].save("./if_stage_III.png")
|
41 |
+
|
image.jpg
DELETED
Binary file (102 kB)
|
|
img2img.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
init_image.png
DELETED
Binary file (407 kB)
|
|
light_and_shadow.safetensors
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:15a630ab2255460b2e99b1e5a6765a1cedcd210e2ffca32474bd02df24232624
|
3 |
-
size 151110122
|
|
|
|
|
|
|
|
load_replicate.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
#!/usr/bin/env python3
|
3 |
+
from diffusers import StableDiffusionXLPipeline, AutoencoderKL
|
4 |
+
import torch
|
5 |
+
|
6 |
+
path = "stabilityai/stable-diffusion-xl-base-1.0"
|
7 |
+
vae_path = "madebyollin/sdxl-vae-fp16-fix"
|
8 |
+
|
9 |
+
# vae = AutoencoderKL.from_pretrained(vae_path, torch_dtype=torch.float16)
|
10 |
+
# pipe = StableDiffusionXLPipeline.from_pretrained(path, torch_dtype=torch.float16, vae=vae, variant="fp16", use_safetensors=True, local_files_only=True, add_watermarker=False)
|
11 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(path, torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
12 |
+
pipe.to("cuda")
|
13 |
+
|
14 |
+
prompt = "An astronaut riding a green horse on Mars"
|
15 |
+
steps = 20
|
16 |
+
|
17 |
+
for _ in range(5):
|
18 |
+
image = pipe(prompt=prompt, num_inference_steps=steps).images[0]
|
mask_image.png
DELETED
Binary file (11.9 kB)
|
|
monthly_downloads.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from huggingface_hub import HfApi, ModelFilter
|
3 |
+
|
4 |
+
api = HfApi()
|
5 |
+
|
6 |
+
filter = ModelFilter(library="diffusers")
|
7 |
+
|
8 |
+
models = api.list_models(filter=filter)
|
9 |
+
|
10 |
+
downloads = sum(m.downloads for m in models)
|
11 |
+
|
12 |
+
print(downloads)
|
monthly_per_class_downloads.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from huggingface_hub import HfApi, ModelFilter
|
3 |
+
|
4 |
+
api = HfApi()
|
5 |
+
|
6 |
+
filter = ModelFilter(library="diffusers")
|
7 |
+
|
8 |
+
models = api.list_models(filter=filter)
|
9 |
+
|
10 |
+
import ipdb; ipdb.set_trace()
|
11 |
+
|
12 |
+
downloads = sum(m.downloads for m in models)
|
13 |
+
|
14 |
+
print(downloads)
|
new_loading.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import time
|
3 |
+
import torch
|
4 |
+
import safetensors.torch
|
5 |
+
from diffusers import StableDiffusionXLPipeline
|
6 |
+
|
7 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(
|
8 |
+
"stabilityai/stable-diffusion-xl-base-1.0",
|
9 |
+
torch_dtype=torch.float16,
|
10 |
+
variant="fp16",
|
11 |
+
use_safetensors=True,
|
12 |
+
local_files_only=True,
|
13 |
+
)
|
14 |
+
|
15 |
+
pipe = pipe.to("cuda")
|
16 |
+
|
17 |
+
# !wget https://civitai.com/api/download/models/135931 -O loras/pixel-art-xl.safetensors
|
18 |
+
lora_weights = safetensors.torch.load_file(
|
19 |
+
"pixel-art-xl.safetensors", device="cpu"
|
20 |
+
)
|
21 |
+
|
22 |
+
for _ in range(5):
|
23 |
+
t0 = time.perf_counter()
|
24 |
+
pipe.load_lora_weights(lora_weights.copy())
|
25 |
+
pipe.unload_lora_weights()
|
26 |
+
print("Load + unload cycle took: ", time.perf_counter() - t0)
|
run_kandinsky.py
CHANGED
@@ -1,36 +1,7 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
-
from diffusers import DiffusionPipeline, KandinskyPriorPipeline, DDPMScheduler, DDIMScheduler
|
3 |
import torch
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
api = HfApi()
|
10 |
-
|
11 |
-
pipe_prior = KandinskyPriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-prior", torch_dtype=torch.float16)
|
12 |
-
pipe_prior.to("cuda")
|
13 |
-
|
14 |
-
prompt = "A alien cheeseburger creature eating itself, claymation, cinematic, moody lighting"
|
15 |
-
negative_prompt = "low quality, bad quality"
|
16 |
-
|
17 |
-
generator = torch.Generator(device="cuda").manual_seed(10)
|
18 |
-
image_embeds, negative_image_embeds = pipe_prior(prompt, negative_prompt, guidance_scale=1.0, generator=generator).to_tuple()
|
19 |
-
|
20 |
-
t2i_pipe = DiffusionPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
|
21 |
-
t2i_pipe.to("cuda")
|
22 |
-
print(t2i_pipe.scheduler.config)
|
23 |
-
|
24 |
-
images = t2i_pipe(prompt, num_images_per_prompt=4, image_embeds=image_embeds, negative_image_embeds=negative_image_embeds, negative_prompt=negative_prompt).images
|
25 |
-
|
26 |
-
for i, image in enumerate(images):
|
27 |
-
path = os.path.join(Path.home(), "images", f"aa_{i}.png")
|
28 |
-
image.save(path)
|
29 |
-
|
30 |
-
api.upload_file(
|
31 |
-
path_or_fileobj=path,
|
32 |
-
path_in_repo=path.split("/")[-1],
|
33 |
-
repo_id="patrickvonplaten/images",
|
34 |
-
repo_type="dataset",
|
35 |
-
)
|
36 |
-
print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/aa_{i}.png")
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
+
from diffusers import AutoPipelineForInpainting, AutoPipelineForText2Image, DiffusionPipeline, KandinskyPriorPipeline, DDPMScheduler, DDIMScheduler
|
3 |
import torch
|
4 |
|
5 |
+
cache_dir = DiffusionPipeline.download("kandinsky-community/kandinsky-2-2-decoder", torch_dtype=torch.float16, variant="fp16", load_connected_pipeline=True)
|
6 |
+
print(cache_dir)
|
7 |
+
pipe = DiffusionPipeline.from_pretrained(cache_dir, load_connected_pipeline=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
run_local_fuse_xl.py
CHANGED
@@ -1,38 +1,37 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
-
from huggingface_hub import HfApi
|
3 |
import torch
|
4 |
-
from pathlib import Path
|
5 |
-
import os
|
6 |
import time
|
|
|
7 |
|
8 |
-
api = HfApi()
|
9 |
start_time = time.time()
|
10 |
|
11 |
from diffusers import DiffusionPipeline
|
12 |
import torch
|
13 |
|
14 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
|
15 |
-
pipe.load_lora_weights("stabilityai/stable-diffusion-xl-base-1.0", weight_name="sd_xl_offset_example-lora_1.0.safetensors")
|
16 |
-
# pipe.unet.fuse_lora()
|
17 |
|
18 |
pipe.to(torch_dtype=torch.float16)
|
19 |
pipe.to("cuda")
|
20 |
|
21 |
torch.manual_seed(33)
|
22 |
|
23 |
-
prompt = "
|
24 |
negative_prompt = "text, watermark"
|
25 |
|
|
|
26 |
image = pipe(prompt, negative_prompt=negative_prompt, num_inference_steps=25).images[0]
|
|
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
1 |
#!/usr/bin/env python3
|
|
|
2 |
import torch
|
|
|
|
|
3 |
import time
|
4 |
+
import hf_image_uploader as hiu
|
5 |
|
|
|
6 |
start_time = time.time()
|
7 |
|
8 |
from diffusers import DiffusionPipeline
|
9 |
import torch
|
10 |
|
11 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
|
|
|
|
|
12 |
|
13 |
pipe.to(torch_dtype=torch.float16)
|
14 |
pipe.to("cuda")
|
15 |
|
16 |
torch.manual_seed(33)
|
17 |
|
18 |
+
prompt = "a mecha robot"
|
19 |
negative_prompt = "text, watermark"
|
20 |
|
21 |
+
torch.manual_seed(0)
|
22 |
image = pipe(prompt, negative_prompt=negative_prompt, num_inference_steps=25).images[0]
|
23 |
+
hiu.upload(image, "patrickvonplaten/images")
|
24 |
|
25 |
+
pipe.load_lora_weights("davizca87/sun-flower", weight_name="snfw3rXL-000004.safetensors")
|
26 |
+
pipe.fuse_lora()
|
27 |
+
pipe.unload_lora_weights()
|
28 |
+
|
29 |
+
torch.manual_seed(0)
|
30 |
+
image = pipe(prompt, negative_prompt=negative_prompt, num_inference_steps=25).images[0]
|
31 |
+
hiu.upload(image, "patrickvonplaten/images")
|
32 |
+
|
33 |
+
pipe.unfuse_lora()
|
34 |
+
|
35 |
+
torch.manual_seed(0)
|
36 |
+
image = pipe(prompt, negative_prompt=negative_prompt, num_inference_steps=25).images[0]
|
37 |
+
hiu.upload(image, "patrickvonplaten/images")
|
run_local_img2img_xl.py
CHANGED
@@ -1,16 +1,11 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
-
from diffusers import
|
3 |
import time
|
|
|
4 |
import numpy as np
|
5 |
-
import os
|
6 |
from huggingface_hub import HfApi
|
7 |
-
# from compel import Compel
|
8 |
import torch
|
9 |
import sys
|
10 |
-
from pathlib import Path
|
11 |
-
import requests
|
12 |
-
from PIL import Image
|
13 |
-
from io import BytesIO
|
14 |
|
15 |
path = sys.argv[1]
|
16 |
|
@@ -18,34 +13,30 @@ api = HfApi()
|
|
18 |
start_time = time.time()
|
19 |
pipe = StableDiffusionXLImg2ImgPipeline.from_pretrained(path, torch_dtype=torch.float16)
|
20 |
pipe.to("cuda")
|
21 |
-
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
22 |
-
# pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
23 |
-
# pipe = StableDiffusionImg2ImgXLPipeline.from_pretrained(path, torch_dtype=torch.float16, safety_checker=None
|
24 |
-
|
25 |
-
# compel = Compel(tokenizer=pipe.tokenizer, text_encoder=pipe.text_encoder)
|
26 |
|
27 |
|
28 |
prompt = "An astronaut riding a green horse on Mars"
|
29 |
|
30 |
|
31 |
-
# pipe.unet.to(memory_format=torch.channels_last)
|
32 |
-
# pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
33 |
-
# pipe(prompt=prompt, num_inference_steps=2).images[0]
|
34 |
-
# url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
|
35 |
-
#
|
36 |
-
# response = requests.get(url)
|
37 |
init_image = torch.from_numpy(np.load("/home/patrick/images/xl_latents.npy")).to("cuda")
|
38 |
|
39 |
-
image = pipe(prompt=prompt, image=init_image).images[0]
|
40 |
|
41 |
-
file_name = f"aaa"
|
42 |
-
path = os.path.join(Path.home(), "images", f"{file_name}.png")
|
43 |
-
image.save(path)
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
)
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
+
from diffusers import StableDiffusionXLImg2ImgPipeline, EulerDiscreteScheduler, UniPCMultistepScheduler, DEISMultistepScheduler, HeunDiscreteScheduler, DPMSolverMultistepScheduler
|
3 |
import time
|
4 |
+
import hf_image_uploader as hiu
|
5 |
import numpy as np
|
|
|
6 |
from huggingface_hub import HfApi
|
|
|
7 |
import torch
|
8 |
import sys
|
|
|
|
|
|
|
|
|
9 |
|
10 |
path = sys.argv[1]
|
11 |
|
|
|
13 |
start_time = time.time()
|
14 |
pipe = StableDiffusionXLImg2ImgPipeline.from_pretrained(path, torch_dtype=torch.float16)
|
15 |
pipe.to("cuda")
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
|
18 |
prompt = "An astronaut riding a green horse on Mars"
|
19 |
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
init_image = torch.from_numpy(np.load("/home/patrick/images/xl_latents.npy")).to("cuda")
|
22 |
|
|
|
23 |
|
|
|
|
|
|
|
24 |
|
25 |
+
|
26 |
+
|
27 |
+
for scheduler_cls, kwargs in [
|
28 |
+
(EulerDiscreteScheduler, {}),
|
29 |
+
(EulerDiscreteScheduler, {"use_karras_sigmas": True}),
|
30 |
+
(UniPCMultistepScheduler, {}),
|
31 |
+
(UniPCMultistepScheduler, {"use_karras_sigmas": True}),
|
32 |
+
(DEISMultistepScheduler, {}),
|
33 |
+
(DEISMultistepScheduler, {"use_karras_sigmas": True}),
|
34 |
+
(HeunDiscreteScheduler, {}),
|
35 |
+
(HeunDiscreteScheduler, {"use_karras_sigmas": True}),
|
36 |
+
(DPMSolverMultistepScheduler, {}),
|
37 |
+
(DPMSolverMultistepScheduler, {"use_karras_sigmas": True, "algorithm_type": "sd-dpmsolver++"}),
|
38 |
+
]:
|
39 |
+
for num_steps in [11,12]:
|
40 |
+
pipe.scheduler = scheduler_cls.from_config(pipe.scheduler.config, **kwargs)
|
41 |
+
image = pipe(prompt=prompt, num_inference_steps=num_steps, image=init_image).images[0]
|
42 |
+
hiu.upload(image, "patrickvonplaten/images")
|
run_local_xl.py
CHANGED
@@ -22,12 +22,13 @@ use_refiner = False
|
|
22 |
use_diffusers = True
|
23 |
path = "stabilityai/stable-diffusion-xl-base-1.0"
|
24 |
refiner_path = "stabilityai/stable-diffusion-xl-refiner-1.0"
|
25 |
-
vae_path = "
|
26 |
|
27 |
-
vae = AutoencoderKL.from_pretrained(vae_path, torch_dtype=torch.float16
|
28 |
if use_diffusers:
|
29 |
# pipe = StableDiffusionXLPipeline.from_pretrained(path, vae=vae, torch_dtype=torch.float16, variant="fp16", use_safetensors=True, local_files_only=True)
|
30 |
pipe = StableDiffusionXLPipeline.from_pretrained(path, torch_dtype=torch.float16, vae=vae, variant="fp16", use_safetensors=True, local_files_only=True, add_watermarker=False)
|
|
|
31 |
# pipe.enable_xformers_memory_efficient_attention()
|
32 |
print(time.time() - start_time)
|
33 |
pipe.to("cuda")
|
|
|
22 |
use_diffusers = True
|
23 |
path = "stabilityai/stable-diffusion-xl-base-1.0"
|
24 |
refiner_path = "stabilityai/stable-diffusion-xl-refiner-1.0"
|
25 |
+
vae_path = "madebyollin/sdxl-vae-fp16-fix"
|
26 |
|
27 |
+
vae = AutoencoderKL.from_pretrained(vae_path, torch_dtype=torch.float16)
|
28 |
if use_diffusers:
|
29 |
# pipe = StableDiffusionXLPipeline.from_pretrained(path, vae=vae, torch_dtype=torch.float16, variant="fp16", use_safetensors=True, local_files_only=True)
|
30 |
pipe = StableDiffusionXLPipeline.from_pretrained(path, torch_dtype=torch.float16, vae=vae, variant="fp16", use_safetensors=True, local_files_only=True, add_watermarker=False)
|
31 |
+
import ipdb; ipdb.set_trace()
|
32 |
# pipe.enable_xformers_memory_efficient_attention()
|
33 |
print(time.time() - start_time)
|
34 |
pipe.to("cuda")
|
run_local_xl_img2img.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from diffusers import DiffusionPipeline, EulerDiscreteScheduler, StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler
|
3 |
+
from diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipeline, AutoencoderKL
|
4 |
+
import time
|
5 |
+
from pytorch_lightning import seed_everything
|
6 |
+
import os
|
7 |
+
from huggingface_hub import HfApi
|
8 |
+
# from compel import Compel
|
9 |
+
import torch
|
10 |
+
import sys
|
11 |
+
from pathlib import Path
|
12 |
+
import requests
|
13 |
+
from PIL import Image
|
14 |
+
from io import BytesIO
|
15 |
+
import xformers
|
16 |
+
|
17 |
+
api = HfApi()
|
18 |
+
start_time = time.time()
|
19 |
+
|
20 |
+
# use_refiner = bool(int(sys.argv[1]))
|
21 |
+
use_refiner = False
|
22 |
+
use_diffusers = True
|
23 |
+
path = "stabilityai/stable-diffusion-xl-base-1.0"
|
24 |
+
refiner_path = "stabilityai/stable-diffusion-xl-refiner-1.0"
|
25 |
+
vae_path = "madebyollin/sdxl-vae-fp16-fix"
|
26 |
+
|
27 |
+
vae = AutoencoderKL.from_pretrained(vae_path, torch_dtype=torch.float16)
|
28 |
+
if use_diffusers:
|
29 |
+
# pipe = StableDiffusionXLPipeline.from_pretrained(path, vae=vae, torch_dtype=torch.float16, variant="fp16", use_safetensors=True, local_files_only=True)
|
30 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(path, torch_dtype=torch.float16, vae=vae, variant="fp16", use_safetensors=True, local_files_only=True, add_watermarker=False)
|
31 |
+
import ipdb; ipdb.set_trace()
|
32 |
+
# pipe.enable_xformers_memory_efficient_attention()
|
33 |
+
print(time.time() - start_time)
|
34 |
+
pipe.to("cuda")
|
35 |
+
|
36 |
+
if use_refiner:
|
37 |
+
start_time = time.time()
|
38 |
+
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained(refiner_path, vae=vae, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
39 |
+
print(time.time() - start_time)
|
40 |
+
refiner.to("cuda")
|
41 |
+
# refiner.enable_sequential_cpu_offload()
|
42 |
+
else:
|
43 |
+
start_time = time.time()
|
44 |
+
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)
|
45 |
+
print(time.time() - start_time)
|
46 |
+
pipe.to("cuda")
|
47 |
+
|
48 |
+
if use_refiner:
|
49 |
+
start_time = time.time()
|
50 |
+
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)
|
51 |
+
print(time.time() - start_time)
|
52 |
+
refiner.to("cuda")
|
53 |
+
|
54 |
+
|
55 |
+
prompt = "An astronaut riding a green horse on Mars"
|
56 |
+
steps = 20
|
57 |
+
seed = 0
|
58 |
+
seed_everything(seed)
|
59 |
+
start_time = time.time()
|
60 |
+
image = pipe(prompt=prompt, num_inference_steps=steps, output_type="latent" if use_refiner else "pil").images[0]
|
61 |
+
print(time.time() - start_time)
|
62 |
+
|
63 |
+
if use_refiner:
|
64 |
+
image = refiner(prompt=prompt, num_inference_steps=steps - 10, image=image).images[0]
|
65 |
+
|
66 |
+
file_name = f"aaa"
|
67 |
+
path = os.path.join(Path.home(), "images", "ediffi_sdxl", f"{file_name}.png")
|
68 |
+
image.save(path)
|
69 |
+
|
70 |
+
api.upload_file(
|
71 |
+
path_or_fileobj=path,
|
72 |
+
path_in_repo=path.split("/")[-1],
|
73 |
+
repo_id="patrickvonplaten/images",
|
74 |
+
repo_type="dataset",
|
75 |
+
)
|
76 |
+
print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/{file_name}.png")
|
run_local_xl_simple.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from diffusers import DPMSolverMultistepScheduler, StableDiffusionXLPipeline, DPMSolverSDEScheduler
|
3 |
+
import hf_image_uploader as hiu
|
4 |
+
import torch
|
5 |
+
|
6 |
+
path = "stabilityai/stable-diffusion-xl-base-1.0"
|
7 |
+
vae_path = "madebyollin/sdxl-vae-fp16-fix"
|
8 |
+
|
9 |
+
# vae = AutoencoderKL.from_pretrained(vae_path, torch_dtype=torch.float16)
|
10 |
+
# pipe = StableDiffusionXLPipeline.from_pretrained(path, torch_dtype=torch.float16, vae=vae, variant="fp16", use_safetensors=True, local_files_only=True, add_watermarker=False)
|
11 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(path, torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
12 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config, algorithm_type="sde-dpmsolver++")
|
13 |
+
pipe.to("cuda")
|
14 |
+
|
15 |
+
prompt = "An astronaut riding a green horse on Mars"
|
16 |
+
steps = 20
|
17 |
+
|
18 |
+
for i in range(2):
|
19 |
+
width = 512 * (i + 1)
|
20 |
+
height = 512 * (i + 1)
|
21 |
+
image = pipe(prompt=prompt, width=width, height=height, num_inference_steps=steps).images[0]
|
22 |
+
hiu.upload(image, "patrickvonplaten/images")
|
23 |
+
|
24 |
+
pipe.scheduler = DPMSolverSDEScheduler.from_config(pipe.scheduler.config, algorithm_type="sde-dpmsolver++")
|
25 |
+
|
26 |
+
for i in range(2):
|
27 |
+
width = 512 * (i + 1)
|
28 |
+
height = 512 * (i + 1)
|
29 |
+
image = pipe(prompt=prompt, width=width, height=height, num_inference_steps=steps).images[0]
|
30 |
+
hiu.upload(image, "patrickvonplaten/images")
|
run_lora.py
CHANGED
@@ -1,27 +1,25 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
-
from diffusers import AutoPipelineForText2Image
|
3 |
import time
|
4 |
import os
|
5 |
from huggingface_hub import HfApi
|
6 |
-
# from compel import Compel
|
7 |
import torch
|
8 |
-
import sys
|
9 |
from pathlib import Path
|
10 |
-
import requests
|
11 |
-
from PIL import Image
|
12 |
-
from io import BytesIO
|
13 |
|
14 |
-
path = "stabilityai/stable-diffusion-xl-base-0
|
15 |
|
16 |
api = HfApi()
|
17 |
start_time = time.time()
|
18 |
pipe = AutoPipelineForText2Image.from_pretrained(path, torch_dtype=torch.float16)
|
19 |
pipe.enable_model_cpu_offload()
|
20 |
lora_model_id = "hf-internal-testing/sdxl-0.9-kamepan-lora"
|
|
|
21 |
lora_filename = "kame_sdxl_v2-000020-16rank.safetensors"
|
|
|
22 |
pipe.load_lora_weights(lora_model_id, weight_name=lora_filename)
|
23 |
|
24 |
prompt = "masterpiece, best quality, mountain"
|
|
|
25 |
|
26 |
images = pipe(prompt=prompt,
|
27 |
num_inference_steps=20,
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
+
from diffusers import AutoPipelineForText2Image
|
3 |
import time
|
4 |
import os
|
5 |
from huggingface_hub import HfApi
|
|
|
6 |
import torch
|
|
|
7 |
from pathlib import Path
|
|
|
|
|
|
|
8 |
|
9 |
+
path = "stabilityai/stable-diffusion-xl-base-1.0"
|
10 |
|
11 |
api = HfApi()
|
12 |
start_time = time.time()
|
13 |
pipe = AutoPipelineForText2Image.from_pretrained(path, torch_dtype=torch.float16)
|
14 |
pipe.enable_model_cpu_offload()
|
15 |
lora_model_id = "hf-internal-testing/sdxl-0.9-kamepan-lora"
|
16 |
+
lora_model_id = "TheLastBen/Papercut_SDXL"
|
17 |
lora_filename = "kame_sdxl_v2-000020-16rank.safetensors"
|
18 |
+
lora_filename = "papercut.safetensors"
|
19 |
pipe.load_lora_weights(lora_model_id, weight_name=lora_filename)
|
20 |
|
21 |
prompt = "masterpiece, best quality, mountain"
|
22 |
+
prompt = "papercut sonic"
|
23 |
|
24 |
images = pipe(prompt=prompt,
|
25 |
num_inference_steps=20,
|
run_muse.py
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from PIL import Image
|
3 |
+
import torch
|
4 |
+
from muse import PipelineMuse, MaskGiTUViT
|
5 |
+
from datasets import Dataset, Features
|
6 |
+
from datasets import Image as ImageFeature
|
7 |
+
from datasets import Value, load_dataset
|
8 |
+
|
9 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
+
|
11 |
+
pipe = PipelineMuse.from_pretrained(
|
12 |
+
transformer_path="valhalla/research-run",
|
13 |
+
text_encoder_path="openMUSE/clip-vit-large-patch14-text-enc",
|
14 |
+
vae_path="openMUSE/vqgan-f16-8192-laion",
|
15 |
+
).to(device)
|
16 |
+
|
17 |
+
pipe.transformer = MaskGiTUViT.from_pretrained("valhalla/research-run-finetuned-journeydb", revision="06bcd6ab6580a2ed3275ddfc17f463b8574457da", subfolder="ema_model").to(device)
|
18 |
+
pipe.tokenizer.pad_token_id = 49407
|
19 |
+
|
20 |
+
if device == "cuda":
|
21 |
+
pipe.transformer.enable_xformers_memory_efficient_attention()
|
22 |
+
pipe.text_encoder.to(torch.float16)
|
23 |
+
pipe.transformer.to(torch.float16)
|
24 |
+
|
25 |
+
|
26 |
+
import PIL
|
27 |
+
|
28 |
+
|
29 |
+
def main():
|
30 |
+
print("Loading dataset...")
|
31 |
+
parti_prompts = load_dataset("nateraw/parti-prompts", split="train")
|
32 |
+
|
33 |
+
print("Loading pipeline...")
|
34 |
+
seed = 0
|
35 |
+
|
36 |
+
device = "cuda"
|
37 |
+
torch.manual_seed(0)
|
38 |
+
|
39 |
+
ckpt_id = "openMUSE/muse-512"
|
40 |
+
|
41 |
+
scale = 10
|
42 |
+
|
43 |
+
print("Running inference...")
|
44 |
+
main_dict = {}
|
45 |
+
for i in range(len(parti_prompts)):
|
46 |
+
sample = parti_prompts[i]
|
47 |
+
prompt = sample["Prompt"]
|
48 |
+
|
49 |
+
image = pipe(
|
50 |
+
prompt,
|
51 |
+
timesteps=16,
|
52 |
+
negative_text=None,
|
53 |
+
guidance_scale=scale,
|
54 |
+
temperature=(2, 0),
|
55 |
+
orig_size=(512, 512),
|
56 |
+
crop_coords=(0, 0),
|
57 |
+
aesthetic_score=6,
|
58 |
+
use_fp16=device == "cuda",
|
59 |
+
transformer_seq_len=1024,
|
60 |
+
use_tqdm=False,
|
61 |
+
)[0]
|
62 |
+
|
63 |
+
image = image.resize((256, 256), resample=PIL.Image.Resampling.LANCZOS)
|
64 |
+
img_path = f"/home/patrick/muse_images/muse_512_{i}.png"
|
65 |
+
image.save(img_path)
|
66 |
+
main_dict.update(
|
67 |
+
{
|
68 |
+
prompt: {
|
69 |
+
"img_path": img_path,
|
70 |
+
"Category": sample["Category"],
|
71 |
+
"Challenge": sample["Challenge"],
|
72 |
+
"Note": sample["Note"],
|
73 |
+
"model_name": ckpt_id,
|
74 |
+
"seed": seed,
|
75 |
+
}
|
76 |
+
}
|
77 |
+
)
|
78 |
+
|
79 |
+
def generation_fn():
|
80 |
+
for prompt in main_dict:
|
81 |
+
prompt_entry = main_dict[prompt]
|
82 |
+
yield {
|
83 |
+
"Prompt": prompt,
|
84 |
+
"Category": prompt_entry["Category"],
|
85 |
+
"Challenge": prompt_entry["Challenge"],
|
86 |
+
"Note": prompt_entry["Note"],
|
87 |
+
"images": {"path": prompt_entry["img_path"]},
|
88 |
+
"model_name": prompt_entry["model_name"],
|
89 |
+
"seed": prompt_entry["seed"],
|
90 |
+
}
|
91 |
+
|
92 |
+
print("Preparing HF dataset...")
|
93 |
+
ds = Dataset.from_generator(
|
94 |
+
generation_fn,
|
95 |
+
features=Features(
|
96 |
+
Prompt=Value("string"),
|
97 |
+
Category=Value("string"),
|
98 |
+
Challenge=Value("string"),
|
99 |
+
Note=Value("string"),
|
100 |
+
images=ImageFeature(),
|
101 |
+
model_name=Value("string"),
|
102 |
+
seed=Value("int64"),
|
103 |
+
),
|
104 |
+
)
|
105 |
+
ds_id = "diffusers-parti-prompts/muse_512"
|
106 |
+
ds.push_to_hub(ds_id)
|
107 |
+
|
108 |
+
|
109 |
+
if __name__ == "__main__":
|
110 |
+
main()
|
run_muse_256.py
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from PIL import Image
|
3 |
+
import torch
|
4 |
+
from muse import PipelineMuse, MaskGiTUViT
|
5 |
+
from datasets import Dataset, Features
|
6 |
+
from datasets import Image as ImageFeature
|
7 |
+
from datasets import Value, load_dataset
|
8 |
+
|
9 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
+
|
11 |
+
pipe = PipelineMuse.from_pretrained(
|
12 |
+
transformer_path="valhalla/research-run",
|
13 |
+
text_encoder_path="openMUSE/clip-vit-large-patch14-text-enc",
|
14 |
+
vae_path="openMUSE/vqgan-f16-8192-laion",
|
15 |
+
).to(device)
|
16 |
+
|
17 |
+
# pipe.transformer = MaskGiTUViT.from_pretrained("valhalla/research-run-finetuned-journeydb", revision="06bcd6ab6580a2ed3275ddfc17f463b8574457da", subfolder="ema_model").to(device)
|
18 |
+
pipe.transformer = MaskGiTUViT.from_pretrained("valhalla/muse-research-run", subfolder="ema_model").to(device)
|
19 |
+
pipe.tokenizer.pad_token_id = 49407
|
20 |
+
|
21 |
+
if device == "cuda":
|
22 |
+
pipe.transformer.enable_xformers_memory_efficient_attention()
|
23 |
+
pipe.text_encoder.to(torch.float16)
|
24 |
+
pipe.transformer.to(torch.float16)
|
25 |
+
|
26 |
+
|
27 |
+
import PIL
|
28 |
+
|
29 |
+
|
30 |
+
def main():
|
31 |
+
print("Loading dataset...")
|
32 |
+
parti_prompts = load_dataset("nateraw/parti-prompts", split="train")
|
33 |
+
|
34 |
+
print("Loading pipeline...")
|
35 |
+
seed = 0
|
36 |
+
|
37 |
+
device = "cuda"
|
38 |
+
torch.manual_seed(0)
|
39 |
+
|
40 |
+
ckpt_id = "openMUSE/muse-256"
|
41 |
+
|
42 |
+
scale = 10
|
43 |
+
|
44 |
+
print("Running inference...")
|
45 |
+
main_dict = {}
|
46 |
+
for i in range(len(parti_prompts)):
|
47 |
+
sample = parti_prompts[i]
|
48 |
+
prompt = sample["Prompt"]
|
49 |
+
|
50 |
+
image = pipe(
|
51 |
+
prompt,
|
52 |
+
timesteps=16,
|
53 |
+
negative_text=None,
|
54 |
+
guidance_scale=scale,
|
55 |
+
temperature=(2, 0),
|
56 |
+
orig_size=(256, 256),
|
57 |
+
crop_coords=(0, 0),
|
58 |
+
aesthetic_score=6,
|
59 |
+
use_fp16=device == "cuda",
|
60 |
+
transformer_seq_len=256,
|
61 |
+
use_tqdm=False,
|
62 |
+
)[0]
|
63 |
+
|
64 |
+
image = image.resize((256, 256), resample=PIL.Image.Resampling.LANCZOS)
|
65 |
+
img_path = f"/home/patrick/muse_images/muse_256_{i}.png"
|
66 |
+
image.save(img_path)
|
67 |
+
main_dict.update(
|
68 |
+
{
|
69 |
+
prompt: {
|
70 |
+
"img_path": img_path,
|
71 |
+
"Category": sample["Category"],
|
72 |
+
"Challenge": sample["Challenge"],
|
73 |
+
"Note": sample["Note"],
|
74 |
+
"model_name": ckpt_id,
|
75 |
+
"seed": seed,
|
76 |
+
}
|
77 |
+
}
|
78 |
+
)
|
79 |
+
|
80 |
+
def generation_fn():
|
81 |
+
for prompt in main_dict:
|
82 |
+
prompt_entry = main_dict[prompt]
|
83 |
+
yield {
|
84 |
+
"Prompt": prompt,
|
85 |
+
"Category": prompt_entry["Category"],
|
86 |
+
"Challenge": prompt_entry["Challenge"],
|
87 |
+
"Note": prompt_entry["Note"],
|
88 |
+
"images": {"path": prompt_entry["img_path"]},
|
89 |
+
"model_name": prompt_entry["model_name"],
|
90 |
+
"seed": prompt_entry["seed"],
|
91 |
+
}
|
92 |
+
|
93 |
+
print("Preparing HF dataset...")
|
94 |
+
ds = Dataset.from_generator(
|
95 |
+
generation_fn,
|
96 |
+
features=Features(
|
97 |
+
Prompt=Value("string"),
|
98 |
+
Category=Value("string"),
|
99 |
+
Challenge=Value("string"),
|
100 |
+
Note=Value("string"),
|
101 |
+
images=ImageFeature(),
|
102 |
+
model_name=Value("string"),
|
103 |
+
seed=Value("int64"),
|
104 |
+
),
|
105 |
+
)
|
106 |
+
ds_id = "diffusers-parti-prompts/muse_256"
|
107 |
+
ds.push_to_hub(ds_id)
|
108 |
+
|
109 |
+
|
110 |
+
if __name__ == "__main__":
|
111 |
+
main()
|
run_sd_text.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import logging
|
3 |
+
import torch
|
4 |
+
import diffusers
|
5 |
+
|
6 |
+
log = logging.getLogger("test")
|
7 |
+
log.setLevel(logging.DEBUG)
|
8 |
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s | %(name)s | %(levelname)s | %(module)s | %(message)s')
|
9 |
+
|
10 |
+
log.info(f'loaded: torch={torch.__version__} diffusers={diffusers.__version__}')
|
11 |
+
|
12 |
+
prompt_positive = 'futuristic city'
|
13 |
+
prompt_negative = 'grass'
|
14 |
+
seeds = [42]
|
15 |
+
model_path = "runwayml/stable-diffusion-v1-5"
|
16 |
+
embedding_path_ok = "sd15_text_inv.pt"
|
17 |
+
# embedding_path_err = "./sd21_text_inv.pt"
|
18 |
+
device = 'cuda:0'
|
19 |
+
load_args = {
|
20 |
+
"low_cpu_mem_usage": True,
|
21 |
+
"torch_dtype": torch.float16,
|
22 |
+
"variant": 'fp16',
|
23 |
+
"safety_checker": None,
|
24 |
+
"load_safety_checker": False,
|
25 |
+
# "local_files_only": False,
|
26 |
+
}
|
27 |
+
pipe = diffusers.StableDiffusionPipeline.from_pretrained(model_path, **load_args)
|
28 |
+
pipe.set_progress_bar_config(bar_format='Progress {rate_fmt}{postfix} {bar} {percentage:3.0f}% {n_fmt}/{total_fmt} {elapsed} {remaining} ' + '\x1b[38;5;71m', ncols=80, colour='#327fba')
|
29 |
+
pipe.enable_model_cpu_offload()
|
30 |
+
args = {
|
31 |
+
'prompt': [prompt_positive],
|
32 |
+
'negative_prompt': [prompt_negative],
|
33 |
+
'guidance_scale': 6,
|
34 |
+
'generator': [torch.Generator(device).manual_seed(s) for s in seeds],
|
35 |
+
'output_type': 'pil',
|
36 |
+
'num_inference_steps': 10,
|
37 |
+
'eta': 0.0,
|
38 |
+
'guidance_rescale': 0.7,
|
39 |
+
'height': 512,
|
40 |
+
'width': 512,
|
41 |
+
}
|
42 |
+
|
43 |
+
# pipe.load_lora_weights(embedding_path_ok, **load_args)
|
44 |
+
try:
|
45 |
+
pipe.load_lora_weights(embedding_path_ok, **load_args)
|
46 |
+
except Exception as e:
|
47 |
+
log.error(f'failed to load embeddings: {e}')
|
48 |
+
|
49 |
+
output = pipe(**args)
|
50 |
+
log.info(f'output: {output}') # this works fine
|
51 |
+
|
run_sdxl_text_inv.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import hf_image_uploader as hiu
|
3 |
+
from diffusers import EulerDiscreteScheduler
|
4 |
+
from diffusers import AutoPipelineForText2Image
|
5 |
+
import torch
|
6 |
+
|
7 |
+
pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", variant="fp16", torch_dtype=torch.float16)
|
8 |
+
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
9 |
+
pipe.to("cuda")
|
10 |
+
|
11 |
+
prompt = "photo of a rhino dressed suit and tie sitting at a table in a bar with a bar stools, award winning photography, Elke vogelsang"
|
12 |
+
image = pipe(prompt, guidance_scale=9.0, num_inference_steps=25).images[0]
|
13 |
+
|
14 |
+
hiu.upload(image, repo_id="patrickvonplaten/images")
|
run_wuerst.py
CHANGED
@@ -1,37 +1,42 @@
|
|
1 |
#!/usr/bin/env python3
|
|
|
2 |
import torch
|
3 |
-
from diffusers import
|
4 |
-
from
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
+
import hf_image_uploader as hiu
|
3 |
import torch
|
4 |
+
from diffusers import WuerstchenDecoderPipeline, WuerstchenPriorPipeline
|
5 |
+
from diffusers.pipelines.wuerstchen import DEFAULT_STAGE_C_TIMESTEPS
|
6 |
+
|
7 |
+
device = "cuda"
|
8 |
+
dtype = torch.float16
|
9 |
+
num_images_per_prompt = 2
|
10 |
+
|
11 |
+
prior_pipeline = WuerstchenPriorPipeline.from_pretrained(
|
12 |
+
"warp-ai/wuerstchen-prior", torch_dtype=dtype
|
13 |
+
).to(device)
|
14 |
+
decoder_pipeline = WuerstchenDecoderPipeline.from_pretrained(
|
15 |
+
"warp-ai/wuerstchen", torch_dtype=dtype
|
16 |
+
).to(device)
|
17 |
+
|
18 |
+
caption = "Anthropomorphic cat dressed as a fire fighter"
|
19 |
+
negative_prompt = ""
|
20 |
+
|
21 |
+
prior_pipeline.prior = torch.compile(prior_pipeline.prior, mode="reduce-overhead", fullgraph=True)
|
22 |
+
decoder_pipeline.decoder = torch.compile(decoder_pipeline.decoder, mode="reduce-overhead", fullgraph=True)
|
23 |
+
|
24 |
+
prior_output = prior_pipeline(
|
25 |
+
prompt=caption,
|
26 |
+
height=1024,
|
27 |
+
width=1536,
|
28 |
+
timesteps=DEFAULT_STAGE_C_TIMESTEPS,
|
29 |
+
negative_prompt=negative_prompt,
|
30 |
+
guidance_scale=4.0,
|
31 |
+
num_images_per_prompt=num_images_per_prompt,
|
32 |
+
)
|
33 |
+
images = decoder_pipeline(
|
34 |
+
image_embeddings=prior_output.image_embeddings,
|
35 |
+
prompt=caption,
|
36 |
+
negative_prompt=negative_prompt,
|
37 |
+
guidance_scale=0.0,
|
38 |
+
output_type="pil",
|
39 |
+
).images
|
40 |
+
|
41 |
+
for image in images:
|
42 |
+
hiu.upload(image, repo_id="patrickvonplaten/images")
|
run_wuerstchen.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import torch
|
3 |
+
from datasets import Dataset, Features
|
4 |
+
from datasets import Image as ImageFeature
|
5 |
+
from datasets import Value, load_dataset
|
6 |
+
from diffusers import AutoPipelineForText2Image
|
7 |
+
|
8 |
+
import PIL
|
9 |
+
|
10 |
+
|
11 |
+
def main():
|
12 |
+
print("Loading dataset...")
|
13 |
+
parti_prompts = load_dataset("nateraw/parti-prompts", split="train")
|
14 |
+
|
15 |
+
print("Loading pipeline...")
|
16 |
+
seed = 0
|
17 |
+
|
18 |
+
device = "cuda"
|
19 |
+
generator = torch.Generator(device).manual_seed(seed)
|
20 |
+
dtype = torch.float16
|
21 |
+
|
22 |
+
ckpt_id = "warp-diffusion/wuerstchen"
|
23 |
+
|
24 |
+
pipeline = AutoPipelineForText2Image.from_pretrained(
|
25 |
+
ckpt_id, torch_dtype=dtype
|
26 |
+
).to(device)
|
27 |
+
|
28 |
+
pipeline.prior_prior = torch.compile(pipeline.prior_prior, mode="reduce-overhead", fullgraph=True)
|
29 |
+
pipeline.decoder = torch.compile(pipeline.decoder, mode="reduce-overhead", fullgraph=True)
|
30 |
+
|
31 |
+
print("Running inference...")
|
32 |
+
main_dict = {}
|
33 |
+
for i in range(len(parti_prompts)):
|
34 |
+
sample = parti_prompts[i]
|
35 |
+
prompt = sample["Prompt"]
|
36 |
+
|
37 |
+
image = pipeline(
|
38 |
+
prompt=prompt,
|
39 |
+
height=1024,
|
40 |
+
width=1024,
|
41 |
+
prior_guidance_scale=4.0,
|
42 |
+
decoder_guidance_scale=0.0,
|
43 |
+
generator=generator,
|
44 |
+
).images[0]
|
45 |
+
|
46 |
+
image = image.resize((256, 256), resample=PIL.Image.Resampling.LANCZOS)
|
47 |
+
img_path = f"wuerstchen_{i}.png"
|
48 |
+
image.save(img_path)
|
49 |
+
main_dict.update(
|
50 |
+
{
|
51 |
+
prompt: {
|
52 |
+
"img_path": img_path,
|
53 |
+
"Category": sample["Category"],
|
54 |
+
"Challenge": sample["Challenge"],
|
55 |
+
"Note": sample["Note"],
|
56 |
+
"model_name": ckpt_id,
|
57 |
+
"seed": seed,
|
58 |
+
}
|
59 |
+
}
|
60 |
+
)
|
61 |
+
|
62 |
+
def generation_fn():
|
63 |
+
for prompt in main_dict:
|
64 |
+
prompt_entry = main_dict[prompt]
|
65 |
+
yield {
|
66 |
+
"Prompt": prompt,
|
67 |
+
"Category": prompt_entry["Category"],
|
68 |
+
"Challenge": prompt_entry["Challenge"],
|
69 |
+
"Note": prompt_entry["Note"],
|
70 |
+
"images": {"path": prompt_entry["img_path"]},
|
71 |
+
"model_name": prompt_entry["model_name"],
|
72 |
+
"seed": prompt_entry["seed"],
|
73 |
+
}
|
74 |
+
|
75 |
+
print("Preparing HF dataset...")
|
76 |
+
ds = Dataset.from_generator(
|
77 |
+
generation_fn,
|
78 |
+
features=Features(
|
79 |
+
Prompt=Value("string"),
|
80 |
+
Category=Value("string"),
|
81 |
+
Challenge=Value("string"),
|
82 |
+
Note=Value("string"),
|
83 |
+
images=ImageFeature(),
|
84 |
+
model_name=Value("string"),
|
85 |
+
seed=Value("int64"),
|
86 |
+
),
|
87 |
+
)
|
88 |
+
ds_id = "diffusers-parti-prompts/wuerstchen"
|
89 |
+
ds.push_to_hub(ds_id)
|
90 |
+
|
91 |
+
|
92 |
+
if __name__ == "__main__":
|
93 |
+
main()
|
run_wuerstchen_new.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import torch
|
3 |
+
from diffusers import AutoPipelineForText2Image
|
4 |
+
from diffusers.pipelines.wuerstchen import DEFAULT_STAGE_C_TIMESTEPS
|
5 |
+
|
6 |
+
pipe = AutoPipelineForText2Image.from_pretrained("warp-ai/wuerstchen", torch_dtype=torch.float16).to("cuda")
|
7 |
+
|
8 |
+
caption = "Anthropomorphic cat dressed as a fire fighter"
|
9 |
+
images = pipe(
|
10 |
+
caption,
|
11 |
+
width=1024,
|
12 |
+
height=1536,
|
13 |
+
prior_timesteps=DEFAULT_STAGE_C_TIMESTEPS,
|
14 |
+
prior_guidance_scale=4.0,
|
15 |
+
num_images_per_prompt=2,
|
16 |
+
).images
|
17 |
+
|
18 |
+
import ipdb; ipdb.set_trace()
|
run_xl.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import hf_image_uploader as hiu
|
3 |
+
import torch
|
4 |
+
from compel import Compel, ReturnedEmbeddingsType
|
5 |
+
from diffusers import DiffusionPipeline
|
6 |
+
|
7 |
+
pipe = DiffusionPipeline.from_pretrained(
|
8 |
+
"stabilityai/stable-diffusion-xl-base-1.0",
|
9 |
+
variant="fp16",
|
10 |
+
torch_dtype=torch.float16
|
11 |
+
)
|
12 |
+
pipe2 = DiffusionPipeline.from_pretrained(
|
13 |
+
"stabilityai/stable-diffusion-xl-refiner-1.0",
|
14 |
+
variant="fp16",
|
15 |
+
torch_dtype=torch.float16
|
16 |
+
)
|
17 |
+
pipe.enable_model_cpu_offload()
|
18 |
+
pipe2.enable_model_cpu_offload()
|
19 |
+
|
20 |
+
compel = Compel(
|
21 |
+
tokenizer=[pipe.tokenizer, pipe.tokenizer_2] ,
|
22 |
+
text_encoder=[pipe.text_encoder, pipe.text_encoder_2],
|
23 |
+
returned_embeddings_type=ReturnedEmbeddingsType.PENULTIMATE_HIDDEN_STATES_NON_NORMALIZED,
|
24 |
+
requires_pooled=[False, True]
|
25 |
+
)
|
26 |
+
|
27 |
+
compel2 = Compel(
|
28 |
+
tokenizer=pipe.tokenizer_2,
|
29 |
+
text_encoder=pipe.text_encoder_2,
|
30 |
+
returned_embeddings_type=ReturnedEmbeddingsType.PENULTIMATE_HIDDEN_STATES_NON_NORMALIZED,
|
31 |
+
requires_pooled=True,
|
32 |
+
)
|
33 |
+
|
34 |
+
# apply weights
|
35 |
+
prompt = ["a red cat playing with a (ball)1.5", "a red cat playing with a (ball)0.6"]
|
36 |
+
conditioning, pooled = compel(prompt)
|
37 |
+
conditioning2, pooled2 = compel2(prompt)
|
38 |
+
|
39 |
+
# generate image
|
40 |
+
|
41 |
+
for _ in range(3):
|
42 |
+
generator = [torch.Generator().manual_seed(i) for i in range(len(prompt))]
|
43 |
+
|
44 |
+
image = pipe(prompt_embeds=conditioning, pooled_prompt_embeds=pooled, generator=generator, num_inference_steps=30, output_type="latent").images
|
45 |
+
image = pipe2(image=image, prompt_embeds=conditioning2, pooled_prompt_embeds=pooled2, generator=generator, num_inference_steps=20).images[0]
|
46 |
+
hiu.upload(image, "patrickvonplaten/images")
|
run_xl_lora.py
CHANGED
@@ -1,35 +1,45 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
from diffusers import DiffusionPipeline
|
|
|
3 |
import torch
|
4 |
from pathlib import Path
|
5 |
-
from huggingface_hub import HfApi
|
6 |
import os
|
|
|
|
|
7 |
|
8 |
api = HfApi()
|
9 |
|
|
|
10 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
|
11 |
-
pipe.load_lora_weights("stabilityai/stable-diffusion-xl-base-1.0", weight_name="sd_xl_offset_example-lora_1.0.safetensors")
|
12 |
-
# pipe.unet.fuse_lora()
|
13 |
-
# 7.8 it/s to beat
|
14 |
-
#
|
15 |
-
pipe.to(torch_dtype=torch.float16)
|
16 |
pipe.to("cuda")
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
22 |
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
28 |
|
29 |
-
|
30 |
-
path_or_fileobj=path,
|
31 |
-
path_in_repo=path.split("/")[-1],
|
32 |
-
repo_id="patrickvonplaten/images",
|
33 |
-
repo_type="dataset",
|
34 |
-
)
|
35 |
-
print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/{file_name}.png")
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
from diffusers import DiffusionPipeline
|
3 |
+
from safetensors.torch import load_file
|
4 |
import torch
|
5 |
from pathlib import Path
|
6 |
+
from huggingface_hub import HfApi, hf_hub_download
|
7 |
import os
|
8 |
+
import hf_image_uploader as hiu
|
9 |
+
import time
|
10 |
|
11 |
api = HfApi()
|
12 |
|
13 |
+
|
14 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
|
|
|
|
|
|
|
|
|
|
|
15 |
pipe.to("cuda")
|
16 |
|
17 |
+
# pipe.load_lora_weights("stabilityai/stable-diffusion-xl-base-1.0", weight_name="sd_xl_offset_example-lora_1.0.safetensors", low_cpu_mem_usage=True)
|
18 |
+
# file = hf_hub_download("TheLastBen/Papercut_SDXL", filename="papercut.safetensors")
|
19 |
+
file = hf_hub_download("hf-internal-testing/sdxl-0.9-daiton-lora", filename="daiton-xl-lora-test.safetensors")
|
20 |
+
|
21 |
+
start_time = time.time()
|
22 |
+
pipe.load_lora_weights("Pclanglais/TintinIA")
|
23 |
+
pipe.fuse_lora()
|
24 |
+
pipe.unfuse_lora()
|
25 |
+
pipe.unload_lora_weights()
|
26 |
+
|
27 |
+
pipe.load_lora_weights("ProomptEngineer/pe-balloon-diffusion-style")
|
28 |
+
pipe.fuse_lora()
|
29 |
+
pipe.unload_lora_weights()
|
30 |
+
pipe.unfuse_lora()
|
31 |
|
32 |
+
pipe.load_lora_weights("ostris/crayon_style_lora_sdxl")
|
33 |
+
pipe.fuse_lora()
|
34 |
+
pipe.unload_lora_weights()
|
35 |
+
pipe.unfuse_lora()
|
36 |
+
print(time.time() - start_time)
|
37 |
|
38 |
+
prompt = "masterpiece, best quality, mountain"
|
39 |
|
40 |
+
images = pipe(prompt=prompt,
|
41 |
+
num_inference_steps=20,
|
42 |
+
generator=torch.manual_seed(0)
|
43 |
+
).images
|
44 |
|
45 |
+
hiu.upload(images[0], "patrickvonplaten/images")
|
|
|
|
|
|
|
|
|
|
|
|
run_xl_pivotal.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import hf_image_uploader as hiu
|
3 |
+
from safetensors.torch import load_file
|
4 |
+
from huggingface_hub import snapshot_download
|
5 |
+
|
6 |
+
from diffusers import DiffusionPipeline
|
7 |
+
import torch
|
8 |
+
import json
|
9 |
+
import os
|
10 |
+
|
11 |
+
model_id = "multimodalart/sdxl-emoji"
|
12 |
+
|
13 |
+
folder = snapshot_download(model_id)
|
14 |
+
|
15 |
+
with open(os.path.join(folder, "special_params.json"), 'r') as json_file:
|
16 |
+
data = json.load(json_file)
|
17 |
+
token, token_2 = data["TOK"][:4], data["TOK"][4:]
|
18 |
+
|
19 |
+
state_dict = load_file(os.path.join(folder, "embeddings.pti"))
|
20 |
+
|
21 |
+
text_encoder_sd = state_dict["text_encoders_0"]
|
22 |
+
text_encoder_2_sd = state_dict["text_encoders_1"]
|
23 |
+
|
24 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
|
25 |
+
|
26 |
+
pipe.load_textual_inversion(text_encoder_sd, token=token, text_encoder=pipe.text_encoder, tokenizer=pipe.tokenizer)
|
27 |
+
pipe.load_textual_inversion(text_encoder_2_sd, token=token_2, text_encoder=pipe.text_encoder_2, tokenizer=pipe.tokenizer_2)
|
28 |
+
pipe.load_lora_weights(os.path.join(folder, "lora.safetensors"))
|
29 |
+
pipe.to(torch_dtype=torch.float16)
|
30 |
+
pipe.to("cuda")
|
31 |
+
|
32 |
+
prompt="A <s0><s1> emoji of a man"
|
33 |
+
|
34 |
+
image = pipe(prompt, cross_attention_kwargs={"scale": 0.8}, num_inference_steps=20).images[0]
|
35 |
+
hiu.upload(image, "patrickvonplaten/images")
|
sd_xl_inpaint.py
CHANGED
@@ -1,25 +1,24 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
-
from diffusers import AutoPipelineForInpainting, AutoPipelineForImage2Image
|
3 |
from diffusers.utils import load_image
|
4 |
import torch
|
5 |
-
|
6 |
-
import os
|
7 |
-
from huggingface_hub import HfApi
|
8 |
|
9 |
torch.backends.cuda.matmul.allow_tf32 = True
|
10 |
torch_device = "cuda" if torch.cuda.is_available() else "cpu"
|
11 |
-
api = HfApi()
|
12 |
|
13 |
-
pipe = AutoPipelineForInpainting.from_pretrained("runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
|
|
|
|
14 |
|
15 |
pipe = pipe.to(torch_device)
|
16 |
-
pipe.enable_xformers_memory_efficient_attention()
|
17 |
|
18 |
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
|
|
|
19 |
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
|
20 |
|
21 |
-
image = load_image(img_url)
|
22 |
-
mask_image = load_image(mask_url)
|
23 |
|
24 |
prompt = "dslr photography of an empty bench, high quality"
|
25 |
generator = torch.Generator(device="cuda").manual_seed(0)
|
@@ -30,47 +29,10 @@ image = pipe(
|
|
30 |
mask_image=mask_image,
|
31 |
guidance_scale=8.0,
|
32 |
num_inference_steps=20,
|
|
|
33 |
generator=generator,
|
34 |
).images[0]
|
35 |
|
36 |
|
37 |
image = image.resize((1024, 1024))
|
38 |
-
|
39 |
-
pipe = AutoPipelineForInpainting.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
40 |
-
pipe.to("cuda")
|
41 |
-
|
42 |
-
pipe.enable_xformers_memory_efficient_attention()
|
43 |
-
|
44 |
-
image = pipe(
|
45 |
-
prompt=prompt,
|
46 |
-
image=image,
|
47 |
-
mask_image=mask_image,
|
48 |
-
guidance_scale=8.0,
|
49 |
-
num_inference_steps=100,
|
50 |
-
strength=0.2,
|
51 |
-
generator=generator,
|
52 |
-
).images[0]
|
53 |
-
|
54 |
-
pipe = AutoPipelineForImage2Image.from_pipe(pipe)
|
55 |
-
pipe.enable_xformers_memory_efficient_attention()
|
56 |
-
|
57 |
-
image = pipe(
|
58 |
-
prompt=prompt,
|
59 |
-
image=image,
|
60 |
-
guidance_scale=8.0,
|
61 |
-
num_inference_steps=100,
|
62 |
-
strength=0.2,
|
63 |
-
generator=generator,
|
64 |
-
).images[0]
|
65 |
-
|
66 |
-
file_name = f"aaa"
|
67 |
-
path = os.path.join(Path.home(), "images", "ediffi_sdxl", f"{file_name}.png")
|
68 |
-
image.save(path)
|
69 |
-
|
70 |
-
api.upload_file(
|
71 |
-
path_or_fileobj=path,
|
72 |
-
path_in_repo=path.split("/")[-1],
|
73 |
-
repo_id="patrickvonplaten/images",
|
74 |
-
repo_type="dataset",
|
75 |
-
)
|
76 |
-
print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/{file_name}.png")
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
+
from diffusers import AutoPipelineForInpainting, AutoPipelineForImage2Image, UNet2DConditionModel
|
3 |
from diffusers.utils import load_image
|
4 |
import torch
|
5 |
+
import hf_image_uploader as hfi
|
|
|
|
|
6 |
|
7 |
torch.backends.cuda.matmul.allow_tf32 = True
|
8 |
torch_device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
9 |
|
10 |
+
# pipe = AutoPipelineForInpainting.from_pretrained("runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
11 |
+
unet = UNet2DConditionModel.from_pretrained("valhalla/sdxl-inpaint-ema", torch_dtype=torch.float16)
|
12 |
+
pipe = AutoPipelineForInpainting.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
|
13 |
|
14 |
pipe = pipe.to(torch_device)
|
|
|
15 |
|
16 |
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
|
17 |
+
img_url = "https://huggingface.co/datasets/patrickvonplaten/images_1024_1024/resolve/main/jdn_jacques_de_nuce-1024x1024.jpg"
|
18 |
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
|
19 |
|
20 |
+
image = load_image(img_url).resize((1024, 1024))
|
21 |
+
mask_image = load_image(mask_url).resize((1024, 1024))
|
22 |
|
23 |
prompt = "dslr photography of an empty bench, high quality"
|
24 |
generator = torch.Generator(device="cuda").manual_seed(0)
|
|
|
29 |
mask_image=mask_image,
|
30 |
guidance_scale=8.0,
|
31 |
num_inference_steps=20,
|
32 |
+
strength=0.90,
|
33 |
generator=generator,
|
34 |
).images[0]
|
35 |
|
36 |
|
37 |
image = image.resize((1024, 1024))
|
38 |
+
hfi.upload(image, "patrickvonplaten/images")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
upload_new_checkpoint.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from huggingface_hub import HfApi
|
3 |
+
from diffusers import StableDiffusionPipeline, StableDiffusionXLPipeline, StableDiffusionInpaintPipeline
|
4 |
+
from pathlib import Path
|
5 |
+
import os
|
6 |
+
import sys
|
7 |
+
import requests
|
8 |
+
from PIL import Image
|
9 |
+
from io import BytesIO
|
10 |
+
|
11 |
+
org_name = "lykon-models"
|
12 |
+
org_name = "lykon-absolute-realism"
|
13 |
+
|
14 |
+
file_path = sys.argv[1]
|
15 |
+
file_name = file_path.split("/")[-1].split(".safetensors")[0].replace("_", "-").replace(".", "-").lower()
|
16 |
+
|
17 |
+
if file_name.endswith("-"):
|
18 |
+
file_name = file_name[:-1]
|
19 |
+
|
20 |
+
def download_image(url):
|
21 |
+
response = requests.get(url)
|
22 |
+
return Image.open(BytesIO(response.content)).convert("RGB")
|
23 |
+
|
24 |
+
kwargs = {}
|
25 |
+
if "xl" in file_name or "alpha2" in file_name:
|
26 |
+
pipe = StableDiffusionXLPipeline.from_single_file(file_path)
|
27 |
+
elif "inpaint" in file_name:
|
28 |
+
pipe = StableDiffusionInpaintPipeline.from_single_file(file_path)
|
29 |
+
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
|
30 |
+
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
|
31 |
+
|
32 |
+
init_image = download_image(img_url).resize((512, 512))
|
33 |
+
mask_image = download_image(mask_url).resize((512, 512))
|
34 |
+
kwargs = {"image": init_image, "mask_image": mask_image}
|
35 |
+
else:
|
36 |
+
pipe = StableDiffusionPipeline.from_single_file(file_path)
|
37 |
+
|
38 |
+
print("Test...")
|
39 |
+
prompt = "A lion in galaxies, spirals, nebulae, stars, smoke, iridescent, intricate detail, octane render, 8k"
|
40 |
+
pipe.to("cuda")
|
41 |
+
images = pipe(prompt=prompt, num_inference_steps=25, **kwargs).images
|
42 |
+
pipe.to("cpu")
|
43 |
+
|
44 |
+
api = HfApi()
|
45 |
+
for i, image in enumerate(images):
|
46 |
+
image_file_name = f"bb_1_{i}"
|
47 |
+
path = os.path.join(Path.home(), "images", f"{image_file_name}.png")
|
48 |
+
image.save(path)
|
49 |
+
|
50 |
+
api.upload_file(
|
51 |
+
path_or_fileobj=path,
|
52 |
+
path_in_repo=path.split("/")[-1],
|
53 |
+
repo_id="patrickvonplaten/images",
|
54 |
+
repo_type="dataset",
|
55 |
+
)
|
56 |
+
print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/{image_file_name}.png")
|
57 |
+
|
58 |
+
print("Upload...")
|
59 |
+
model_id = os.path.join(org_name, file_name)
|
60 |
+
pipe.push_to_hub(model_id, private=True)
|