Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files188 unmodified lines18919019119219319425 unmodified lines220221222223224225226227228229230188 unmodified lines@spaces.GPU(duration=240, size=GPU_SIZE)def _generate(prompt_embeds, seed, steps, switch, hr_steps, feather, alpha, use_head, box):"""Run the four-stage two-track sampler and compose to pixels, all on GPU time.25 unmodified linesalpha=float(alpha), feather=float(feather), hr_steps=int(hr_steps),latent_t=latent_t, switch_upscale="crop", final="pixel",)# The sampler's dual-resolution activations are freed on return, but the caching allocator# still holds their segments (~20 GB): hand them back before the merge or the VAE decode# starts with ~0 bytes free and dies on PyTorch's NVML assert (it OOM'd the first live run# here even at the port's measured 22-frame size). The vendored code uses this same# empty_cache() idiom at its own stage boundaries.torch.cuda.empty_cache()if "lr" in info: # render()'s guard: the merge inputs exist only on the two-track pathpixels = pixel_compose(UPSCALE.vae, latent, info["lr"], info["weight"])188 unmodified lines18919019119219319419519625 unmodified lines222223224225226227228229230231232188 unmodified lines@spaces.GPU(duration=240, size=GPU_SIZE)@torch.no_grad() # render() is grad-free end to end; without this the VAE decode of the merge# builds a full autograd graph (~24 GB of retained activations) and OOMs the workerdef _generate(prompt_embeds, seed, steps, switch, hr_steps, feather, alpha, use_head, box):"""Run the four-stage two-track sampler and compose to pixels, all on GPU time.25 unmodified linesalpha=float(alpha), feather=float(feather), hr_steps=int(hr_steps),latent_t=latent_t, switch_upscale="crop", final="pixel",)# Stage boundary, as in the vendored code: the sampler's dual-resolution activations are# freed on return but the caching allocator still holds their segments — hand them back# so the merge starts from a clean pool. (The full-clip decode OOM here on the first two# live runs was the missing no_grad on this function: the VAE decode was retaining a# ~24 GB autograd graph that render()'s @torch.no_grad() never builds.)torch.cuda.empty_cache()if "lr" in info: # render()'s guard: the merge inputs exist only on the two-track pathpixels = pixel_compose(UPSCALE.vae, latent, info["lr"], info["weight"])
app.py+7-5