topabaem commited on
Commit
b0a01d0
·
verified ·
1 Parent(s): b5560c8

Check for kernels before loading, not after

Browse files
Files changed (1) hide show
  1. ltx_packed_codec.py +42 -0
ltx_packed_codec.py CHANGED
@@ -511,6 +511,46 @@ def resident_bytes(model) -> int:
511
  return total
512
 
513
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
514
  def load_packed_model(model_dir: str, packed_path: Path | str,
515
  gpu_budget: str | None = None, resident: bool = False,
516
  fold_pre_scale: bool = False, device: str | None = None):
@@ -537,6 +577,8 @@ def load_packed_model(model_dir: str, packed_path: Path | str,
537
  import os
538
  import re
539
 
 
 
540
  if gpu_budget is None:
541
  gpu_budget = os.environ.get("LTX_PACKED_GPU_BUDGET", "13GiB")
542
 
 
511
  return total
512
 
513
 
514
+ def check_gpu_kernels(device: str | None = None) -> None:
515
+ """Refuse a wheel that has no kernels for this card, and say what to install.
516
+
517
+ Nothing in this format needs anything unusual from a GPU - no fp8 units, no
518
+ minimum compute capability, no bf16 tensor cores. What can be missing is
519
+ PyTorch's own kernels: the current default wheel on PyPI is a cu130 build,
520
+ and cu130 dropped Volta.
521
+
522
+ Left alone, that surfaces as
523
+
524
+ CUDA error: no kernel image is available for execution on the device
525
+
526
+ raised from the first kernel launch - which is after an 8.46 GB load, inside
527
+ somebody else's library, and long after `torch.cuda.is_available()` returned
528
+ True. Checking `get_arch_list` costs nothing and moves the failure to the
529
+ place where the fix makes sense.
530
+ """
531
+ if device is not None and not str(device).startswith("cuda"):
532
+ return
533
+ if not torch.cuda.is_available():
534
+ return
535
+
536
+ major, minor = torch.cuda.get_device_capability(0)
537
+ arch = f"sm_{major}{minor}"
538
+ compiled = torch.cuda.get_arch_list()
539
+ # An empty list means a build that does not report them; do not guess.
540
+ if not compiled or arch in compiled:
541
+ return
542
+
543
+ name = torch.cuda.get_device_name(0)
544
+ raise SystemExit(
545
+ f"this torch ({torch.__version__}) has no kernels for {name} ({arch}).\n"
546
+ f"It was built for {', '.join(compiled)}, and the first CUDA op would "
547
+ f"fail with 'no kernel image is available for execution on the device'.\n"
548
+ f"The model is fine - it needs no custom kernels. Install a torch built "
549
+ f"for your card, e.g. for {arch}:\n"
550
+ f" pip install torch --index-url https://download.pytorch.org/whl/cu128\n"
551
+ f"or pass device='cpu' to load without touching the GPU.")
552
+
553
+
554
  def load_packed_model(model_dir: str, packed_path: Path | str,
555
  gpu_budget: str | None = None, resident: bool = False,
556
  fold_pre_scale: bool = False, device: str | None = None):
 
577
  import os
578
  import re
579
 
580
+ check_gpu_kernels(device)
581
+
582
  if gpu_budget is None:
583
  gpu_budget = os.environ.get("LTX_PACKED_GPU_BUDGET", "13GiB")
584