Spaces:
Runtime error
Runtime error
Back to float32
Browse files- app.py +6 -9
- src/editor.py +1 -1
- src/euler_scheduler.py +6 -6
app.py
CHANGED
@@ -30,23 +30,20 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
30 |
# }
|
31 |
# """
|
32 |
|
33 |
-
if
|
34 |
-
power_device = "GPU"
|
35 |
torch.cuda.max_memory_allocated(device=device)
|
36 |
-
else:
|
37 |
-
power_device = "CPU"
|
38 |
|
39 |
scheduler_class = MyEulerAncestralDiscreteScheduler
|
40 |
|
41 |
-
pipe_inversion = SDXLDDIMPipeline.from_pretrained("stabilityai/sdxl-turbo",
|
42 |
-
pipe_inference = AutoPipelineForImage2Image.from_pretrained("stabilityai/sdxl-turbo",
|
43 |
-
use_safetensors=True) # .to('cpu')
|
44 |
pipe_inference.scheduler = scheduler_class.from_config(pipe_inference.scheduler.config)
|
45 |
pipe_inversion.scheduler = scheduler_class.from_config(pipe_inversion.scheduler.config)
|
46 |
pipe_inversion.scheduler_inference = scheduler_class.from_config(pipe_inference.scheduler.config)
|
47 |
|
48 |
-
|
49 |
-
|
|
|
50 |
|
51 |
|
52 |
|
|
|
30 |
# }
|
31 |
# """
|
32 |
|
33 |
+
if device == "cuda":
|
|
|
34 |
torch.cuda.max_memory_allocated(device=device)
|
|
|
|
|
35 |
|
36 |
scheduler_class = MyEulerAncestralDiscreteScheduler
|
37 |
|
38 |
+
pipe_inversion = SDXLDDIMPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True) # .to('cpu')
|
39 |
+
pipe_inference = AutoPipelineForImage2Image.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True) # .to('cpu')
|
|
|
40 |
pipe_inference.scheduler = scheduler_class.from_config(pipe_inference.scheduler.config)
|
41 |
pipe_inversion.scheduler = scheduler_class.from_config(pipe_inversion.scheduler.config)
|
42 |
pipe_inversion.scheduler_inference = scheduler_class.from_config(pipe_inference.scheduler.config)
|
43 |
|
44 |
+
if device == "cuda":
|
45 |
+
pipe_inference.enable_xformers_memory_efficient_attention()
|
46 |
+
pipe_inversion.enable_xformers_memory_efficient_attention()
|
47 |
|
48 |
|
49 |
|
src/editor.py
CHANGED
@@ -44,7 +44,7 @@ class ImageEditorDemo:
|
|
44 |
img_size = (512,512)
|
45 |
VQAE_SCALE = 8
|
46 |
latents_size = (1, 4, img_size[0] // VQAE_SCALE, img_size[1] // VQAE_SCALE)
|
47 |
-
noise = [randn_tensor(latents_size, dtype=torch.
|
48 |
in range(cfg.num_inversion_steps)]
|
49 |
pipe_inversion.scheduler.set_noise_list(noise)
|
50 |
pipe_inversion.scheduler_inference.set_noise_list(noise)
|
|
|
44 |
img_size = (512,512)
|
45 |
VQAE_SCALE = 8
|
46 |
latents_size = (1, 4, img_size[0] // VQAE_SCALE, img_size[1] // VQAE_SCALE)
|
47 |
+
noise = [randn_tensor(latents_size, dtype=torch.float32, device=torch.device(device), generator=g_cpu) for i
|
48 |
in range(cfg.num_inversion_steps)]
|
49 |
pipe_inversion.scheduler.set_noise_list(noise)
|
50 |
pipe_inversion.scheduler_inference.set_noise_list(noise)
|
src/euler_scheduler.py
CHANGED
@@ -120,7 +120,7 @@ class MyEulerAncestralDiscreteScheduler(EulerAncestralDiscreteScheduler):
|
|
120 |
sigma = self.sigmas[self.step_index]
|
121 |
|
122 |
# Upcast to avoid precision issues when computing prev_sample
|
123 |
-
|
124 |
|
125 |
# 1. compute predicted original sample (x_0) from sigma-scaled predicted noise
|
126 |
if self.config.prediction_type == "epsilon":
|
@@ -226,7 +226,7 @@ class MyEulerAncestralDiscreteScheduler(EulerAncestralDiscreteScheduler):
|
|
226 |
sigma = self.sigmas[self.step_index]
|
227 |
|
228 |
# Upcast to avoid precision issues when computing prev_sample
|
229 |
-
|
230 |
|
231 |
# 1. compute predicted original sample (x_0) from sigma-scaled predicted noise
|
232 |
if self.config.prediction_type == "epsilon":
|
@@ -342,7 +342,7 @@ class MyEulerAncestralDiscreteScheduler(EulerAncestralDiscreteScheduler):
|
|
342 |
sigma = self.sigmas[self.step_index]
|
343 |
|
344 |
# Upcast to avoid precision issues when computing prev_sample
|
345 |
-
|
346 |
|
347 |
# 1. compute predicted original sample (x_0) from sigma-scaled predicted noise
|
348 |
if self.config.prediction_type == "epsilon":
|
@@ -394,7 +394,7 @@ class MyEulerAncestralDiscreteScheduler(EulerAncestralDiscreteScheduler):
|
|
394 |
|
395 |
def get_all_sigmas(self) -> torch.FloatTensor:
|
396 |
sigmas = np.array(((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5)
|
397 |
-
sigmas = np.concatenate([sigmas[::-1], [0.0]])
|
398 |
return torch.from_numpy(sigmas)
|
399 |
|
400 |
def add_noise_off_schedule(
|
@@ -408,7 +408,7 @@ class MyEulerAncestralDiscreteScheduler(EulerAncestralDiscreteScheduler):
|
|
408 |
sigmas = sigmas.to(device=original_samples.device, dtype=original_samples.dtype)
|
409 |
if original_samples.device.type == "mps" and torch.is_floating_point(timesteps):
|
410 |
# mps does not support float64
|
411 |
-
timesteps = timesteps.to(original_samples
|
412 |
else:
|
413 |
timesteps = timesteps.to(original_samples.device)
|
414 |
|
@@ -539,7 +539,7 @@ class MyEulerAncestralDiscreteScheduler(EulerAncestralDiscreteScheduler):
|
|
539 |
# sigma = self.sigmas[self.step_index]
|
540 |
|
541 |
# # Upcast to avoid precision issues when computing prev_sample
|
542 |
-
|
543 |
|
544 |
# # 1. compute predicted original sample (x_0) from sigma-scaled predicted noise
|
545 |
# if self.config.prediction_type == "epsilon":
|
|
|
120 |
sigma = self.sigmas[self.step_index]
|
121 |
|
122 |
# Upcast to avoid precision issues when computing prev_sample
|
123 |
+
sample = sample.to(torch.float32)
|
124 |
|
125 |
# 1. compute predicted original sample (x_0) from sigma-scaled predicted noise
|
126 |
if self.config.prediction_type == "epsilon":
|
|
|
226 |
sigma = self.sigmas[self.step_index]
|
227 |
|
228 |
# Upcast to avoid precision issues when computing prev_sample
|
229 |
+
sample = sample.to(torch.float32)
|
230 |
|
231 |
# 1. compute predicted original sample (x_0) from sigma-scaled predicted noise
|
232 |
if self.config.prediction_type == "epsilon":
|
|
|
342 |
sigma = self.sigmas[self.step_index]
|
343 |
|
344 |
# Upcast to avoid precision issues when computing prev_sample
|
345 |
+
sample = sample.to(torch.float32)
|
346 |
|
347 |
# 1. compute predicted original sample (x_0) from sigma-scaled predicted noise
|
348 |
if self.config.prediction_type == "epsilon":
|
|
|
394 |
|
395 |
def get_all_sigmas(self) -> torch.FloatTensor:
|
396 |
sigmas = np.array(((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5)
|
397 |
+
sigmas = np.concatenate([sigmas[::-1], [0.0]]).astype(np.float32)
|
398 |
return torch.from_numpy(sigmas)
|
399 |
|
400 |
def add_noise_off_schedule(
|
|
|
408 |
sigmas = sigmas.to(device=original_samples.device, dtype=original_samples.dtype)
|
409 |
if original_samples.device.type == "mps" and torch.is_floating_point(timesteps):
|
410 |
# mps does not support float64
|
411 |
+
timesteps = timesteps.to(original_samples.device, dtype=torch.float32)
|
412 |
else:
|
413 |
timesteps = timesteps.to(original_samples.device)
|
414 |
|
|
|
539 |
# sigma = self.sigmas[self.step_index]
|
540 |
|
541 |
# # Upcast to avoid precision issues when computing prev_sample
|
542 |
+
sample = sample.to(torch.float32)
|
543 |
|
544 |
# # 1. compute predicted original sample (x_0) from sigma-scaled predicted noise
|
545 |
# if self.config.prediction_type == "epsilon":
|