Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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")
|