multimodalart HF Staff commited on
Commit
6e456ff
·
verified ·
1 Parent(s): 433b691

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +11 -9
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
- # Attention mask: text uses its key-padding mask, all image tokens (src+tgt) valid.
 
 
 
 
 
286
  attention_mask = None
287
- if prompt_mask is not None:
288
- img_ones = prompt_mask.new_ones((combined_img.shape[0], combined_img.shape[1]))
289
- attention_mask = torch.cat([prompt_mask, img_ones], dim=1)[:, None, None, :]
290
-
291
- # Force the math SDPA kernel. The flash / mem-efficient kernels probe the
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