Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -282,16 +282,18 @@ def _edit_transformer_forward(latents, src_packed, prompt_embeds, prompt_mask,
|
|
| 282 |
|
| 283 |
image_rotary_emb = m.rotary_emb(position_ids)
|
| 284 |
|
| 285 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
attention_mask = None
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
# device via NVML, which on ZeroGPU's forked CUDA context triggers
|
| 293 |
-
# "NVML_SUCCESS == r INTERNAL ASSERT FAILED" inside the caching allocator.
|
| 294 |
-
with sdpa_kernel([SDPBackend.MATH]):
|
| 295 |
for block in m.transformer_blocks:
|
| 296 |
hidden = block(hidden, temb_mod, image_rotary_emb, attention_mask)
|
| 297 |
|
|
|
|
| 282 |
|
| 283 |
image_rotary_emb = m.rotary_emb(position_ids)
|
| 284 |
|
| 285 |
+
# Single prompt, batch=1: the grounded encode uses padding=True on one
|
| 286 |
+
# sequence, so there is no padding and every token is valid. Passing
|
| 287 |
+
# attention_mask=None lets SDPA pick the flash / mem-efficient kernels
|
| 288 |
+
# (a dense boolean mask would force the score-materializing math path and
|
| 289 |
+
# OOM given the doubled token count). If padding is ever introduced (batched
|
| 290 |
+
# or CFG with unequal lengths), trim to the shorter length instead of masking.
|
| 291 |
attention_mask = None
|
| 292 |
+
|
| 293 |
+
# Prefer the flash / mem-efficient SDPA kernels (they never materialize the
|
| 294 |
+
# full seq x seq score matrix, which the MATH kernel would OOM on given the
|
| 295 |
+
# doubled token count from prepending the source latent).
|
| 296 |
+
with sdpa_kernel([SDPBackend.FLASH_ATTENTION, SDPBackend.EFFICIENT_ATTENTION]):
|
|
|
|
|
|
|
|
|
|
| 297 |
for block in m.transformer_blocks:
|
| 298 |
hidden = block(hidden, temb_mod, image_rotary_emb, attention_mask)
|
| 299 |
|