TiGa-RCE commited on
Commit
88534d9
·
verified ·
1 Parent(s): 7973967

Move GTE 1.5B CUDA placement to ZeroGPU startup

Browse files
Files changed (2) hide show
  1. __pycache__/app.cpython-313.pyc +0 -0
  2. app.py +34 -12
__pycache__/app.cpython-313.pyc CHANGED
Binary files a/__pycache__/app.cpython-313.pyc and b/__pycache__/app.cpython-313.pyc differ
 
app.py CHANGED
@@ -33,6 +33,17 @@ model = AutoModel.from_pretrained(
33
  trust_remote_code=True,
34
  ).to("cuda").eval()
35
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  def detailed_instruction(query: str) -> str:
38
  return f"Instruct: {TASK}\nQuery:{query}"
@@ -272,18 +283,27 @@ def run_family_bf16_control(family: str) -> dict:
272
  query_texts = [detailed_instruction(item["query"]) for item in pairs]
273
  document_texts = [item["document"] for item in pairs]
274
 
275
- gc.collect()
276
- torch.cuda.empty_cache()
277
  torch.cuda.reset_peak_memory_stats()
278
  torch.cuda.synchronize()
279
  allocation_before = int(torch.cuda.memory_allocated())
280
- load_started = time.perf_counter()
281
- family_tokenizer = AutoTokenizer.from_pretrained(spec["path"], padding_side="left")
282
- family_model = AutoModel.from_pretrained(
283
- spec["path"], dtype=torch.bfloat16, trust_remote_code=True
284
- ).to("cuda").eval()
285
- torch.cuda.synchronize()
286
- load_seconds = time.perf_counter() - load_started
 
 
 
 
 
 
 
 
 
 
 
287
  allocation_after_load = int(torch.cuda.memory_allocated())
288
 
289
  encode_started = time.perf_counter()
@@ -302,6 +322,7 @@ def run_family_bf16_control(family: str) -> dict:
302
  "model": spec["source"],
303
  "source_revision": spec["revision"],
304
  "load_seconds": load_seconds,
 
305
  "encode_seconds": encode_seconds,
306
  "texts_per_second": len(query_texts + document_texts) / encode_seconds,
307
  "torch_version": torch.__version__,
@@ -332,9 +353,10 @@ def run_family_bf16_control(family: str) -> dict:
332
  )
333
  (output_dir / "cuda-bf16.json").write_text(json.dumps(result, indent=2) + "\n")
334
 
335
- del family_model, family_tokenizer
336
- gc.collect()
337
- torch.cuda.empty_cache()
 
338
  return result
339
 
340
 
 
33
  trust_remote_code=True,
34
  ).to("cuda").eval()
35
 
36
+ # ZeroGPU optimizes CUDA placements made during module startup. The previous
37
+ # larger-family path loaded this model inside the decorated call and exhausted
38
+ # that reservation before producing an artifact.
39
+ GTE_MODEL_PATH = Path("/models/gte-qwen2-1.5b")
40
+ gte_tokenizer = AutoTokenizer.from_pretrained(GTE_MODEL_PATH, padding_side="left")
41
+ gte_model = AutoModel.from_pretrained(
42
+ GTE_MODEL_PATH,
43
+ dtype=torch.bfloat16,
44
+ trust_remote_code=True,
45
+ ).to("cuda").eval()
46
+
47
 
48
  def detailed_instruction(query: str) -> str:
49
  return f"Instruct: {TASK}\nQuery:{query}"
 
283
  query_texts = [detailed_instruction(item["query"]) for item in pairs]
284
  document_texts = [item["document"] for item in pairs]
285
 
 
 
286
  torch.cuda.reset_peak_memory_stats()
287
  torch.cuda.synchronize()
288
  allocation_before = int(torch.cuda.memory_allocated())
289
+ if family == "gte-qwen2-1.5b":
290
+ family_tokenizer = gte_tokenizer
291
+ family_model = gte_model
292
+ load_seconds = 0.0
293
+ loading_strategy = "root-module-cuda-emulation"
294
+ owns_model = False
295
+ else:
296
+ load_started = time.perf_counter()
297
+ family_tokenizer = AutoTokenizer.from_pretrained(
298
+ spec["path"], padding_side="left"
299
+ )
300
+ family_model = AutoModel.from_pretrained(
301
+ spec["path"], dtype=torch.bfloat16, trust_remote_code=True
302
+ ).to("cuda").eval()
303
+ torch.cuda.synchronize()
304
+ load_seconds = time.perf_counter() - load_started
305
+ loading_strategy = "in-call-cuda-placement"
306
+ owns_model = True
307
  allocation_after_load = int(torch.cuda.memory_allocated())
308
 
309
  encode_started = time.perf_counter()
 
322
  "model": spec["source"],
323
  "source_revision": spec["revision"],
324
  "load_seconds": load_seconds,
325
+ "loading_strategy": loading_strategy,
326
  "encode_seconds": encode_seconds,
327
  "texts_per_second": len(query_texts + document_texts) / encode_seconds,
328
  "torch_version": torch.__version__,
 
353
  )
354
  (output_dir / "cuda-bf16.json").write_text(json.dumps(result, indent=2) + "\n")
355
 
356
+ if owns_model:
357
+ del family_model, family_tokenizer
358
+ gc.collect()
359
+ torch.cuda.empty_cache()
360
  return result
361
 
362