Commit
·
fcc7a59
1
Parent(s):
f1bde35
up
Browse files- run_xl_ediffi.py +35 -9
run_xl_ediffi.py
CHANGED
|
@@ -18,27 +18,53 @@ from torch.nn.functional import fractional_max_pool2d_with_indices
|
|
| 18 |
api = HfApi()
|
| 19 |
start_time = time.time()
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
model_id = "stabilityai/stable-diffusion-xl-base-0.9"
|
| 25 |
pipe_high_noise = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, variant="fp16", use_safetensors=True, local_files_only=True)
|
| 26 |
-
pipe_high_noise.scheduler =
|
| 27 |
pipe_high_noise.to("cuda")
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
pipe_low_noise = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-0.9", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
| 30 |
-
pipe_low_noise.scheduler =
|
| 31 |
pipe_low_noise.to("cuda")
|
| 32 |
|
| 33 |
prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
|
| 34 |
|
| 35 |
-
num_inference_steps = 40
|
| 36 |
-
high_noise_frac = 0.8
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
image = pipe_high_noise(prompt=prompt, num_inference_steps=num_inference_steps, denoising_end=high_noise_frac, output_type="
|
| 42 |
image = pipe_low_noise(prompt=prompt, num_inference_steps=num_inference_steps, denoising_start=high_noise_frac, image=image).images[0]
|
| 43 |
|
| 44 |
file_name = f"aaa_1"
|
|
|
|
| 18 |
api = HfApi()
|
| 19 |
start_time = time.time()
|
| 20 |
|
| 21 |
+
scheduler = DPMSolverMultistepScheduler(
|
| 22 |
+
beta_start=0.00085,
|
| 23 |
+
beta_end=0.012,
|
| 24 |
+
beta_schedule="scaled_linear",
|
| 25 |
+
prediction_type="epsilon",
|
| 26 |
+
num_train_timesteps=1000,
|
| 27 |
+
trained_betas=None,
|
| 28 |
+
thresholding=False,
|
| 29 |
+
algorithm_type="dpmsolver++",
|
| 30 |
+
solver_type="midpoint",
|
| 31 |
+
lower_order_final=True,
|
| 32 |
+
use_karras_sigmas=True,
|
| 33 |
+
)
|
| 34 |
|
| 35 |
model_id = "stabilityai/stable-diffusion-xl-base-0.9"
|
| 36 |
pipe_high_noise = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, variant="fp16", use_safetensors=True, local_files_only=True)
|
| 37 |
+
pipe_high_noise.scheduler = scheduler
|
| 38 |
pipe_high_noise.to("cuda")
|
| 39 |
|
| 40 |
+
scheduler = DPMSolverMultistepScheduler(
|
| 41 |
+
beta_start=0.00085,
|
| 42 |
+
beta_end=0.012,
|
| 43 |
+
beta_schedule="scaled_linear",
|
| 44 |
+
prediction_type="epsilon",
|
| 45 |
+
num_train_timesteps=1000,
|
| 46 |
+
trained_betas=None,
|
| 47 |
+
thresholding=False,
|
| 48 |
+
algorithm_type="dpmsolver++",
|
| 49 |
+
solver_type="midpoint",
|
| 50 |
+
lower_order_final=True,
|
| 51 |
+
use_karras_sigmas=True,
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
pipe_low_noise = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-0.9", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
| 55 |
+
pipe_low_noise.scheduler = scheduler
|
| 56 |
pipe_low_noise.to("cuda")
|
| 57 |
|
| 58 |
prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
|
| 59 |
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
random_generator = torch.Generator()
|
| 62 |
+
random_generator.manual_seed(0)
|
| 63 |
+
|
| 64 |
+
num_inference_steps = 100
|
| 65 |
+
high_noise_frac = 0.8
|
| 66 |
|
| 67 |
+
image = pipe_high_noise(prompt=prompt, num_inference_steps=num_inference_steps, denoising_end=high_noise_frac, output_type="latent").images
|
| 68 |
image = pipe_low_noise(prompt=prompt, num_inference_steps=num_inference_steps, denoising_start=high_noise_frac, image=image).images[0]
|
| 69 |
|
| 70 |
file_name = f"aaa_1"
|