Skip to content

Report the full-vocabulary entropy with token log probabilities - #822

Merged
davidkoski merged 1 commit into
ml-explore:mainfrom
aleroot:alessio/log-probability-entropy
Nov 26, 2026
Merged

davidkoski merged 1 commit into
ml-explore:mainfrom
aleroot:alessio/log-probability-entropy

Conversation

@aleroot

@aleroot aleroot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

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 x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

AI usage

  • I have read this PR description in full and approve it as my own, and it
    accurately describes the code changes.
  • AI usage disclosure:

@davidkoski davidkoski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense, thank you!

@davidkoski
davidkoski merged commit 4d2d8a3 into ml-explore:main Nov 26, 2026
3 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants