multimodalart HF Staff commited on
Commit
81df4d4
·
verified ·
1 Parent(s): d2db40e

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +7 -5
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
- # The sampler's dual-resolution activations are freed on return, but the caching allocator
224
- # still holds their segments (~20 GB): hand them back before the merge or the VAE decode
225
- # starts with ~0 bytes free and dies on PyTorch's NVML assert (it OOM'd the first live run
226
- # here even at the port's measured 22-frame size). The vendored code uses this same
227
- # empty_cache() idiom at its own stage boundaries.
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"])