Spaces:
Running on Zero
Running on Zero
Fix: use PEFT torch_device=cpu (not device_map, which was silently ignored) to force CPU-side adapter load
Browse files
app.py
CHANGED
|
@@ -49,16 +49,21 @@ SYSTEM_PROMPT = SYSTEM_PROMPT_TEMPLATE.format(
|
|
| 49 |
|
| 50 |
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
| 51 |
base_model = AutoModelForCausalLM.from_pretrained(BASE_MODEL, torch_dtype="auto")
|
| 52 |
-
#
|
| 53 |
-
#
|
| 54 |
-
#
|
| 55 |
-
#
|
| 56 |
-
#
|
| 57 |
-
#
|
| 58 |
-
#
|
| 59 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
model = PeftModel.from_pretrained(
|
| 61 |
-
base_model, ADAPTER, subfolder=ADAPTER_SUBFOLDER,
|
| 62 |
)
|
| 63 |
model.to("cuda")
|
| 64 |
model.eval()
|
|
|
|
| 49 |
|
| 50 |
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
| 51 |
base_model = AutoModelForCausalLM.from_pretrained(BASE_MODEL, torch_dtype="auto")
|
| 52 |
+
# torch_device="cpu" is required here: PeftModel.from_pretrained forwards
|
| 53 |
+
# unrecognized kwargs to load_adapter(), whose `torch_device` parameter
|
| 54 |
+
# controls what device load_peft_weights()/safetensors loads the adapter
|
| 55 |
+
# weights onto. Left unset, it calls infer_device(), which sees
|
| 56 |
+
# torch.cuda.is_available() == True (ZeroGPU's emulation layer reports
|
| 57 |
+
# this as True even at module-load time, before a real GPU is allocated)
|
| 58 |
+
# and picks "cuda" -- a direct-to-device safetensors load that the
|
| 59 |
+
# emulation layer does not cover, causing "RuntimeError: No CUDA GPUs are
|
| 60 |
+
# available". Forcing torch_device="cpu" here and moving the whole
|
| 61 |
+
# composed model to CUDA afterward avoids that code path entirely. Note
|
| 62 |
+
# this is NOT the same kwarg as transformers' `device_map` (which is
|
| 63 |
+
# unrelated to this PEFT-internal loading path and is silently ignored if
|
| 64 |
+
# passed here instead).
|
| 65 |
model = PeftModel.from_pretrained(
|
| 66 |
+
base_model, ADAPTER, subfolder=ADAPTER_SUBFOLDER, torch_device="cpu"
|
| 67 |
)
|
| 68 |
model.to("cuda")
|
| 69 |
model.eval()
|