collinschreyer-dev commited on
Commit
0d2be74
·
1 Parent(s): 731a3f9

Add GPU debug logging to diagnose CUDA detection issue

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -38,9 +38,34 @@ PROCESSOR = None
38
 
39
  def get_device():
40
  """Detect GPU at runtime, not import time."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  if torch.cuda.is_available():
 
 
42
  return "cuda"
 
43
  return "cpu"
 
44
  matplotlib.use("Agg")
45
 
46
  # ---------------------------------------------------------------------------
 
38
 
39
  def get_device():
40
  """Detect GPU at runtime, not import time."""
41
+ import subprocess
42
+ print(f"[GPU DEBUG] torch.cuda.is_available() = {torch.cuda.is_available()}")
43
+ print(f"[GPU DEBUG] torch.version.cuda = {torch.version.cuda}")
44
+ print(f"[GPU DEBUG] torch.backends.cudnn.enabled = {torch.backends.cudnn.enabled}")
45
+ try:
46
+ print(f"[GPU DEBUG] torch.cuda.device_count() = {torch.cuda.device_count()}")
47
+ except Exception as e:
48
+ print(f"[GPU DEBUG] torch.cuda.device_count() ERROR: {e}")
49
+ try:
50
+ result = subprocess.run(["nvidia-smi"], capture_output=True, text=True, timeout=5)
51
+ print(f"[GPU DEBUG] nvidia-smi output:\n{result.stdout[:500]}")
52
+ if result.stderr:
53
+ print(f"[GPU DEBUG] nvidia-smi stderr: {result.stderr[:200]}")
54
+ except Exception as e:
55
+ print(f"[GPU DEBUG] nvidia-smi ERROR: {e}")
56
+ try:
57
+ import os
58
+ print(f"[GPU DEBUG] CUDA_VISIBLE_DEVICES = {os.environ.get('CUDA_VISIBLE_DEVICES', 'NOT SET')}")
59
+ print(f"[GPU DEBUG] NVIDIA_VISIBLE_DEVICES = {os.environ.get('NVIDIA_VISIBLE_DEVICES', 'NOT SET')}")
60
+ except Exception as e:
61
+ print(f"[GPU DEBUG] env check ERROR: {e}")
62
  if torch.cuda.is_available():
63
+ name = torch.cuda.get_device_name(0)
64
+ print(f"[GPU DEBUG] Using GPU: {name}")
65
  return "cuda"
66
+ print("[GPU DEBUG] Falling back to CPU")
67
  return "cpu"
68
+
69
  matplotlib.use("Agg")
70
 
71
  # ---------------------------------------------------------------------------