Hussein
Claude Opus 5 (1M context)
Resolve tf32 against the GPU, and reject GPUs PyTorch cannot use
85d3028 Download tests/test_gpu_capability.py from NabuxAi/buddi-asr-source-code: direct link, hf CLI and curl.
- Browser
- Download file 2.54 kB
-
https://huggingface.co/datasets/NabuxAi/buddi-asr-source-code/resolve/main/tests/test_gpu_capability.py
- Command line
-
hf download hf://datasets/NabuxAi/buddi-asr-source-code/tests/test_gpu_capability.py
-
curl -L -o test_gpu_capability.py https://huggingface.co/datasets/NabuxAi/buddi-asr-source-code/resolve/main/tests/test_gpu_capability.py
2.54 kB
| 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=())), []) | |