Skip to content

Fix Jina reranker cosine scoring precision (#651) - #666

Merged
davidkoski merged 1 commit into
ml-explore:mainfrom
aleroot:alessio/fix-issue-651
Oct 3, 2026
Merged

davidkoski merged 1 commit into
ml-explore:mainfrom
aleroot:alessio/fix-issue-651

Conversation

@aleroot

@aleroot aleroot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

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 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.

Change looks good, thank you!

@davidkoski
davidkoski merged commit 5e46681 into ml-explore:main Oct 3, 2026
5 checks passed
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>
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.

Nightly integration tests are failing

3 participants