Repository navigation
Fix Jina reranker cosine scoring precision (#651) - #666
Merged
Merged
Conversation
aleroot
force-pushed
the
alessio/fix-issue-651
branch
from
October 2, 2026 22:21
bcb0ada to
0cf870c
Compare
davidkoski
approved these changes
Oct 3, 2026
davidkoski
left a comment
Member
There was a problem hiding this comment.
Change looks good, thank you!
wballard
added a commit
to swissarmyhammer/mlx-swift-lm-old
that referenced
this pull request
Oct 7, 2026
Apply the upstream commits 55db721..ecd8e88 as a 3-way patch. CLAUDE.md is excluded. - 5e46681 Fix Jina reranker cosine scoring precision (ml-explore#651) (ml-explore#666) - c07010e Make reranker cancellation test deterministic (ml-explore#669) - 6d84ef6 Introduce component-aware checkpoint loading (ml-explore#679) - 282c2f5 Report KV cache memory in KVCacheStatus (ml-explore#639) - 0754e10 Fix Gemma tool calls losing nested object and array arguments to raw strings (ml-explore#626) - ecd8e88 Add generation observability (ml-explore#640) Conflict resolutions: - Evaluate.swift: keep discardGeneratedToken and stopTokenFedToCache of stable, and add the upstream lastLogProbabilities, evictedTokenCount, reasoningTokenCount and recordEmittedToken. handleGeneratedToken now records the emitted token and calls the upstream onToken with the log probabilities and emit. - KVCache.swift: CacheList keeps the offset and residentByteCount of stable and gets the upstream evictedTokenCount. - TurboQuantKVCache.swift: take the upstream innerState() override and memoryBytes. Remove the residentByteCount override of stable, because the base implementation now counts the same buffers through innerState(). - Load.swift: keep the async loadWeights of stable with the ModelWeightResidency raise and the dispatch to a global queue. installWeights now uses the upstream checkpoint API (loadModelCheckpoint and prepareCheckpoint) and quantizes from the per-layer plan of the checkpoint through quantizationParameters. Test changes for stable: - Gemma3nCheckpointTests and Qwen35MTPTests: loadWeights and convert are async on stable, thus the new upstream tests use await. - SpeculativeDecodingTests: the new upstream test expected a draft cache that trails by one token. On stable, finalizeGeneration() aligns the draft cache with the main cache, thus the test expects offset 3. No upstream commit in this range changes MiniMax code. Tests (xcrun xctest): MLXLMTests 1344 Swift Testing and 711 XCTest tests pass. MLXGuidedGenerationTests 70, MLXFoundationModelsTests 349, CXGrammarTests 7, MLXHuggingFaceMacrosTests 5 pass. 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
Fix #651.
The Jina v3 source checkpoint uses a bfloat16 projector, while the converted MLX checkpoint uses float32. Our cosine helper computed products and norms in the embeddings’ dtype, introducing additional rounding and allowing float16 underflow or overflow.
Compute cosine scores in float32, matching the source reranker’s final scoring calculation. Add regression tests covering positive, negative, and zero-vector scores across supported precisions, plus float16 underflow and overflow. The integration score baseline and tolerance remain unchanged.
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.