Skip to content

Moonshot: commit the sweep levers and the P13 state-rank study - #128

Merged
SamMausberg merged 5 commits into
mainfrom
moonshot/sweep-levers
Oct 1, 2026
Merged

SamMausberg merged 5 commits into
mainfrom
moonshot/sweep-levers

Conversation

@SamMausberg

Copy link
Copy Markdown
Owner

Moves the moonshot work that existed only as uncommitted changes in the moonshot worktree onto main. The queued and planned jobs that use it then run committed code. Two of those jobs were already queued against that worktree: the P13 state-rank study (shared) and the quality probe for the INT4/DFlash arms (shared). Their outputs could not have been cited otherwise.

What is added

  • experiments/moonshot/levers.py, the levers used by the planned X3, X4c and X4d sweeps:

    • tuned_noradix: radix off with 128 state slots, matching bench's tuned arms.
    • gdn_triton: Triton GDN decode and verify, pinned so arms on different engines match.
    • gdn_verify_triton: Triton GDN verify only. Its exactness class is pending bench's equality classification.
    • prefill_delay4 and prefill_delay8: SGLang's prefill delayer, batching arrivals (scheduling only).
    • fold: GDN fold-every-commit buffered verify. It needs the drafter workstream's engine patch, which is not on main. The lever's comment says so and that, on an engine without the patch, the flag alone gives stock ReplaySSM-spec.

    No existing lever changes.

  • experiments/moonshot/summarise.py: the sweeps table gains server_full_batch_tps, the token-weighted server decode rate over full-batch windows (bench's logged_gen_tps_full_batch). It sits beside the median-window rate already reported, which drops prefill-heavy windows and so flatters speculation.

  • experiments/moonshot/gdn_state_rank_study.py: proposal P13's offline, training-free test. Each GDN head's state is reduced to rank r in the key dimension, with energy, query and product bases. It runs on the HF model with teacher forcing, measuring KL, top-1 agreement and a delayed-retrieval probe. It has not run yet. The coordinator's rule for P13 is one run, closed if it misses the quality budget.

  • experiments/moonshot/README.md: a row for gdn_state_rank_study.py in the script index.

Left out on purpose: the README's exactness-class updates. They cite bench's evidence/bench/equality/classes.json, which is not on main yet, and will follow once bench's equality PR merges. The worktree's older gdn_fast_verify_check.py is also left out, since main's version is newer.

Validation

  • Pre-commit hooks pass on the changed files (ruff, mypy over the tree, codespell).
  • tests/test_moonshot_levers.py: 2 passed, 3 skipped (engine tests without SGLang).
  • Not run: none of the new levers or the P13 script has run from this commit yet. The queued P13 job (shared) runs the script from this commit, since the worktree it uses is now at this branch's head.

These lived only as uncommitted changes in the moonshot worktree, which
the queued P13 job and the planned X3/X4 sweeps run from, so their
outputs could not have been cited.

- levers.py: tuned_noradix, gdn_triton, gdn_verify_triton,
  prefill_delay4/8 and fold (the last needs the drafter's engine patch,
  not on main; its comment says so).
- summarise.py: the sweeps table adds server_full_batch_tps, the
  token-weighted full-batch decode rate, beside the median-window rate.
- gdn_state_rank_study.py: P13's offline, training-free test of a rank-r
  GDN state in the key dimension; not run yet.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 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-10-01T15:15:00.099230Z 154e94f Manual request
ℹ️ 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: d4ce798806

ℹ️ 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 on lines +176 to +177
parser.add_argument('--ranks', type=int, nargs='+', default=[32, 64, 96, 128])
parser.add_argument('--kinds', nargs='+', default=['energy', 'query', 'product'])

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 Reject invalid rank and basis sweep values

When a custom sweep contains a typo such as --kinds qurey, bases() silently executes the product branch but records the result as qurey; likewise, ranks outside 1..128 produce mislabeled data (r=0 selects all 128 vectors while reporting a zero state fraction, and r>128 still selects only 128 vectors). Constrain --kinds with argparse choices and reject ranks outside the valid interval before running so malformed experiment commands cannot silently corrupt the study output.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 3f630a3. --kinds now uses argparse choices (energy, query, product), --ranks accepts only integers in 1..128, and bases() raises on an unknown kind or an out-of-range rank instead of falling through to the product basis. Checked: --kinds qurey, --ranks 0 and --ranks 129 each exit 2 with an argparse error before the model loads. The defaults, which the queued P13 run uses, are unchanged.

A typo such as --kinds qurey silently ran the product basis under the
typo's label, and ranks outside 1..128 produced mislabelled rows (r = 0
selected all 128 vectors). --kinds now has argparse choices, --ranks
accepts only 1..128, and bases() raises on an unknown kind or rank
(Codex review of #128). The defaults the queued P13 run uses are
unchanged.
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@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: 3f630a3ca2

ℹ️ 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 on lines +186 to +188
parser.add_argument('--calib-count', type=int, default=24)
parser.add_argument('--eval-count', type=int, default=8)
parser.add_argument('--probes', type=int, default=24)

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 Require positive sample counts

When any of --calib-count, --eval-count, or --probes is zero, the expensive GPU run eventually fails through division by zero or empty statistics; negative calibration/evaluation counts are worse because Python slicing accepts them, so the study processes nearly the entire dataset while recording a negative requested count in the result metadata. Use a positive-integer argparse type for all three options so malformed experiment commands fail before loading the model.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in a1c49a9. --calib-count, --eval-count and --probes (the script's only count arguments) accept only integers of at least 1, checked at argument parsing; --calib-count 0, --eval-count -1 and --probes 0 each exit 2 before the model loads. A count larger than its file now stops the run instead of recording fewer texts than requested. The defaults (24, 8, 24) fit the default files (48 and 512 texts).

--calib-count, --eval-count or --probes of zero failed late with a
division by zero, and negative counts sliced nearly the whole file while
recording the negative number. All three now accept only integers of at
least 1, and a count larger than its file stops the run instead of
recording fewer texts than requested (Codex review of #128). The
defaults (24, 8, 24) fit the default files.
@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: REQUEST CHANGES (one item: the new Codex P2)

Review of the exact head 3f630a3: d4ce798 plus the argument checks for Codex r4156847576.

Verified

  • levers.py. The new levers are flag and environment overlays only, and no existing lever changes. fold says plainly that it needs the drafter's unmerged engine patch, and that the flag alone gives stock ReplaySSM-spec. The gdn_verify_triton note's figures (4.78 → 4.55, 15.62 → 7.58 and 44.82 → 19.18 ms at B = 16, 64, 256) match evidence/repair/README.md lines 121-123.
  • summarise.py. server_full_batch_tps reads bench's logged_gen_tps_full_batch beside the existing p50 column.
  • gdn_state_rank_study.py.
    • The reduced recurrence keeps the model's query scale: pre-multiplying q by sqrt(r)/sqrt(128) cancels torch_chunk_gated_delta_rule's 1/sqrt(r).
    • The reference is the same function with no basis.
    • KL is KL(full || reduced) over the second half, and top-1 agreement is over the same positions.
    • The three bases match the docstring.
  • Codex r4156847576 is fixed in 3f630a3 and has a reply: argparse choices, ranks limited to 1..128, and bases() raises.
  • Checks. Pre-commit passes on the changed files. The commits are by Samuel Mausberg. The hostname check is clean.

Blocking

  1. Codex P2 r4156948344 on 3f630a3 is valid and unanswered. A zero --calib-count, --eval-count or --probes fails by division by zero only after the model has loaded and the GPU work has run. Reject non-positive counts at argument parsing, as you did for the ranks, and reply on the thread.

Merge-order note (non-blocking for this PR)

Suggestion. The prefill_delay comment says "the served cycle is ~35 ms: each arrival's prefill pass interrupts decode". The hostgap evidence (#120) derives about 32 ms and labels the prefill explanation a hypothesis. Matching that wording keeps the code from stating it as fact.

@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

SamMausberg added a commit that referenced this pull request Oct 1, 2026
#128 adds a column to the sweeps table, so host_levers.csv would no
longer regenerate byte for byte with a later summarise.py; the README now
names e47f0e5, where both CSVs were checked (reviewer's note).
The ~35 ms served cycle at c = 128 was an estimate, and that arrivals'
prefill passes cause the gap is untested (reviewer's note).
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@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: 781ec0dab0

ℹ️ 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".


@torch.no_grad()
def kl_and_agreement(model: Any, ids: torch.Tensor, ref_logp: torch.Tensor) -> tuple[float, float]:
logits = model(ids.unsqueeze(0)).logits[0].float()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Disable the model cache for projected-state forwards

With the pinned Qwen model's default use_cache=True, these teacher-forced calls still create the model's fixed-width GDN recurrent cache. Once state['basis'] selects any rank below 128, the replacement rule returns an r-wide final state that cannot be stored in that 128-wide cache, so the study fails on its first reduced-rank evaluation instead of producing results. Pass use_cache=False on every calibration, reference, evaluation, and retrieval model call.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 154e94f: every calibration, reference, evaluation and retrieval call now passes use_cache=False. One correction on the failure mode: at the pinned transformers (the SGLang venv's), a fresh DynamicCache stores the r-wide final state without error (a tiny random Qwen3.5 model at r = 32 returns a cache state of shape [1, 2, 32, 16]), so the study would not have failed; it would only have computed and stored a state it never reuses. The new tests/test_moonshot_gdn_state_rank.py runs the patched rule on that tiny model on CPU: a full-rank rotation reproduces the unprojected outputs within 1e-4, and rank 32 runs without the cache (it skips without torch and transformers).

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE (provisional, on 781ec0d: Codex is still running on this head. I will confirm or withdraw once it finishes.)

Re-review of a1c49a9 and 781ec0d on top of 3f630a3.

  • The blocking item is fixed, and Codex r4156948344 is answered. --calib-count, --eval-count and --probes use a positive argparse type, so 0 and negative counts exit 2 before the model loads. A count larger than its file now stops the run instead of quietly using fewer texts.
  • The suggestion is taken. The prefill_delay comment calls the ~35 ms served cycle an estimate and its mechanism an untested hypothesis.
  • The merge-order note is resolved on Moonshot P4b: explain the 127-request plateau; amend to a running limit of 129 #123's side. Its README now names summarise.py at e47f0e5.
  • Checks. Pre-commit passes on the two changed files.

Everything else stands from my review of 3f630a3.

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: REQUEST CHANGES (withdraws my provisional approval of 781ec0d)

Codex's P1 on 781ec0d is valid and blocking. The projected-state forwards run with use_cache=True, which builds the model's fixed 128-wide GDN cache, so any rank below 128 fails the P13 study. Disable the cache for those forwards (or size it to r), add a check that rank < 128 runs, and reply on the thread. I will re-review the new head.

…ed rule

The study's teacher-forced calls left use_cache at its default, so HF
built a cache and had the projected rule return each layer's final state.
At the pinned transformers a fresh DynamicCache stores the r-wide state
without error (checked on a tiny model), but the cache is never reused,
so every call now passes use_cache=False (Codex review of #128).

tests/test_moonshot_gdn_state_rank.py runs the patched rule on a tiny
random Qwen3.5 model on CPU: a full-rank rotation reproduces the stock
outputs within 1e-4, and rank 32 runs without the cache. It skips
without torch and transformers.
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE (provisional, on 154e94f: Codex is still running on this head. I will confirm or withdraw once it finishes.)

154e94f addresses Codex P1 r4157009510, and the thread has a reply:

  • Every calibration, reference, evaluation and retrieval call passes use_cache=False, so no fixed-width GDN cache is built for the projected-state forwards.
  • The new tests/test_moonshot_gdn_state_rank.py (tiny random Qwen3.5, CPU) checks two things: a full-rank orthogonal basis reproduces the unprojected logits within 1e-4, and a rank-32 basis runs and changes them.

I ran the test in the SGLang venv on one core with CUDA hidden (2 passed). Pre-commit passes on both files.

Everything else stands from my reviews of 3f630a3 and 781ec0d.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 154e94faae

ℹ️ 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".

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