Hussein Claude Opus 5 (1M context) commited on
Commit
85d3028
·
1 Parent(s): c9c3030

Resolve tf32 against the GPU, and reject GPUs PyTorch cannot use

Browse files

Second GPU run got past LoRA injection and died building the trainer:

error: --tf32 requires Ampere or a newer GPU arch, cuda>=11 and torch>=1.7

The configs enable tf32 because it is free speed where it exists, but the guard
was `config.tf32 if torch.cuda.is_available() else False` -- which asks whether
there is a GPU, not whether that GPU has TF32. Anything below Ampere reaches
Transformers, which raises rather than ignoring the flag. Resolve it against the
device instead, the way the script already resolves precision, and say so when a
requested tf32 is dropped. Losing tf32 costs speed; failing the run costs the
whole run.

Preflight also let this through, and let through the larger problem behind it: a
Tesla P100 is sm_60, PyTorch 2.10 compiles for sm_70 and up, and such a GPU is
visible, reports its memory, and satisfies `is_available()` before failing at the
first kernel launch. Compare each device against `torch.cuda.get_arch_list()` and
refuse there -- preflight exists to fail in seconds rather than mid-run, and this
run spent seventeen minutes reaching a wall it could have named at the start.

The local smoke config had tf32 off, which is why no local run reproduced this.
It is on now, and both Transformers versions pass; the new unit tests drive the
capability logic directly with stand-in devices, so neither branch depends on
what hardware happens to be present.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uis9uRynosX69gefzFQeNN

src/buddi_asr/training/runtime.py CHANGED
@@ -13,6 +13,54 @@ from buddi_asr.data.validate import validate_manifest
13
  from buddi_asr.errors import ManifestError, OptionalDependencyError
14
  from buddi_asr.training.config import load_train_config
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  def _gib(byte_count: int) -> float:
18
  return round(byte_count / (1024**3), 2)
@@ -177,6 +225,14 @@ def run_gpu_preflight(
177
  "CUDA is not available to PyTorch. Use an NVIDIA PyTorch image or install the "
178
  "matching CUDA wheel from https://pytorch.org/get-started/locally/."
179
  )
 
 
 
 
 
 
 
 
180
  runtime = collect_runtime_metadata(torch)
181
  if minimum_free_vram_gib < 0:
182
  raise ValueError("minimum_free_vram_gib cannot be negative")
@@ -217,11 +273,15 @@ def run_gpu_preflight(
217
  )
218
  checkpoint = resolve_resume_checkpoint(config.resume_from_checkpoint, output_dir)
219
  precision = "bf16" if config.bf16 else "fp16" if config.fp16 else "fp32"
 
 
 
220
  return {
221
  "ok": True,
222
  "model": config.model_name_or_path,
223
  "method": config.method,
224
  "precision": precision,
 
225
  "output_dir": str(output_dir),
226
  "resume_checkpoint": str(checkpoint) if checkpoint else None,
227
  "per_device_train_batch_size": config.per_device_train_batch_size,
 
13
  from buddi_asr.errors import ManifestError, OptionalDependencyError
14
  from buddi_asr.training.config import load_train_config
15
 
16
+ # TF32 needs Ampere (compute capability 8.0). Turing and Pascal reject it, and
17
+ # Transformers raises rather than ignoring the flag:
18
+ # --tf32 requires Ampere or a newer GPU arch, cuda>=11 and torch>=1.7
19
+ # The configs turn it on because it is free speed where it exists, so resolve it
20
+ # against the device the same way precision is resolved, instead of failing a
21
+ # run over a performance knob.
22
+ TF32_MINIMUM_CAPABILITY = (8, 0)
23
+
24
+
25
+ def resolve_tf32(torch: Any, requested: bool) -> bool:
26
+ """Whether TF32 can actually be enabled on the visible devices."""
27
+
28
+ if not requested or not torch.cuda.is_available():
29
+ return False
30
+ return all(
31
+ torch.cuda.get_device_capability(index) >= TF32_MINIMUM_CAPABILITY
32
+ for index in range(torch.cuda.device_count())
33
+ )
34
+
35
+
36
+ def unsupported_devices(torch: Any) -> list[str]:
37
+ """Visible GPUs the installed PyTorch has no compiled kernels for.
38
+
39
+ A GPU older than the build's oldest target is visible to CUDA, reports its
40
+ memory, and passes `is_available()` -- then fails at the first kernel launch.
41
+ PyTorch 2.10 dropped sm_60, so a Kaggle P100 gets that far and no further.
42
+ Reading the arch list turns a mid-run failure into a preflight message.
43
+ """
44
+
45
+ try:
46
+ arch_list = torch.cuda.get_arch_list()
47
+ except Exception: # older torch, or a build without the attribute
48
+ return []
49
+ supported = {
50
+ int(name.removeprefix("sm_"))
51
+ for name in arch_list
52
+ if name.startswith("sm_") and name.removeprefix("sm_").isdigit()
53
+ }
54
+ if not supported:
55
+ return []
56
+ unsupported = []
57
+ for index in range(torch.cuda.device_count()):
58
+ major, minor = torch.cuda.get_device_capability(index)
59
+ if major * 10 + minor not in supported:
60
+ name = torch.cuda.get_device_properties(index).name
61
+ unsupported.append(f"GPU {index} ({name}, sm_{major}{minor})")
62
+ return unsupported
63
+
64
 
65
  def _gib(byte_count: int) -> float:
66
  return round(byte_count / (1024**3), 2)
 
225
  "CUDA is not available to PyTorch. Use an NVIDIA PyTorch image or install the "
226
  "matching CUDA wheel from https://pytorch.org/get-started/locally/."
227
  )
228
+ incompatible = unsupported_devices(torch)
229
+ if incompatible:
230
+ raise RuntimeError(
231
+ "This PyTorch build has no kernels for: "
232
+ + ", ".join(incompatible)
233
+ + f". It was compiled for {', '.join(torch.cuda.get_arch_list())}. "
234
+ "Select a newer accelerator or install a build that targets this GPU."
235
+ )
236
  runtime = collect_runtime_metadata(torch)
237
  if minimum_free_vram_gib < 0:
238
  raise ValueError("minimum_free_vram_gib cannot be negative")
 
273
  )
274
  checkpoint = resolve_resume_checkpoint(config.resume_from_checkpoint, output_dir)
275
  precision = "bf16" if config.bf16 else "fp16" if config.fp16 else "fp32"
276
+ tf32 = resolve_tf32(torch, config.tf32)
277
+ if config.tf32 and not tf32:
278
+ warnings.append("tf32 requested but the visible GPUs predate Ampere; it will be off")
279
  return {
280
  "ok": True,
281
  "model": config.model_name_or_path,
282
  "method": config.method,
283
  "precision": precision,
284
+ "tf32": tf32,
285
  "output_dir": str(output_dir),
286
  "resume_checkpoint": str(checkpoint) if checkpoint else None,
287
  "per_device_train_batch_size": config.per_device_train_batch_size,
src/buddi_asr/training/train.py CHANGED
@@ -13,7 +13,11 @@ from buddi_asr.metrics import score_pairs
13
  from buddi_asr.training.collator import WhisperDataCollator
14
  from buddi_asr.training.config import load_train_config
15
  from buddi_asr.training.dataset import ManifestSpeechDataset
16
- from buddi_asr.training.runtime import collect_runtime_metadata, resolve_resume_checkpoint
 
 
 
 
17
 
18
 
19
  def _sha256(path: str | Path) -> str:
@@ -129,9 +133,12 @@ def run_training(
129
  output_dir = Path(config.output_dir).resolve()
130
  output_dir.mkdir(parents=True, exist_ok=True)
131
  resume_checkpoint = resolve_resume_checkpoint(config.resume_from_checkpoint, output_dir)
 
 
 
132
  if torch.cuda.is_available():
133
- torch.backends.cuda.matmul.allow_tf32 = config.tf32
134
- torch.backends.cudnn.allow_tf32 = config.tf32
135
  runtime = collect_runtime_metadata(torch)
136
  processor = WhisperProcessor.from_pretrained(config.model_name_or_path)
137
  model = WhisperForConditionalGeneration.from_pretrained(config.model_name_or_path)
@@ -232,7 +239,7 @@ def run_training(
232
  report_to=config.report_to,
233
  dataloader_num_workers=config.dataloader_num_workers,
234
  dataloader_pin_memory=config.dataloader_pin_memory,
235
- tf32=config.tf32 if torch.cuda.is_available() else False,
236
  ddp_find_unused_parameters=config.ddp_find_unused_parameters,
237
  remove_unused_columns=False,
238
  label_names=["labels"],
 
13
  from buddi_asr.training.collator import WhisperDataCollator
14
  from buddi_asr.training.config import load_train_config
15
  from buddi_asr.training.dataset import ManifestSpeechDataset
16
+ from buddi_asr.training.runtime import (
17
+ collect_runtime_metadata,
18
+ resolve_resume_checkpoint,
19
+ resolve_tf32,
20
+ )
21
 
22
 
23
  def _sha256(path: str | Path) -> str:
 
133
  output_dir = Path(config.output_dir).resolve()
134
  output_dir.mkdir(parents=True, exist_ok=True)
135
  resume_checkpoint = resolve_resume_checkpoint(config.resume_from_checkpoint, output_dir)
136
+ tf32 = resolve_tf32(torch, config.tf32)
137
+ if config.tf32 and not tf32 and torch.cuda.is_available():
138
+ print("tf32 requested but the visible GPUs predate Ampere; continuing without it")
139
  if torch.cuda.is_available():
140
+ torch.backends.cuda.matmul.allow_tf32 = tf32
141
+ torch.backends.cudnn.allow_tf32 = tf32
142
  runtime = collect_runtime_metadata(torch)
143
  processor = WhisperProcessor.from_pretrained(config.model_name_or_path)
144
  model = WhisperForConditionalGeneration.from_pretrained(config.model_name_or_path)
 
239
  report_to=config.report_to,
240
  dataloader_num_workers=config.dataloader_num_workers,
241
  dataloader_pin_memory=config.dataloader_pin_memory,
242
+ tf32=tf32,
243
  ddp_find_unused_parameters=config.ddp_find_unused_parameters,
244
  remove_unused_columns=False,
245
  label_names=["labels"],
tests/test_gpu_capability.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import unittest
4
+
5
+ from buddi_asr.training.runtime import resolve_tf32, unsupported_devices
6
+
7
+
8
+ class FakeProperties:
9
+ def __init__(self, name: str) -> None:
10
+ self.name = name
11
+
12
+
13
+ class FakeCuda:
14
+ """Just enough of `torch.cuda` for the capability checks."""
15
+
16
+ def __init__(self, capabilities, arch_list=("sm_70", "sm_75", "sm_80", "sm_90")):
17
+ self._capabilities = capabilities
18
+ self._arch_list = list(arch_list)
19
+
20
+ def is_available(self) -> bool:
21
+ return bool(self._capabilities)
22
+
23
+ def device_count(self) -> int:
24
+ return len(self._capabilities)
25
+
26
+ def get_device_capability(self, index: int):
27
+ return self._capabilities[index]
28
+
29
+ def get_device_properties(self, index: int) -> FakeProperties:
30
+ return FakeProperties(f"Fake {self._capabilities[index]}")
31
+
32
+ def get_arch_list(self):
33
+ return self._arch_list
34
+
35
+
36
+ class FakeTorch:
37
+ def __init__(self, capabilities, arch_list=("sm_70", "sm_75", "sm_80", "sm_90")):
38
+ self.cuda = FakeCuda(capabilities, arch_list)
39
+
40
+
41
+ class ResolveTf32Tests(unittest.TestCase):
42
+ def test_ampere_gets_tf32(self) -> None:
43
+ self.assertTrue(resolve_tf32(FakeTorch([(8, 0)]), True))
44
+
45
+ def test_turing_does_not(self) -> None:
46
+ # A Kaggle T4 is sm_75. Transformers raises on tf32=True there, so this
47
+ # has to come back False rather than let the run reach that error.
48
+ self.assertFalse(resolve_tf32(FakeTorch([(7, 5)]), True))
49
+
50
+ def test_a_single_older_gpu_disables_it_for_all(self) -> None:
51
+ self.assertFalse(resolve_tf32(FakeTorch([(8, 6), (7, 5)]), True))
52
+
53
+ def test_off_stays_off(self) -> None:
54
+ self.assertFalse(resolve_tf32(FakeTorch([(9, 0)]), False))
55
+
56
+ def test_no_cuda_is_off(self) -> None:
57
+ self.assertFalse(resolve_tf32(FakeTorch([]), True))
58
+
59
+
60
+ class UnsupportedDeviceTests(unittest.TestCase):
61
+ def test_pascal_is_rejected_by_a_modern_build(self) -> None:
62
+ # The exact case that reached training on Kaggle: a P100 is sm_60 and
63
+ # torch 2.10 ships no kernels below sm_70.
64
+ found = unsupported_devices(FakeTorch([(6, 0)]))
65
+ self.assertEqual(len(found), 1)
66
+ self.assertIn("sm_60", found[0])
67
+
68
+ def test_supported_devices_report_nothing(self) -> None:
69
+ self.assertEqual(unsupported_devices(FakeTorch([(7, 5), (8, 0)])), [])
70
+
71
+ def test_an_empty_arch_list_is_not_treated_as_rejecting_everything(self) -> None:
72
+ self.assertEqual(unsupported_devices(FakeTorch([(6, 0)], arch_list=())), [])