[BUG]: simple/ovl.py bench crashes with TypeError or ZeroDivisionError when stream yields <= 50 updates

Open Beginner friendly
#223 2 comments 0 reactions 2 assignees View on GitHub

Maintainers usually reply within 1 day

@AdityasagarR123 is already working on this.

Since Oct 26, 2026.

  • #227 by @AdityasagarR123 — open
  • #350 by @AdityasagarR123 — open

Assessment

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

Research direction

Read simple/ovl.py and inspect cmd_bench, especially the warm-up loop and throughput calculation. Run the provided command with a data directory that yields fewer than 51 Wikipedia batches to reproduce the failure. Done when empty and short streams exit with a clear message or are handled safely, while a normal benchmark still reports valid throughput.

Written by the indexing model from the issue text.

Description

Bug Description

In simple/ovl.py, the bench command measures throughput (ms_per_update) by iterating over the Wikipedia data stream. It assumes that more than 50 updates will always be executed and hardcodes a 50-step warm-up before initializing t0 = time.time():

def cmd_bench(a):
    model, opt = fresh()
    ctl, n, t0 = initial_control(), 0, None
    for b, _ in prefetch(a.data, "wikipedia", [0, 0]):
        loss, ctl["cursor"], _ = step(model, opt, b, ctl)
        n += 1
        if n == 50:
            if DEV == "cuda": torch.cuda.synchronize()
            t0 = time.time()
        if t0 and time.time() - t0 >= a.seconds:
            break
    if DEV == "cuda": torch.cuda.synchronize()
    ms = 1000 * (time.time() - t0) / (n - 50)
    total = RECIPE["schedule"]["wikipedia_updates"]
    print(json.dumps({"ms_per_update": round(ms, 2), "updates_timed": n - 50, "loss": loss.item(),
                      ...}))

This leads to three failure modes when running benchmarks on small/smoke datasets, interrupted runs, or streams with fewer than 51 batches:

  1. TypeError (t0 is None): If the stream exhausts before reaching update 50 (i.e. n < 50), n == 50 never triggers and t0 remains None. Line 571 evaluates time.time() - t0, raising:
    TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'
    
  2. ZeroDivisionError (n == 50): If the stream yields exactly 50 batches, t0 is initialized on the final iteration and the loop terminates. Line 571 computes (n - 50) which is 0, raising:
    ZeroDivisionError: division by zero
    
  3. UnboundLocalError / AttributeError (n == 0): If the prefetch generator yields 0 batches (e.g. empty or exhausted stream), loss is never assigned in the loop, causing an error at loss.item().
Steps to Reproduce

Run simple/ovl.py bench on any data directory that contains fewer than 51 batches in the Wikipedia stream (e.g. testing with a small sample stream or quick smoke tests):

python simple/ovl.py bench --data tests/fixtures/simple-run --seconds 60
Logs and Screenshots
Traceback (most recent call last):
  File "simple/ovl.py", line 622, in <module>
    main()
  File "simple/ovl.py", line 618, in main
    {"train": cmd_train, "fork": cmd_fork, "verify": cmd_verify, "bench": cmd_bench, "chat": cmd_chat}[a.cmd](a)
  File "simple/ovl.py", line 571, in cmd_bench
    ms = 1000 * (time.time() - t0) / (n - 50)
                 ~~~~~~~~~~~^~~~
TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'
Environment Details
  • OS: Windows / Linux / macOS
  • Python: 3.10+
  • Branch: main
Impact
  • Medium: Prevents benchmark runs from functioning on small, smoke test, or custom datasets. Instead of exiting gracefully with a clear message or adapting the warm-up window, the script crashes with unhandled tracebacks.
Suggested Solution

Add validation before computing ms to ensure sufficient updates were timed, or provide an adaptive warm-up. For example:

--- a/simple/ovl.py
+++ b/simple/ovl.py
@@ -559,8 +559,9 @@ def cmd_verify(a):
 def cmd_bench(a):
     model, opt = fresh()
-    ctl, n, t0 = initial_control(), 0, None
+    ctl, n, t0, loss = initial_control(), 0, None, None
+    warmup_steps = 50
     for b, _ in prefetch(a.data, "wikipedia", [0, 0]):
         loss, ctl["cursor"], _ = step(model, opt, b, ctl)
         n += 1
-        if n == 50:
+        if n == warmup_steps:
             if DEV == "cuda": torch.cuda.synchronize()
             t0 = time.time()
         if t0 and time.time() - t0 >= a.seconds:
             break
+    if loss is None or n == 0:
+        sys.exit("bench error: data stream yielded 0 batches")
+    if t0 is None or n <= warmup_steps:
+        sys.exit(f"bench error: completed {n} updates; at least {warmup_steps + 1} updates are required to measure throughput after warm-up")
     if DEV == "cuda": torch.cuda.synchronize()
-    ms = 1000 * (time.time() - t0) / (n - 50)
+    timed_updates = n - warmup_steps
+    ms = 1000 * (time.time() - t0) / timed_updates
     total = RECIPE["schedule"]["wikipedia_updates"]
-    print(json.dumps({"ms_per_update": round(ms, 2), "updates_timed": n - 50, "loss": loss.item(),
+    print(json.dumps({"ms_per_update": round(ms, 2), "updates_timed": timed_updates, "loss": loss.item(),
                       **environment(), "projected_train_hours": round(total * ms / 3.6e6, 2),
                       "segments": math.ceil(total / RECIPE["boundary_every"]),
                       "minutes_per_segment": round(RECIPE["boundary_every"] * ms / 6e4, 1)}))

Additionally, an optional --warmup argument could be added to bench CLI arguments to allow developers to run benchmark smoke tests with smaller values (e.g., --warmup 2).

Code of Conduct
  • I have joined the Discord server and will post updates there
  • I have searched existing issues to avoid duplicates
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.