Conversation
One float32 logsumexp per row, top-K ids through a 64-logit block-max prefilter, and float32(logit) - lse only at the K survivors and the scored token. Values are bitwise those of the full log-softmax; ids differ only among exact ties at the K-th value, and exact ties now order by ascending token id. Synthetic 256 x 248,320 bf16 chunk on an M5 Pro: 47 ms -> 3.4 to 5.2 ms on the GPU, 420 ms -> 150 to 170 ms on the CPU. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
jvmenen
pushed a commit
to jvmenen/MTPLX
that referenced
this pull request
Sep 25, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prompt scoring (
/v1/completionswithecho: true,max_tokens: 0,logprobs: K) picks its top-K per chunk without building a full-vocabulary float32 log-softmax. Results are bitwise identical; scoring is faster.Motivation
For every 256-row chunk,
score_prompt_logprobsmaterialised a float32 log-softmax over all 248,320 logits (256 × 248,320 × 4 bytes ≈ 254 MB), a second tensor for the subtraction, and then partitioned the whole vocabulary to find the top-K. Only K values per row and the scored token are ever returned.Change
logsumexpper row.float32(logit) - lseonly at the K survivors and at the scored token.mtplx/generation.py:_row_logsumexp_f32,_logprobs_at,_exact_top_k_ids,_argpartition_top_k,_sorted_top_k,_TOP_K_PREFILTER_BLOCK.Evidence
Synthetic, one 256 × 248,320 bf16 chunk, M5 Pro: 47 ms → 3.4–5.2 ms on the GPU (K 1 to 128), 420 ms → 150–170 ms on the CPU.
Real model: M5 Pro 64 GB, Qwen3.6-35B-A3B MTPLX Optimized-Balance, profile turbo, depth 2, fan mode default,
logprobs: 20, fresh server per run, 2026-09-26, against 2.12.0 (1de2b1c). 240 prompts of 250–840 tokens plus ~2k, ~4k and ~8k token prompts:Tests
tests/test_prompt_scoring_topk.py(25 tests): parity with the full log-softmax on synthetic bf16/f16 logits (normal, peaked, Gumbel-like), exact ties,-inf, K = 0, 1 and 128, CPU and GPU.test_no_mlx_importstests: 539 passed, 1 skipped.python -m buildandscripts/fresh_venv_smoke.shpass. Ruff: no new findings.🤖 Generated with Claude Code