Priority: P1 — quick CPU-path improvement
Agent ownership: crates/aien-serve-http/src/sampling.rs and sampling-specific tests/benchmark only
Estimated engineering effort: a few hours, plus benchmark time
Goal
Remove unnecessary full-vocabulary sorting from OWN-30B HTTP sampling without changing any token decisions or sampling receipts.
Observed on main (rechecked 2026-10-17)
crates/aien-serve-http/src/sampling.rs::top_k_maskbuilds an index vector for the entire logits array, sorts it, and retains only K entries.SamplingObserver::sampleuses this for0 < top_k < vocabwith non-greedy temperature;ServerConfigdefaults totop_k=20.- Vocabulary is ~152k logits. This is unnecessary CPU work; no end-to-end throughput gain has been measured.
Agent implementation
- Keep a test-only reference version of the current full-sort behavior.
- Replace the production full sort with exact top-K partial selection (bounded heap or
select_nth_unstable_by, sorting K winners only when needed). - Preserve rank semantics for finite logits (higher value first, lower token ID on exact ties); excluded logits remain negative infinity.
- Preserve greedy sampling,
top_k=0,k>=vocab, seed/top-p behavior; explicitly test infinities, NaNs, ties at the cutoff and all-equal vectors. Do not silently change nonfinite semantics. - Introduce a narrowly scoped sampler microbenchmark without a dependency or HTTP server rewrite.
Acceptance criteria
- Optimized and reference masks agree for deterministic random finite vectors and K = 0, 1, 20, 100, vocab-1, vocab; include negative values and ties.
- Selected token IDs, seeded replay and all
SamplingRecordfields match before/after (kept-set metrics, probability/logprob metrics, etc.). - Nonfinite-value behavior is regression-tested and any comparator ambiguity documented.
-
cargo test --locked -p aien-serve-httppasses;cargo clippy --locked -p aien-serve-http --all-targets -- -D warningsclean, or blockers explained. - Include reproducible before/after CPU microbenchmarks at ~152k vocab and K=1,20,100 with same host/compiler/profile, medians and spread.
- If idle GB10 available, matched HTTP A/B measures real service throughput; do not claim tokens/sec gain based solely on microbenchmarks.
- Small independent PR with rollback path, no unrelated changes.
Coordination / excluded scope
Can start immediately. Do not edit omega_engine.rs, server.rs, qwen3_moe_omega.rs, decode graph or GPU-lock scripts. Existing PR #595 touches HTTP server internals.
Source: https://github.com/aien-dev/aien-sovereign-core-mv/blob/main/crates/aien-serve-http/src/sampling.rs