multimodalart HF Staff commited on
Commit
c8e7904
·
verified ·
1 Parent(s): 3d2e374

SDPA fallback for the CLIP/DiT flash_attention path; Gradio 6 theme in launch()

Browse files
Files changed (2) hide show
  1. app.py +3 -2
  2. wan/modules/attention.py +18 -0
app.py CHANGED
@@ -407,7 +407,7 @@ CSS = """
407
  .gradio-container { max-width: 1200px !important; }
408
  """
409
 
410
- with gr.Blocks(theme=gr.themes.Citrus(), css=CSS, title="ForgeWM") as demo:
411
  gr.Markdown(
412
  "# 🎮 ForgeWM — few-step action-conditioned world model\n"
413
  "Give it **one Minecraft frame** and a short **action script**; the "
@@ -480,4 +480,5 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS, title="ForgeWM") as demo:
480
  api_name="generate",
481
  )
482
 
483
- demo.queue(max_size=12).launch(mcp_server=True, show_error=True)
 
 
407
  .gradio-container { max-width: 1200px !important; }
408
  """
409
 
410
+ with gr.Blocks(title="ForgeWM") as demo:
411
  gr.Markdown(
412
  "# 🎮 ForgeWM — few-step action-conditioned world model\n"
413
  "Give it **one Minecraft frame** and a short **action script**; the "
 
480
  api_name="generate",
481
  )
482
 
483
+ demo.queue(max_size=12).launch(
484
+ theme=gr.themes.Citrus(), css=CSS, mcp_server=True, show_error=True)
wan/modules/attention.py CHANGED
@@ -26,6 +26,7 @@ import warnings
26
  __all__ = [
27
  'flash_attention',
28
  'attention',
 
29
  ]
30
 
31
 
@@ -57,6 +58,23 @@ def flash_attention(
57
  deterministic: bool. If True, slightly slower and uses more memory.
58
  dtype: torch.dtype. Apply when dtype of q/k/v is not float16/bfloat16.
59
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  half_dtypes = (torch.float16, torch.bfloat16)
61
  assert dtype in half_dtypes
62
  assert q.device.type == 'cuda' and q.size(-1) <= 256
 
26
  __all__ = [
27
  'flash_attention',
28
  'attention',
29
+ 'sdpa_flash_attn_func',
30
  ]
31
 
32
 
 
58
  deterministic: bool. If True, slightly slower and uses more memory.
59
  dtype: torch.dtype. Apply when dtype of q/k/v is not float16/bfloat16.
60
  """
61
+ if not (FLASH_ATTN_2_AVAILABLE or FLASH_ATTN_3_AVAILABLE):
62
+ # No FlashAttention wheel on this platform. Fall back to PyTorch SDPA
63
+ # while preserving the caller's dtype (the FA path would downcast to
64
+ # bfloat16, which we do not want for the fp32 CLIP tower).
65
+ if q_lens is not None or k_lens is not None:
66
+ warnings.warn(
67
+ 'Padding mask is disabled when using scaled_dot_product_attention.')
68
+ if q_scale is not None:
69
+ q = q * q_scale
70
+ return sdpa_flash_attn_func(
71
+ q, k, v,
72
+ dropout_p=dropout_p,
73
+ softmax_scale=softmax_scale,
74
+ causal=causal,
75
+ window_size=window_size,
76
+ )
77
+
78
  half_dtypes = (torch.float16, torch.bfloat16)
79
  assert dtype in half_dtypes
80
  assert q.device.type == 'cuda' and q.size(-1) <= 256