Spaces:
Running
on
Zero
Running
on
Zero
arthur-qiu
commited on
Commit
•
c8dda36
1
Parent(s):
0a9f009
init
Browse files- app.py +6 -6
- free_lunch_utils.py +1 -1
app.py
CHANGED
@@ -9,14 +9,11 @@ from pipeline_freescale import StableDiffusionXLPipeline
|
|
9 |
from free_lunch_utils import register_free_upblock2d, register_free_crossattn_upblock2d
|
10 |
|
11 |
@spaces.GPU(duration=120)
|
12 |
-
def infer_gpu_part(pipe, seed, prompt, negative_prompt, ddim_steps, guidance_scale, resolutions_list, fast_mode, cosine_scale
|
13 |
pipe = pipe.to("cuda")
|
14 |
generator = torch.Generator(device='cuda')
|
15 |
generator = generator.manual_seed(seed)
|
16 |
-
|
17 |
-
register_free_upblock2d(pipe, b1=1.1, b2=1.2, s1=0.6, s2=0.4)
|
18 |
-
register_free_crossattn_upblock2d(pipe, b1=1.1, b2=1.2, s1=0.6, s2=0.4)
|
19 |
-
resul = pipe(prompt, negative_prompt=negative_prompt, generator=generator,
|
20 |
num_inference_steps=ddim_steps, guidance_scale=guidance_scale,
|
21 |
resolutions_list=resolutions_list, fast_mode=fast_mode, cosine_scale=cosine_scale,
|
22 |
)
|
@@ -44,9 +41,12 @@ def infer(prompt, output_size, ddim_steps, guidance_scale, cosine_scale, seed, o
|
|
44 |
|
45 |
model_ckpt = "stabilityai/stable-diffusion-xl-base-1.0"
|
46 |
pipe = StableDiffusionXLPipeline.from_pretrained(model_ckpt, torch_dtype=torch.float16)
|
|
|
|
|
|
|
47 |
|
48 |
print('GPU starts')
|
49 |
-
result = infer_gpu_part(pipe, seed, prompt, negative_prompt, ddim_steps, guidance_scale, resolutions_list, fast_mode, cosine_scale
|
50 |
print('GPU ends')
|
51 |
|
52 |
image = result.images[0]
|
|
|
9 |
from free_lunch_utils import register_free_upblock2d, register_free_crossattn_upblock2d
|
10 |
|
11 |
@spaces.GPU(duration=120)
|
12 |
+
def infer_gpu_part(pipe, seed, prompt, negative_prompt, ddim_steps, guidance_scale, resolutions_list, fast_mode, cosine_scale):
|
13 |
pipe = pipe.to("cuda")
|
14 |
generator = torch.Generator(device='cuda')
|
15 |
generator = generator.manual_seed(seed)
|
16 |
+
result = pipe(prompt, negative_prompt=negative_prompt, generator=generator,
|
|
|
|
|
|
|
17 |
num_inference_steps=ddim_steps, guidance_scale=guidance_scale,
|
18 |
resolutions_list=resolutions_list, fast_mode=fast_mode, cosine_scale=cosine_scale,
|
19 |
)
|
|
|
41 |
|
42 |
model_ckpt = "stabilityai/stable-diffusion-xl-base-1.0"
|
43 |
pipe = StableDiffusionXLPipeline.from_pretrained(model_ckpt, torch_dtype=torch.float16)
|
44 |
+
if not disable_freeu:
|
45 |
+
register_free_upblock2d(pipe, b1=1.1, b2=1.2, s1=0.6, s2=0.4)
|
46 |
+
register_free_crossattn_upblock2d(pipe, b1=1.1, b2=1.2, s1=0.6, s2=0.4)
|
47 |
|
48 |
print('GPU starts')
|
49 |
+
result = infer_gpu_part(pipe, seed, prompt, negative_prompt, ddim_steps, guidance_scale, resolutions_list, fast_mode, cosine_scale)
|
50 |
print('GPU ends')
|
51 |
|
52 |
image = result.images[0]
|
free_lunch_utils.py
CHANGED
@@ -30,7 +30,7 @@ def Fourier_filter(x, threshold, scale):
|
|
30 |
x_freq = fft.fftshift(x_freq, dim=(-2, -1))
|
31 |
|
32 |
B, C, H, W = x_freq.shape
|
33 |
-
mask = torch.ones((B, C, H, W)).
|
34 |
|
35 |
crow, ccol = H // 2, W //2
|
36 |
mask[..., crow - threshold:crow + threshold, ccol - threshold:ccol + threshold] = scale
|
|
|
30 |
x_freq = fft.fftshift(x_freq, dim=(-2, -1))
|
31 |
|
32 |
B, C, H, W = x_freq.shape
|
33 |
+
mask = torch.ones((B, C, H, W)).to(x.device)
|
34 |
|
35 |
crow, ccol = H // 2, W //2
|
36 |
mask[..., crow - threshold:crow + threshold, ccol - threshold:ccol + threshold] = scale
|