Spaces:
Running on Zero
Running on Zero
File size: 2,152 Bytes
51e9717 c3fa125 51e9717 c3fa125 51e9717 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
import gradio as gr
import numpy as np
import soundfile as sf
from tiger_ui.errors import describe_error
from tiger_ui.gpu_budget import gpu_duration
class QuotaTests(unittest.TestCase):
def test_actual_failure_is_actionable(self):
exc=gr.Error('You have exceeded your ZeroGPU quota (90s requested vs. 43s left). Try again in 19:17:51. ',title='ZeroGPU quota exceeded')
self.assertEqual(describe_error(exc),{'error':'gpu_quota','requested_seconds':90.0,'remaining_seconds':43.0,'retry_after_seconds':69471})
def test_run_count_limit_is_not_a_duration_shortfall(self):
self.assertEqual(describe_error(gr.Error('You have exceeded your ZeroGPU runs limit.',title='ZeroGPU quota exceeded')),{'error':'gpu_runs_limit'})
def test_unknown_messages_do_not_leak_paths_or_html(self):
self.assertEqual(describe_error(RuntimeError('/private/path secret')) ,{'error':'failed'})
self.assertEqual(describe_error(gr.Error('<a href="https://example.org">No GPU available</a>',title='ZeroGPU queue timeout')),{'error':'gpu_unavailable'})
def test_budget_matches_duration_and_stays_below_reported_quota(self):
with tempfile.TemporaryDirectory() as temp:
p=Path(temp)/'sample.wav'
for seconds,expected in [(6,18),(60,25),(180,59),(300,92)]:
sf.write(p,np.zeros(seconds*8000,dtype='float32'),8000)
self.assertEqual(gpu_duration(str(p),'stems'),expected)
self.assertEqual(gpu_duration(str(p),'speakers'),32)
sf.write(p,np.zeros(301*8000,dtype='float32'),8000)
for task in ['stems','speakers']:
with self.assertRaisesRegex(ValueError,'duration'):
gpu_duration(str(p),task)
sf.write(p,np.zeros(60*8000,dtype='float32'),8000)
# Observed hardware factor: old default 60 * 1.5 = 90 seconds.
self.assertLess(gpu_duration(str(p),'stems')*1.5,43)
self.assertGreaterEqual(gpu_duration(str(p),'speakers'),12)
if __name__=='__main__':unittest.main()
|