Skip to content

Drafter follow-up: Codex fixes on #22, engine patch layout, selector control - #40

Merged
SamMausberg merged 8 commits into
mainfrom
drafter/followup-codex
Sep 30, 2026
Merged

SamMausberg merged 8 commits into
mainfrom
drafter/followup-codex

Conversation

@SamMausberg

Copy link
Copy Markdown
Owner

Follow-up to #22: the two Codex comments on #22, the engine-patch layout from BRIEF.md, a VAT-style control for the selector arm, and CPU dry-run support for the trainers. No GPU results in this PR.

Codex comments on #22

P1, build_train_prompts.py --exclude with nargs='+'. Correct: with the flag repeated, argparse kept only the last group. It is now action='extend', and tests/test_drafter_tools.py passes --exclude twice and checks that all files accumulate. The data actually used, prompts-v2, was built with a single --exclude listing all 11 files, and its committed manifest (evidence/drafter/data/prompts-v2.manifest.json) checks every one of them with zero overlap. Rebuilding with the flag repeated three times gives a byte-identical prompt file (SHA-256 97123d99...9b1) and the same zero counts, so no training data was affected. No generation or training has run yet.

compare_outputs.py treated a prefix as equal. Correct: two greedy outputs of different lengths now diverge where the shorter one ends (first_divergence), with the missing side's token recorded as null. No equality result had been computed with the old rule, so nothing needs recomputing; the first equality run is still queued.

Other changes

  • engine/sglang/patches/drafter/0001-dflash-cycle-trace.patch replaces drafter-0001-... at the top level, with a drafter section in engine/sglang/README.md (the separate README is gone).
  • train_selector.py --objective vat: VAT's weighting (full weight up to the current greedy walk's first rejection, then the decay restarted), the matched control for the P6 selector arm.
  • --device and --attention-backend on both trainers, so they can run on CPU with SpecForge's dense SDPA masks. A CPU dry run with tiny random models exercised training, evaluation, resume and export for both trainers and all four selector objectives.
  • run_gen_all.sh can keep its first segment's queue place when restarted (FIRST_ARRIVAL).

Tests: python -m pytest tests/test_drafter_tools.py (4 passed); pre-commit clean.

engine/sglang/patches/drafter/0001-dflash-cycle-trace.patch with a drafter
section in the shared engine README, as in BRIEF.md. The data-generation
driver can keep its first segment's queue place when restarted.
--device and --attention-backend on train_dflash.py and train_selector.py
(block_hidden picks SpecForge's dense SDPA mask when the drafter is not on
flex attention). A CPU dry run with tiny random models exercised training,
evaluation, resume and export for both trainers and all four selector
objectives.
build_train_prompts.py: --exclude uses action='extend', so repeating the flag
accumulates files instead of keeping only the last group. prompts-v2 was built
with a single --exclude listing all 11 files (the committed manifest checks all
of them, zero overlap); rebuilding with the flag repeated gives a byte-identical
prompt file. compare_outputs.py: outputs of different lengths now diverge
where the shorter one ends, even when one is a prefix of the other (no equality
result had been computed with the old rule). Tests in tests/test_drafter_tools.py.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-30T21:19:19.774295Z 0ae85ac PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0ae85ac2e8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread experiments/drafter/train_dflash.py Outdated
'rng': {
'torch': torch.get_rng_state(),
'cuda': torch.cuda.get_rng_state(),
'cuda': torch.cuda.get_rng_state() if torch.cuda.is_available() else None,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid initializing CUDA during CPU-only runs

When --device cpu is used on this CUDA-equipped host, torch.cuda.is_available() remains true, so saving a segment calls torch.cuda.get_rng_state(), which eagerly initializes CUDA. A nominal CPU dry run therefore unexpectedly touches the GPU outside the required GPU-lock workflow and may contend with active jobs; save CUDA state only when trainer.device.type == 'cuda'.

AGENTS.md reference: AGENTS.md:L7-L10

Useful? React with 👍 / 👎.

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: REQUEST CHANGES

Reviewed head 0ae85ac (6 behind main, no conflicts in the files it touches). Both Codex fixes on #22 are correct, and the prompts-v2 claim reproduces. One blocking item remains: Codex's P2 on this PR, which I agree with.

Blocking

B1. A CPU dry run of train_dflash.py initializes CUDA outside the GPU lock (experiments/drafter/train_dflash.py:424, Codex P2).

  • What happens. save_state stores torch.cuda.get_rng_state() if torch.cuda.is_available() else None. On this GH200 is_available() is true even with --device cpu, so every checkpoint of a "CPU" run creates a CUDA context on the GPU without holding scripts/gpu_lock.sh.
  • Consequence. The context costs memory and a context switch on a GPU that another workstream may hold. AGENTS.md and SETUP.md reserve GPU access for locked jobs.
  • Fix. Save the CUDA RNG state only when trainer.device.type == 'cuda', matching the guards already added in load_state and evaluate. No other CUDA call is reachable from the CPU paths of the two trainers.

Checked and correct

  • --exclude with action='extend'. Repeated flags accumulate, and the new test covers it. Argparse copies the default list before extending, so default=[] is not mutated.
  • The prompts-v2 claim. I rebuilt prompts-v2 with this branch's builder, passing --exclude three times over the 11 files, with HF_HUB_OFFLINE=1.
    • The prompt file is byte-identical: 18,000 rows, sha256 97123d99679b50ff0c466afe4003843bbb6afacee4bb8744e35e7e2b9047b9a1, the same as the committed manifest and ~/vp-data/drafter/data/prompts-v2.jsonl.
    • All 11 disjointness entries report hash_matches = id_matches = 0, with the same file hashes.
    • The only manifest difference is that my run recorded the ~/vp-data paths expanded.
  • compare_outputs.py.
    • A strict prefix now diverges at the shorter output's end, with the missing side's token recorded as null.
    • An equal pair adds len(a) to compared.
    • Both behaviours are tested end to end through main().
  • The VAT control. It matches VAT's Eq. 6 (arXiv 2608.30135v1): ŵ_k = 1 for k < k*, and w_{k-k*+1} for k >= k*, with the DFlash base schedule w_k = exp(-(k-1)/γ).
    • The 0-based first_miss, the count of leading hits, equals k*-1.
    • The first-rejection slot gets weight 1, as the paper states.
    • k* = K+1 when every slot hits gives all ones.
    • Under teacher forcing, the first slot where the selector's argmax is not the target equals the greedy walk's first rejection.
    • An uncovered slot counts as a rejection.
    • VAT's verification head is not included; the docstring and PR say "VAT weights", which is accurate.
  • Engine patch. It is a pure rename (100%) into engine/sglang/patches/drafter/. The README section keeps the old content, and experiments/drafter/README.md points at the new path.
  • CPU support in the trainers.
    • --device and --attention-backend are threaded through.
    • fused AdamW is used only on CUDA.
    • Autocast follows the device type.
    • rho_pairs.py chooses the SDPA mask builder unless the draft uses flex attention.
  • Tests and hooks. tests/test_drafter_tools.py: 4 passed. Pre-commit (ruff, mypy, codespell, shellcheck) passes on every changed file.
  • Attribution. There are no AI co-author lines.

Suggestions (not blocking)

  • rho_pairs.py. It still hard-codes torch.device('cuda') at line 137. That is fine for a GPU-only tool, but a --device flag would match the trainers.
  • Engine README. The drafter section names the branch engine/drafter, which exists only in the local ~/sglang clone, as for the other workstreams. Saying "(local branch in ~/sglang)" would stop readers looking for it on origin.

…moke job

A --device cpu dry run no longer creates a CUDA context when it checkpoints
(Codex P2 on #40). The rho auxiliary-loss probe is dropped (geometry's engine
capture already measures rho for the public drafter), so the smoke job no
longer dumps teacher-forced rho pairs.
@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE

This re-review covers head aaef760. B1 and Codex's P2 are fixed: save_state reads the CUDA RNG state only when trainer.device.type == 'cuda', the same guard load_state and evaluate use, so a --device cpu run no longer creates a CUDA context outside the GPU lock.

The same commit removes the rho-pairs step from run_train_smoke.sh, since that auxiliary-loss probe was dropped. tests/test_drafter_tools.py passes (4 tests) and pre-commit passes on the two changed files. Everything verified in my first review still holds: prompts-v2 rebuilds byte-identically with --exclude repeated, the 11 overlap counts are zero, the prefix-divergence rule is correct and the VAT weights match Eq. 6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant