adelelsayed1991 commited on
Commit
a7cc8ca
·
verified ·
1 Parent(s): 64c1aa0

Fix: force adapter safetensors load onto CPU (device_map=cpu) to avoid ZeroGPU emulation gap

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -49,7 +49,17 @@ 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
- model = PeftModel.from_pretrained(base_model, ADAPTER, subfolder=ADAPTER_SUBFOLDER)
 
 
 
 
 
 
 
 
 
 
53
  model.to("cuda")
54
  model.eval()
55
 
 
49
 
50
  tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
51
  base_model = AutoModelForCausalLM.from_pretrained(BASE_MODEL, torch_dtype="auto")
52
+ # device_map="cpu" is required here: PeftModel.from_pretrained's internal
53
+ # safetensors load otherwise infers a CUDA target device from
54
+ # torch.cuda.is_available() (which ZeroGPU's emulation layer reports as
55
+ # True even at module-load time, before a real GPU is allocated), and that
56
+ # specific direct-to-device safetensors load path is not covered by the
57
+ # emulation, causing "RuntimeError: No CUDA GPUs are available". Loading
58
+ # on CPU here and moving the whole composed model to CUDA afterward avoids
59
+ # that code path entirely.
60
+ model = PeftModel.from_pretrained(
61
+ base_model, ADAPTER, subfolder=ADAPTER_SUBFOLDER, device_map="cpu"
62
+ )
63
  model.to("cuda")
64
  model.eval()
65