Repository navigation
Report the full-vocabulary entropy with token log probabilities - #822
Merged
davidkoski merged 1 commit intoNov 26, 2026
Merged
Conversation
This was referenced Nov 21, 2026
wballard
added a commit
to swissarmyhammer/mlx-swift-lm
that referenced
this pull request
Nov 30, 2026
Apply the upstream commits a2b47a7..026d599 (the 6 after 6759555) as cherry-picks. CLAUDE.md is untouched. Where a conflict was only a fork refactor, upstream's code is taken; the fork's MTP speed and prompt-cache behavior is kept. - a2b47a7 Batching: Use per-row rotary positions and attention scaling in LLM and VLM models (ml-explore#773) - b4cc88a Select LFM2-MoE experts in mlx-lm's argpartition order (ml-explore#830) - 9e0f27d Expand the segsum batch mask once, as mlx-lm does (ml-explore#829) - 4d2d8a3 Report the full-vocabulary entropy with token log probabilities (ml-explore#822) - fa4c14a Attend a rotating cache with a rewind reserve in place (ml-explore#727) - 026d599 Bonsai 2.5: Rotate Hadamard-quantized activations in one Metal pass (ml-explore#835) Conflict resolutions: - ml-explore#773: the Qwen 3.5 VLM decode positions take upstream's QwenVL.decodePositionIds; the fork's version differed only by the MRopeAxis.count name. - ml-explore#830: LFM2MoeRoutingTests keeps the fork's removal of the unused TokenizerLoaderStub and takes upstream's makeConfig(numExpertsPerToken:). - ml-explore#822: the Evaluate.swift hunks go into the fork's GenerateParameters.swift (GenerateTokenLogProbabilities.entropy) and TokenIterators.swift (DeferredTokenLogProbabilities). The speculative log-probability test is not taken: the fork's SpeculativeTokenIterator reports no log probabilities, and the doc keeps saying so. - ml-explore#727: the KVCache.swift hunks go into the fork's RotatingKVCache.swift (retainedRanges over the fork's rowRanges, so the window mask also leaves out vacant rows after a rewind). RotatingKVCache does NOT conform to KVCacheAttentionProtocol: the fork's prefill kernel, DeepSeek-V4 and Inkling 2 read a conforming cache as one that owns its attention (Inkling 2 stops with a precondition). attentionWithCacheUpdate calls RotatingKVCache.updateAndAttend directly, and passes the fork's sinks through. The Qwen MTP drafter attends through PrefillAttentionKernel and keeps update(keys:values:). Two tests cover the sinks and the non-conformance. After-merge steps: no merged model adds advance( with a manual offset +=, no new MambaCache/ArraysCache model type, no environment-gated test. Tests: all five bundles pass under xctest (MLXLMTests 1272 XCTest + 2865 Swift Testing, MLXGuidedGenerationTests 96, MLXFoundationModelsTests 770, CXGrammarTests 7, MLXHuggingFaceMacrosTests 11). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Proposed changes
Token log probabilities only expose the top candidates, so a caller that wants the uncertainty of a step has to estimate the entropy from them, and that estimate breaks when the probability outside the top-k spreads over many tokens.
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changesAI usage
accurately describes the code changes.