Md-Asif commited on
Commit
7c9b130
·
verified ·
1 Parent(s): 4cf8f2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -15,7 +15,6 @@ If you'd rather run this as two fully separate models, see the
15
  `# ALTERNATE: two full models` comment block near the model loading code.
16
  """
17
 
18
-
19
  import ast
20
  import re
21
  import time
@@ -67,7 +66,12 @@ base_model = AutoModelForCausalLM.from_pretrained(
67
  )
68
 
69
  print("Attaching LoRA adapter (also on CPU)...")
70
- model = PeftModel.from_pretrained(base_model, ADAPTER_ID)
 
 
 
 
 
71
 
72
  print("Moving model to CUDA (ZeroGPU defers this safely until a request comes in)...")
73
  model.to("cuda")
 
15
  `# ALTERNATE: two full models` comment block near the model loading code.
16
  """
17
 
 
18
  import ast
19
  import re
20
  import time
 
66
  )
67
 
68
  print("Attaching LoRA adapter (also on CPU)...")
69
+ # torch_device="cpu" is required here: PEFT's internal infer_device() checks
70
+ # torch.cuda.is_available(), which ZeroGPU's patching always reports as True
71
+ # (even outside a GPU-attached window). Without this, PEFT tries to load the
72
+ # adapter's safetensors directly onto a CUDA device that isn't physically
73
+ # attached yet at import time, which crashes with "No CUDA GPUs are available".
74
+ model = PeftModel.from_pretrained(base_model, ADAPTER_ID, torch_device="cpu")
75
 
76
  print("Moving model to CUDA (ZeroGPU defers this safely until a request comes in)...")
77
  model.to("cuda")