multimodalart HF Staff commited on
Commit
e90a28b
·
verified ·
1 Parent(s): bcd0340

Pin batch size and GPU duration to measured cost

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -378,7 +378,7 @@ def _gpu_duration(*args, **kwargs):
378
  factor = (float(side) / DEFAULT_MAX_SIDE) ** 2.5
379
  except Exception:
380
  work, factor = DEFAULT_NUM_STEPS * DEFAULT_NUM_FRAMES, 1.0
381
- return int(min(180, max(30, 18 + work * 0.045 * factor)))
382
 
383
 
384
  @spaces.GPU(duration=_gpu_duration)
@@ -460,10 +460,10 @@ def analyze(
460
  t_prep = time.perf_counter() - t1
461
 
462
  seq_len = int(samples[0]["input_ids"].shape[-1])
463
- # `pred_slot_isolated_eager` materialises a full B×32×L×L attention matrix,
464
- # so the batch size is memory- rather than compute-bound. Start optimistic
465
- # and halve on OOM (see the loop below).
466
- batch_size = 8 if seq_len <= 3600 else (4 if seq_len <= 5400 else 2)
467
 
468
  def run_batch(batch):
469
  kwargs = dict(
 
378
  factor = (float(side) / DEFAULT_MAX_SIDE) ** 2.5
379
  except Exception:
380
  work, factor = DEFAULT_NUM_STEPS * DEFAULT_NUM_FRAMES, 1.0
381
+ return int(min(180, max(30, 18 + work * 0.042 * factor)))
382
 
383
 
384
  @spaces.GPU(duration=_gpu_duration)
 
460
  t_prep = time.perf_counter() - t1
461
 
462
  seq_len = int(samples[0]["input_ids"].shape[-1])
463
+ # `pred_slot_isolated_eager` materialises a full B×32×L×L attention matrix.
464
+ # Measured: batch 8 is no faster than batch 4 here (compute-bound), so keep
465
+ # the smaller batch and halve further on OOM (see the loop below).
466
+ batch_size = 4 if seq_len <= 3600 else (2 if seq_len <= 5400 else 1)
467
 
468
  def run_batch(batch):
469
  kwargs = dict(