File size: 2,543 Bytes
85d3028 | 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | from __future__ import annotations
import unittest
from buddi_asr.training.runtime import resolve_tf32, unsupported_devices
class FakeProperties:
def __init__(self, name: str) -> None:
self.name = name
class FakeCuda:
"""Just enough of `torch.cuda` for the capability checks."""
def __init__(self, capabilities, arch_list=("sm_70", "sm_75", "sm_80", "sm_90")):
self._capabilities = capabilities
self._arch_list = list(arch_list)
def is_available(self) -> bool:
return bool(self._capabilities)
def device_count(self) -> int:
return len(self._capabilities)
def get_device_capability(self, index: int):
return self._capabilities[index]
def get_device_properties(self, index: int) -> FakeProperties:
return FakeProperties(f"Fake {self._capabilities[index]}")
def get_arch_list(self):
return self._arch_list
class FakeTorch:
def __init__(self, capabilities, arch_list=("sm_70", "sm_75", "sm_80", "sm_90")):
self.cuda = FakeCuda(capabilities, arch_list)
class ResolveTf32Tests(unittest.TestCase):
def test_ampere_gets_tf32(self) -> None:
self.assertTrue(resolve_tf32(FakeTorch([(8, 0)]), True))
def test_turing_does_not(self) -> None:
# A Kaggle T4 is sm_75. Transformers raises on tf32=True there, so this
# has to come back False rather than let the run reach that error.
self.assertFalse(resolve_tf32(FakeTorch([(7, 5)]), True))
def test_a_single_older_gpu_disables_it_for_all(self) -> None:
self.assertFalse(resolve_tf32(FakeTorch([(8, 6), (7, 5)]), True))
def test_off_stays_off(self) -> None:
self.assertFalse(resolve_tf32(FakeTorch([(9, 0)]), False))
def test_no_cuda_is_off(self) -> None:
self.assertFalse(resolve_tf32(FakeTorch([]), True))
class UnsupportedDeviceTests(unittest.TestCase):
def test_pascal_is_rejected_by_a_modern_build(self) -> None:
# The exact case that reached training on Kaggle: a P100 is sm_60 and
# torch 2.10 ships no kernels below sm_70.
found = unsupported_devices(FakeTorch([(6, 0)]))
self.assertEqual(len(found), 1)
self.assertIn("sm_60", found[0])
def test_supported_devices_report_nothing(self) -> None:
self.assertEqual(unsupported_devices(FakeTorch([(7, 5), (8, 0)])), [])
def test_an_empty_arch_list_is_not_treated_as_rejecting_everything(self) -> None:
self.assertEqual(unsupported_devices(FakeTorch([(6, 0)], arch_list=())), [])
|