Skip to content

sampler: measure relative-weight cutoffs and record the negative CPU result - #65

Merged
midagedev merged 1 commit into
midagedev:mainfrom
Burntgogi:contribution/sampler-threshold-20261012
Oct 12, 2026
Merged

midagedev merged 1 commit into
midagedev:mainfrom
Burntgogi:contribution/sampler-threshold-20261012

Conversation

@Burntgogi

Copy link
Copy Markdown
Contributor

What and why

Add a relative-weight cutoff arm to sample_bench, comparing its candidates and same-seed tokens with Sampler::sample outside each timer. The CPU experiment does not meet the 300 us saving criterion: all 16 ordinary cells match candidates and tokens, but paired median sampling time is 414.1–1899.7 us slower. Explicit top-k ties, top-p ties and rounded min-p boundaries also fail semantic equivalence, so this implementation stays out of the engine.

Closes #34 as a recorded negative experiment, subject to maintainer review.

The cutoff preserves Bloomery's pre-temperature filtering and pre-min-p top-p normalizer. Byte-radix count/mass boundaries feed a single scalar floor. The existing benchmark chain owns the CDF draw, avoiding a second full filtering/sorting pass. --check-only exposes semantic boundaries; --threshold-only measures the new pair; the original invocation retains its existing tables and adds the new comparison.

Full implementation details, all 16 rows, conditions and limitations are in docs/contrib/sampler-threshold.md.

Code shape

  • No second copy. The experiment mirrors the private production RNG in its benchmark module to compare seeded output without opening a production API solely for this experiment. It reuses the benchmark's input seeder and CDF draw, and every timed call checks against the public production sampler.
  • Model code holds only architecture facts. No model-specific code or engine behavior changed.
  • Dead code is gone. The experimental arm and both CLI modes are exercised.
  • No silent failure. Mismatches are printed, counted and marked INVALID; there is no production fallback hiding them.
  • Comments state what is true now. Measurement history is in the report, not source comments.
  • No relaxed gate. Existing sampling contracts and thresholds are unchanged.
  • cargo fmt and cargo clippy are clean on the touched sampler targets.

Duplication: private Xoshiro draw sequence mirrored in the isolated benchmark, as explained above.

What I ran

  • cargo test -p bloomery-sampler: all 11 sampler tests pass.
  • cargo test -p bloomery-sampler --example sample_bench: 3 tests pass, including singleton/RNG scheduling and the scalar tie counterexample.
  • cargo clippy -p bloomery-sampler --all-targets -- -D warnings: passes.
  • Scoped contributor static units: DONE tier=t0 total=9 red=0 wall=16s (fmt, arch, comments, levers, loads, ptx-names, rustflags, unsafe, waits).
  • Release benchmark, after builds/fuzzing completed:
BLOOMERY_LOCK_DIR=<local lock directory> \
  bash tools/ref/lease-hold.sh --card docs/cards/contributor-sampler-threshold.card -- \
  timeout 600 taskset -c 0 target/release/examples/sample_bench --threshold-only

The lease runner returns 0 after 32 seconds. Each cell rotates 4 synthetic rows, warms 100 pairs, and records 1000 pairs with alternating arm order. The 16 cells use V=151936/154880, peaked/flat rows and defaults/top-k/top-p+min-p/min-p filters. All report candidate_bad=0 token_bad=0 BELOW_300US. The three explicit boundary counterexamples print false false and remain disqualifying despite the ordinary rows matching.

No engine port is proposed. This result prices this radix implementation on this CPU and does not establish a GPU or end-to-end decode result. Full T0/T1/workstation gate validation remains with the maintainer.

Hardware

Linux 7.0.0-38-generic x86_64, Intel Core i5-12600K, approximately 64 GB RAM, logical CPU 0; nightly-2026-08-28 with RUSTFLAGS=-C target-cpu=native. The base is b8d1ff06e29819c857948ecd68a450b5226d80fe. Both arms share one release binary and local CPU lease. Ordinary serving processes remained present and are recorded by the pre/post witness.

@midagedev

Copy link
Copy Markdown
Owner

Thank you. The 0.3.1 release is being cut now, so I will review this after the tag today.

@midagedev

Copy link
Copy Markdown
Owner

Thanks. The result is clear: --check-only prints the three boundary rows as false false.

We will finish it on our side and merge it. You do not need to change anything:

  • tools/check-recipes.sh is red because no recipe can run an example's tests (threshold.rs lines 177, 185 and 203). --check-only covers the same cases, so we remove that mod tests.
  • In the doc's table we write the filter values for "defaults": T0.8 k40 p0.95 m0.05.

One thing only you have: the raw --threshold-only output from your run. If you paste it here, we attach it to the doc.
It is a draft. If you still plan changes, say so; otherwise we take it from here.

@midagedev
midagedev merged commit b18b7e7 into midagedev:main Oct 12, 2026
midagedev added a commit that referenced this pull request Oct 12, 2026
… filter values

threshold.rs's mod tests ran under no gate-* or lab-* recipe; the timed
--check-only rows are the example's check. The note's table gives the
filter values (T0.8 k40 p0.95 m0.05, sample_bench.rs:100) and marks the
cost sentence [derived].

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@juliankang4 juliankang4 added documentation Improvements or additions to documentation host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset labels Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset

Projects

None yet

Development

Successfully merging this pull request may close these issues.

측정: 샘플러를 단일 확률 임계값(w = p/p_max)으로 바꾸면 얼마나 빨라지나

3 participants