42e commited on
Commit
3161c99
·
verified ·
1 Parent(s): 5a983c2

Upload folder using huggingface_hub

Browse files
src/mathcompose/eval/run.py CHANGED
@@ -15,8 +15,12 @@ from __future__ import annotations
15
 
16
  import argparse
17
  import json
 
18
  from pathlib import Path
19
 
 
 
 
20
  RESULTS_DIR = Path("results")
21
 
22
 
 
15
 
16
  import argparse
17
  import json
18
+ import os
19
  from pathlib import Path
20
 
21
+ # reduce fragmentation OOMs (set before torch/CUDA initializes)
22
+ os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
23
+
24
  RESULTS_DIR = Path("results")
25
 
26
 
src/mathcompose/eval/runners.py CHANGED
@@ -167,13 +167,15 @@ def auto_concurrent_seqs() -> int:
167
  if not torch.cuda.is_available():
168
  return 8
169
  vram = torch.cuda.get_device_properties(0).total_memory / 1e9
 
 
170
  if vram >= 70:
171
- return 128
172
- if vram >= 40:
173
  return 64
174
- if vram >= 20:
175
  return 32
176
- return 12
 
 
177
 
178
 
179
  def verify_batch_predictions(runner: HFRunner, items, n: int = 1, batch_size: int = 16,
@@ -189,12 +191,29 @@ def verify_batch_predictions(runner: HFRunner, items, n: int = 1, batch_size: in
189
  def tqdm(x, **k):
190
  return x
191
 
 
 
192
  preds: list[int] = []
193
- chunks = list(range(0, len(items), batch_size))
194
- for i in tqdm(chunks, desc=desc):
195
- chunk = items[i:i + batch_size]
 
196
  msgs = [verifier_messages(p, s) for p, s in chunk]
197
- samples = runner.chat_many(msgs, n=n, temperature=temperature,
198
- max_new_tokens=max_new_tokens)
 
 
 
 
 
 
 
 
 
 
 
199
  preds.extend(majority_index(s) for s in samples)
 
 
 
200
  return preds
 
167
  if not torch.cuda.is_available():
168
  return 8
169
  vram = torch.cuda.get_device_properties(0).total_memory / 1e9
170
+ # conservative starting point (a 7B in bf16 leaves far less room than a 1.5B);
171
+ # verify_batch_predictions auto-halves on OOM as a backstop.
172
  if vram >= 70:
 
 
173
  return 64
174
+ if vram >= 40:
175
  return 32
176
+ if vram >= 20:
177
+ return 16
178
+ return 8
179
 
180
 
181
  def verify_batch_predictions(runner: HFRunner, items, n: int = 1, batch_size: int = 16,
 
191
  def tqdm(x, **k):
192
  return x
193
 
194
+ import torch
195
+
196
  preds: list[int] = []
197
+ i, bs = 0, batch_size
198
+ pbar = tqdm(total=len(items), desc=desc)
199
+ while i < len(items):
200
+ chunk = items[i:i + bs]
201
  msgs = [verifier_messages(p, s) for p, s in chunk]
202
+ try:
203
+ samples = runner.chat_many(msgs, n=n, temperature=temperature,
204
+ max_new_tokens=max_new_tokens)
205
+ except torch.cuda.OutOfMemoryError:
206
+ torch.cuda.empty_cache()
207
+ if bs == 1:
208
+ raise
209
+ bs = max(1, bs // 2)
210
+ try:
211
+ pbar.write(f"[oom] halving batch -> {bs}")
212
+ except Exception:
213
+ pass
214
+ continue
215
  preds.extend(majority_index(s) for s in samples)
216
+ i += len(chunk)
217
+ pbar.update(len(chunk))
218
+ pbar.close()
219
  return preds