[BUG]: `verify --segment` checks a repeated segment again and counts it twice

Aperta Adatta ai principianti
#399 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

Inizia in simple/ovl.py, nella logica di selezione dei segmenti intorno alle righe 667–672, poi segui l’elaborazione dell’argomento verify e la generazione del riepilogo. Aggiungi un rapido test di regressione che esegue il monkeypatch di verify_segment, passi un valore duplicato di --segment e verifichi che il segmento venga verificato una sola volta. Fatto significa che i valori duplicati vengono deduplicati prima del replay, il riepilogo nella console conta i segmenti distinti e local-verifications.jsonl contiene un solo record per quel segmento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
Bug Description

ovl.py verify does not remove duplicate values from --segment. Each repeat is replayed from its checkpoint and counted as a separate segment. The console summary and local-verifications.jsonl both overstate how much was checked.

Code (simple/ovl.py#L667-L672):

segments = range(len(chain) - 1) if a.all else list(a.segment or [])
if a.random:
    pool = [k for k in range(len(chain) - 1) if k not in segments]
    ...
for k in sorted(segments):            # duplicates are kept
    report["checks"].append({"segment": [k, k + 1], "match": verify_segment(a.data, run, chain, k)})
Why it matters
  • The count is wrong. verify --segment 0 0 0 prints verify PASS: 4 checks; 3 of 7 segments, but only one distinct segment was checked. The README asks people to post their result line in Discord ("every independent check counts"), so an overstated count goes into the project's public tally.
  • It wastes GPU time and money. On an RTX 5090, one segment takes about 20 minutes (about US$0.50 at the README's ~US$1.50 per hour). Every repeat costs that again.
  • The JSON record is wrong too. local-verifications.jsonl stores [[0, 1], [0, 1], [0, 1]].

A typo such as SEGMENTS="7 7" (verify_segment.sh passes --segment $PICK), or a script that merges segment lists, is enough to trigger this.

Steps to Reproduce

Commit 913dd5a, CPU only. This trains a tiny run with one update per phase, then replays a real segment. Nothing is mocked. It takes about 10 minutes on a laptop CPU, because each replay of the 23M-parameter model takes about 90 seconds.

import json, os, subprocess, sys, tempfile
from pathlib import Path
import numpy as np

with tempfile.TemporaryDirectory() as tmp:
    data, run = Path(tmp) / "prep", Path(tmp) / "run"
    for phase in ("wikipedia", "conversation"):
        d = data / phase; d.mkdir(parents=True)
        np.full(100, 7, dtype="<u2").tofile(d / "tokens.u16")
        np.ones(100, dtype=np.uint8).tofile(d / "mask.u8")
        (d / "documents.jsonl").write_text(json.dumps({"tokens": 100, "offset": 0, "target_start": 0, "targets": 100}) + "\n")
        (d / "stream.json").write_text(json.dumps({"phase": phase, "targets": 100}))
    env = {**os.environ, "OVL_DEVICE": "cpu", "OVL_TIMESTAMP": "0", "OVL_BOUNDARY_EVERY": "1"}
    ovl = [sys.executable, "simple/ovl.py"]
    subprocess.run(ovl + ["train", "--data", str(data), "--out", str(run)], env=env, check=True, capture_output=True)
    r = subprocess.run(ovl + ["verify", "--run", str(run), "--data", str(data), "--no-anchor",
                              "--segment", "0", "0", "0"], env=env, capture_output=True, text=True)
    print(r.stdout)
    print(json.loads((run / "local-verifications.jsonl").read_text().splitlines()[-1])["checks"])

Actual output:

initialization: MATCH
segment 0->1 (base): MATCH in 88 s
segment 0->1 (base): MATCH in 83 s
segment 0->1 (base): MATCH in 96 s
verify PASS: 4 checks; 3 of 7 segments
[{'initialization': True}, {'match': True, 'segment': [0, 1]}, {'match': True, 'segment': [0, 1]}, {'match': True, 'segment': [0, 1]}]

With --segment 0, the same run prints verify PASS: 2 checks; 1 of 7 segments, which is correct.

Expected Behavior

Each distinct segment is replayed once, and the summary counts distinct segments. --segment 0 0 0 should print 1 of 7 segments.

Proposed Fix

Build the selection as a set:

segments = set(range(len(chain) - 1)) if a.all else set(a.segment or [])
if a.random:
    pool = [k for k in range(len(chain) - 1) if k not in segments]
    segments |= {pool.pop(secrets.randbelow(len(pool))) for _ in range(min(a.random, len(pool)))}
for k in sorted(segments):
    ...

Optionally, print a note such as segment 0 given 3 times; checking it once, so the user can see that the input was changed.

Add a regression test that --segment 0 0 calls verify_segment once and the summary says 1 of N. The test can monkeypatch verify_segment, so it runs in milliseconds.

The fix does not change the bits. Only the segment selection changes.

Logs and Screenshots

No response

Environment Details

No response

Impact

Critical - Application is unusable

Code of Conduct
  • I have joined the Discord server and will post updates there
  • I have searched existing issues to avoid duplicates
Lingua principale
Python
Stelle
27
Fork
72
Merge medio
3g 15h
PR unite (30g)
32

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di AOSSIE-Org/OpenVerifiableLLM

Tutte le issue di AOSSIE-Org/OpenVerifiableLLM

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.