Files
Athena-Deck/test_tts_ram.py
T
Mikei386 c0bc5d3a1b Integrate Basalt telemetry and shared GPU speech runtimes
Publish the reviewed accumulated runtime, scheduler, profile, UI, native recipes and historical maintenance evidence. Includes Qwen GPU ASR correction and shared Anna/atelier ownership. Validated with 784 local tests, Python/JSON parsing and eight JavaScript syntax checks. Live GPU acceptance and full fresh-host restore limits remain documented.
2026-11-03 21:16:41 +01:00

58 lines
3.5 KiB
Python

"""Regression: cold-load budgeting must not reject resident GPU TTS at 8 GiB."""
import tempfile,unittest
from pathlib import Path
from types import SimpleNamespace
from unittest.mock import Mock,patch
from tts_test import TTSTests
GIB=1024**3
MIB=1024**2
class TTSRAMTests(unittest.TestCase):
def fixture(self,root,resident=False,weight_bytes=3*GIB):
model=root/'model';model.mkdir()
with (model/'model.safetensors').open('wb') as f:f.truncate(weight_bytes)
runtime=SimpleNamespace(paths=lambda:(root/'python',model))
profiles=SimpleNamespace(status=lambda:{'profiles':[dict(id='tts',kind='audio',runnable=True,parameters={'speed':1})]})
worker=TTSTests(root/'jobs',profiles,runtime);worker.acquire=Mock(return_value=Mock())
gpu=dict(uuid='test3060',name='RTX 3060',free_mib=10000,processes=1)
worker._available_gpu=Mock(return_value=gpu);worker._ensure=Mock()
if resident:
worker.process=Mock();worker.process.poll.return_value=None;worker.gpu_uuid=gpu['uuid']
return worker,gpu
def test_resident_request_does_not_require_cold_load_ram(self):
with tempfile.TemporaryDirectory() as tmp:
worker,gpu=self.fixture(Path(tmp),resident=True)
with patch('tts_test.cgroup_headroom',return_value=600*MIB),patch('tts_test.probe',return_value=[gpu]),patch('tts_test.threading.Thread.start'):
self.assertEqual(worker.start('tts','Ein kurzer Test.')['state'],'running')
def test_cold_start_and_warm_use_same_model_based_budget(self):
for operation in ('start','warm'):
with self.subTest(operation=operation),tempfile.TemporaryDirectory() as tmp:
worker,gpu=self.fixture(Path(tmp))
with patch('tts_test.cgroup_headroom',return_value=5*GIB),patch('tts_test.threading.Thread.start'):
if operation=='start':self.assertEqual(worker.start('tts','Ein kurzer Test.')['state'],'running')
else:self.assertTrue(worker.warm('tts'));worker._ensure.assert_called_once()
def test_insufficient_ram_still_rejects_and_releases_reservation(self):
for operation,resident,headroom in (('start',True,256*MIB),('start',False,2*GIB),('warm',False,2*GIB)):
with self.subTest(operation=operation,resident=resident),tempfile.TemporaryDirectory() as tmp:
worker,gpu=self.fixture(Path(tmp),resident=resident);release=worker.acquire.return_value
with patch('tts_test.cgroup_headroom',return_value=headroom),patch('tts_test.probe',return_value=[gpu]),patch('tts_test.threading.Thread.start'):
with self.assertRaisesRegex(ValueError,'RAM'):
worker.start('tts','Ein Test.') if operation=='start' else worker.warm('tts')
release.assert_called_once();worker._ensure.assert_not_called()
def test_cold_budget_tracks_weights_and_keeps_explicit_safety_reserve(self):
for size in (GIB,3*GIB):
with self.subTest(size=size),tempfile.TemporaryDirectory() as tmp:
worker,_=self.fixture(Path(tmp),weight_bytes=size)
self.assertEqual(worker._required_ram_bytes(False),size+GIB)
self.assertEqual(worker._required_ram_bytes(True),512*MIB)
def test_missing_weights_fail_closed_on_cold_start(self):
with tempfile.TemporaryDirectory() as tmp:
worker,_=self.fixture(Path(tmp));(Path(tmp)/'model/model.safetensors').unlink()
with self.assertRaisesRegex(ValueError,'Gewichte'):worker._required_ram_bytes(False)
def test_unknown_cgroup_limit_preserves_existing_admission_behavior(self):
with tempfile.TemporaryDirectory() as tmp:
worker,_=self.fixture(Path(tmp))
with patch('tts_test.cgroup_headroom',return_value=None),patch('tts_test.threading.Thread.start'):
self.assertEqual(worker.start('tts','Ein Test.')['state'],'running')
if __name__=='__main__':unittest.main()