[BUG]: bench_sizes.py leaks prefetch threads on early break and crashes on short streams or CPU

Open
#379 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@panshularora is already working on this.

Since Nov 25, 2026.

  • #382 by @panshularora — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python, pytorch
Domain
performance

Research direction

Start in simple/bench_sizes.py, lines 34-51, where the prefetch loop breaks early and calls torch.cuda functions. Compare with how ovl.py closes its prefetch iterator after #308. Done means the iterator is closed on break, short streams fail with a clear message, and CUDA calls are guarded by ovl.DEV. Pull request #382 is already open against this issue, so check it before starting.

Written by the indexing model from the issue text.

Description

Summary

simple/bench_sizes.py has two bugs when iterating over ovl.prefetch(...) across the 5 model sizes in SIZES:

  1. Leaked prefetch producer threads on early break: for b, _ in ovl.prefetch(a.data, "wikipedia", [0, 0]): breaks out of the loop after a.seconds without closing the prefetch iterator (unlike ovl.py, which was fixed in #308). Because bench_sizes.py loops over 5 progressively larger models in one process, each timed break leaves a live producer thread blocked in q.put() holding queued batch tensors.
  2. Crash on short streams (<= 30 updates): If ovl.prefetch(...) yields 30 or fewer batches, t0 remains None (or n - 30 == 0), so ms = 1000 * (time.time() - t0) / (n - 30) crashes with TypeError: unsupported operand type(s) for -: 'float' and 'NoneType' or ZeroDivisionError.
  3. Unconditional CUDA calls: torch.cuda.synchronize(), torch.cuda.max_memory_allocated(), torch.cuda.empty_cache(), and torch.cuda.reset_peak_memory_stats() are called without checking ovl.DEV == "cuda".

Source

  • simple/bench_sizes.py (lines 34–51)

Expected Behavior

  • Wrap the ovl.prefetch(...) iterator in contextlib.closing(...) so the producer thread is cancelled and joined when the loop breaks or exits.
  • Fail cleanly with a clear error message if fewer than 31 updates are available in the stream.
  • Guard torch.cuda.* calls with ovl.DEV == "cuda".
Dominant language
Python
Stars
27
Forks
72
Avg merge
2d 19h
Merged PRs (30d)
45

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AOSSIE-Org/OpenVerifiableLLM

All issues in AOSSIE-Org/OpenVerifiableLLM

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.