HimalayaGPT commited on
Commit
72a4652
·
verified ·
1 Parent(s): c9b6574

Make standalone runner Colab-safe (disable device_map by default)

Browse files
Files changed (1) hide show
  1. run_standalone_inference.py +9 -3
run_standalone_inference.py CHANGED
@@ -51,6 +51,11 @@ def parse_args() -> argparse.Namespace:
51
  p.add_argument("--max-new-tokens", type=int, default=96)
52
  p.add_argument("--seed", type=int, default=42)
53
  p.add_argument("--device", choices=["auto", "cuda", "cpu"], default="auto")
 
 
 
 
 
54
  p.add_argument("--prompts-file", default=None, help="Optional .txt file with one prompt per line")
55
  return p.parse_args()
56
 
@@ -203,9 +208,10 @@ def main() -> None:
203
  local,
204
  trust_remote_code=True,
205
  torch_dtype=torch_dtype,
206
- device_map="auto" if device.type == "cuda" else None,
 
207
  )
208
- if device.type == "cpu":
209
  model = model.to(device)
210
  model.eval()
211
 
@@ -227,7 +233,7 @@ def main() -> None:
227
  max_prompt_tokens = max(1, context_window - args.max_new_tokens)
228
 
229
  print(f"repo={args.repo_id} revision={args.revision} snapshot_sha={sha}")
230
- print(f"device={device} dtype={torch_dtype} prompt_style={prompt_style}")
231
  print(f"context_window={context_window} max_prompt_tokens={max_prompt_tokens}")
232
 
233
  torch.manual_seed(args.seed)
 
51
  p.add_argument("--max-new-tokens", type=int, default=96)
52
  p.add_argument("--seed", type=int, default=42)
53
  p.add_argument("--device", choices=["auto", "cuda", "cpu"], default="auto")
54
+ p.add_argument(
55
+ "--use-device-map",
56
+ action="store_true",
57
+ help="Use transformers/accelerate device_map='auto'. Disabled by default for maximum Colab compatibility.",
58
+ )
59
  p.add_argument("--prompts-file", default=None, help="Optional .txt file with one prompt per line")
60
  return p.parse_args()
61
 
 
208
  local,
209
  trust_remote_code=True,
210
  torch_dtype=torch_dtype,
211
+ device_map="auto" if (device.type == "cuda" and args.use_device_map) else None,
212
+ low_cpu_mem_usage=bool(device.type == "cuda" and args.use_device_map),
213
  )
214
+ if device.type == "cpu" or (device.type == "cuda" and not args.use_device_map):
215
  model = model.to(device)
216
  model.eval()
217
 
 
233
  max_prompt_tokens = max(1, context_window - args.max_new_tokens)
234
 
235
  print(f"repo={args.repo_id} revision={args.revision} snapshot_sha={sha}")
236
+ print(f"device={device} dtype={torch_dtype} prompt_style={prompt_style} use_device_map={args.use_device_map}")
237
  print(f"context_window={context_window} max_prompt_tokens={max_prompt_tokens}")
238
 
239
  torch.manual_seed(args.seed)