multimodalart HF Staff commited on
Commit
42ed079
·
verified ·
1 Parent(s): ab9a2db

flash-attn 2 wheel, dynamic duration

Browse files
Files changed (2) hide show
  1. app.py +20 -1
  2. requirements.txt +1 -0
app.py CHANGED
@@ -182,7 +182,26 @@ def write_mp4(pixels_tchw: torch.Tensor, path: str) -> None:
182
 
183
 
184
  # ---------------------------------------------------------------------------------- inference
185
- @spaces.GPU(duration=240)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  def generate(
187
  proxy_video: str,
188
  first_frame: Image.Image,
 
182
 
183
 
184
  # ---------------------------------------------------------------------------------- inference
185
+ try:
186
+ import flash_attn # noqa: F401 (the vendored dense_attention uses FlashAttention-2 when present)
187
+
188
+ ATTENTION = "flash_attn"
189
+ except ImportError:
190
+ ATTENTION = "sdpa"
191
+ print(f"[gamewm] attention backend: {ATTENTION}", flush=True)
192
+
193
+ # Measured GPU seconds per denoising step (plus fixed encode/decode cost), see the build log.
194
+ SECONDS_PER_STEP = {"flash_attn": 7.6, "sdpa": 7.6}
195
+ FIXED_SECONDS = 15.0
196
+
197
+
198
+ def gpu_duration(proxy_video, first_frame, caption, character_sheet=None, modality="style",
199
+ steps=30, seed=0, progress=None) -> int:
200
+ per_step = SECONDS_PER_STEP[ATTENTION] * (1.07 if character_sheet is not None else 1.0)
201
+ return int(1.15 * (FIXED_SECONDS + per_step * (int(steps) - 1))) + 1
202
+
203
+
204
+ @spaces.GPU(duration=gpu_duration)
205
  def generate(
206
  proxy_video: str,
207
  first_frame: Image.Image,
requirements.txt CHANGED
@@ -12,3 +12,4 @@ numpy
12
  pillow
13
  pyyaml
14
  imageio
 
 
12
  pillow
13
  pyyaml
14
  imageio
15
+ https://huggingface.co/datasets/multimodalart/zerogpu-blackwell-wheels/resolve/main/wheels/pt212-cu130-cp312/flash_attn-2.8.3-cp312-cp312-linux_x86_64.whl