Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -189,6 +189,8 @@ def _caller_ip_token() -> str | None:
|
|
| 189 |
|
| 190 |
|
| 191 |
@spaces.GPU(duration=240, size=GPU_SIZE)
|
|
|
|
|
|
|
| 192 |
def _generate(prompt_embeds, seed, steps, switch, hr_steps, feather, alpha, use_head, box):
|
| 193 |
"""Run the four-stage two-track sampler and compose to pixels, all on GPU time.
|
| 194 |
|
|
@@ -220,11 +222,11 @@ def _generate(prompt_embeds, seed, steps, switch, hr_steps, feather, alpha, use_
|
|
| 220 |
alpha=float(alpha), feather=float(feather), hr_steps=int(hr_steps),
|
| 221 |
latent_t=latent_t, switch_upscale="crop", final="pixel",
|
| 222 |
)
|
| 223 |
-
#
|
| 224 |
-
#
|
| 225 |
-
#
|
| 226 |
-
#
|
| 227 |
-
#
|
| 228 |
torch.cuda.empty_cache()
|
| 229 |
if "lr" in info: # render()'s guard: the merge inputs exist only on the two-track path
|
| 230 |
pixels = pixel_compose(UPSCALE.vae, latent, info["lr"], info["weight"])
|
|
|
|
| 189 |
|
| 190 |
|
| 191 |
@spaces.GPU(duration=240, size=GPU_SIZE)
|
| 192 |
+
@torch.no_grad() # render() is grad-free end to end; without this the VAE decode of the merge
|
| 193 |
+
# builds a full autograd graph (~24 GB of retained activations) and OOMs the worker
|
| 194 |
def _generate(prompt_embeds, seed, steps, switch, hr_steps, feather, alpha, use_head, box):
|
| 195 |
"""Run the four-stage two-track sampler and compose to pixels, all on GPU time.
|
| 196 |
|
|
|
|
| 222 |
alpha=float(alpha), feather=float(feather), hr_steps=int(hr_steps),
|
| 223 |
latent_t=latent_t, switch_upscale="crop", final="pixel",
|
| 224 |
)
|
| 225 |
+
# Stage boundary, as in the vendored code: the sampler's dual-resolution activations are
|
| 226 |
+
# freed on return but the caching allocator still holds their segments — hand them back
|
| 227 |
+
# so the merge starts from a clean pool. (The full-clip decode OOM here on the first two
|
| 228 |
+
# live runs was the missing no_grad on this function: the VAE decode was retaining a
|
| 229 |
+
# ~24 GB autograd graph that render()'s @torch.no_grad() never builds.)
|
| 230 |
torch.cuda.empty_cache()
|
| 231 |
if "lr" in info: # render()'s guard: the merge inputs exist only on the two-track path
|
| 232 |
pixels = pixel_compose(UPSCALE.vae, latent, info["lr"], info["weight"])
|