patrickvonplaten commited on
Commit
8e8daa7
·
1 Parent(s): 71da11e
Files changed (2) hide show
  1. run_bug_4297.py +6 -6
  2. run_bug_4297_new.py +49 -0
run_bug_4297.py CHANGED
@@ -1,5 +1,5 @@
1
  #!/usr/bin/env python3
2
- from diffusers import DiffusionPipeline
3
  import torch
4
  torch.backends.cudnn.deterministic = False
5
  torch.backends.cuda.matmul.allow_tf32 = False
@@ -7,7 +7,8 @@ torch.backends.cudnn.allow_tf32 = False
7
  torch.backends.cudnn.benchmark = True
8
  torch.backends.cuda.enable_flash_sdp(False)
9
 
10
- base_pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-0.9", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
 
11
  base_pipe.to("cuda") # OR, pipe.enable_sequential_cpu_offload() OR,
12
  #pipe.enable_model_cpu_offload()
13
 
@@ -17,12 +18,11 @@ base_pipe.to("cuda") # OR, pipe.enable_sequential_cpu_offload() OR,
17
  # Reproducibility.
18
  torch_seed = 4202420420
19
  refiner_seed = 698008569
20
- refiner_strength = 0.50
21
  prompt = "happy child flying a kite on a sunny day"
22
  negative_prompt = ''
23
  # Batch size.
24
  batch_size = 2
25
- do_latent = False
26
  prompt = [ prompt ] * batch_size
27
  negative_prompt = [ negative_prompt ] * batch_size
28
  # We're going to schedule 20 steps, and complete 50% of them using either model.
@@ -30,9 +30,9 @@ total_num_steps = 20
30
  # We need multiple Generators.
31
  generator = [ torch.Generator(device="cuda").manual_seed(torch_seed) ] * batch_size
32
 
33
- pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-0.9", vae=base_pipe.vae, text_encoder_2=base_pipe.text_encoder_2, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
34
  # Using channels last layout.
35
- pipe.unet.to(memory_format=torch.channels_last)
36
  pipe.to("cuda") # OR, pipe.enable_sequential_cpu_offload() OR,
37
 
38
  # Generate the base image.
 
1
  #!/usr/bin/env python3
2
+ from diffusers import DiffusionPipeline, AutoencoderKL
3
  import torch
4
  torch.backends.cudnn.deterministic = False
5
  torch.backends.cuda.matmul.allow_tf32 = False
 
7
  torch.backends.cudnn.benchmark = True
8
  torch.backends.cuda.enable_flash_sdp(False)
9
 
10
+ vae = AutoencoderKL.from_pretrained("stabilityai/sdxl-vae", torch_dtype=torch.float16)
11
+ base_pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", vae=vae, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
12
  base_pipe.to("cuda") # OR, pipe.enable_sequential_cpu_offload() OR,
13
  #pipe.enable_model_cpu_offload()
14
 
 
18
  # Reproducibility.
19
  torch_seed = 4202420420
20
  refiner_seed = 698008569
 
21
  prompt = "happy child flying a kite on a sunny day"
22
  negative_prompt = ''
23
  # Batch size.
24
  batch_size = 2
25
+ do_latent = True
26
  prompt = [ prompt ] * batch_size
27
  negative_prompt = [ negative_prompt ] * batch_size
28
  # We're going to schedule 20 steps, and complete 50% of them using either model.
 
30
  # We need multiple Generators.
31
  generator = [ torch.Generator(device="cuda").manual_seed(torch_seed) ] * batch_size
32
 
33
+ pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", vae=base_pipe.vae, text_encoder_2=base_pipe.text_encoder_2, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
34
  # Using channels last layout.
35
+ # pipe.unet.to(memory_format=torch.channels_last)
36
  pipe.to("cuda") # OR, pipe.enable_sequential_cpu_offload() OR,
37
 
38
  # Generate the base image.
run_bug_4297_new.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ from diffusers import DiffusionPipeline
3
+ import torch
4
+ torch.backends.cudnn.deterministic = False
5
+ torch.backends.cuda.matmul.allow_tf32 = False
6
+ torch.backends.cudnn.allow_tf32 = False
7
+ torch.backends.cudnn.benchmark = True
8
+ torch.backends.cuda.enable_flash_sdp(False)
9
+
10
+ # vae = AutoEncoderKL.from_pretrained("stabilityai/sdxl-vae", torch_dtype=torch.float16)
11
+ # base_pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", vae=vae, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
12
+ base_pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", vae, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
13
+ base_pipe.to("cuda") # OR, pipe.enable_sequential_cpu_offload() OR,
14
+
15
+ # Reproducibility.
16
+ torch_seed = 4202420420
17
+ refiner_seed = 698008569
18
+ refiner_strength = 0.50
19
+ prompt = "happy child flying a kite on a sunny day"
20
+ negative_prompt = ''
21
+ # Batch size.
22
+ batch_size = 2
23
+ do_latent = True
24
+
25
+ # We're going to schedule 20 steps, and complete 50% of them using either model.
26
+ total_num_steps = 20
27
+ # We need multiple Generators.
28
+ generator = torch.Generator(device="cuda").manual_seed(torch_seed)
29
+
30
+ pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", vae=base_pipe.vae, text_encoder_2=base_pipe.text_encoder_2, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
31
+ # Using channels last layout.
32
+ pipe.unet.to(memory_format=torch.channels_last)
33
+ pipe.to("cuda") # OR, pipe.enable_sequential_cpu_offload() OR,
34
+
35
+ # Generate the base image.
36
+ pre_image = base_pipe(prompt=prompt, generator=generator,
37
+ num_inference_steps=total_num_steps, negative_prompt=negative_prompt, num_images_per_prompt=batch_size, output_type="latent" if do_latent else "pil").images
38
+
39
+ # Generate a range from 0.1 to 0.9, with 0.1 increments.
40
+ test_strengths = [0.5]
41
+ for refiner_strength in test_strengths:
42
+ # Generate a new set of random states for each image.
43
+ generator_two = torch.Generator(device="cuda").manual_seed(refiner_seed)
44
+ # Put through the refiner now.
45
+ images = pipe(prompt=prompt, image=pre_image, aesthetic_score=10, negative_aesthetic_score=2.4, generator=generator_two,
46
+ num_inference_steps=total_num_steps, num_images_per_prompt=batch_size, strength=refiner_strength, negative_prompt=negative_prompt).images # denoising_start
47
+ for idx in range(0, len(images)):
48
+ print(f'Image: {idx}')
49
+ images[idx].save(f'/home/patrick/images/refiner_bug/test-{refiner_strength}-{idx}--{batch_size}--{do_latent}.png', format='PNG')