Skip to content

Use per-row rotary positions for FastVLM decoding - #39

Open
ronaldmannak wants to merge 1 commit into
codex/rotating-cache-test-accessfrom
codex/fastvlm-per-row-rope
Open

ronaldmannak wants to merge 1 commit into
codex/rotating-cache-test-accessfrom
codex/fastvlm-per-row-rope

Conversation

@ronaldmannak

Copy link
Copy Markdown
Owner

Closes #33. Stacked on #38.

When separately prefilled FastVLM image and text requests join a ragged decode batch, the shorter row currently receives the batch's scalar rotary position. Its logits and newly cached keys diverge from independent single-row decoding. FastVLM now uses each cache's existing ropeOffset through applyRotaryPosition; ordinary single-row caches keep scalar offsets.

What changed

  • Replace three lines in FastVLM attention with the existing rotary helper.
  • Add a tiny real FastVLM image/text prefill regression to MLXLMTests.
  • Compare full logits, greedy tokens, per-row K/V arrays, and offsets over continued decoding and after filtering a row.

Evidence

xcodebuild test -scheme mlx-swift-lm-Package -destination 'platform=macOS,arch=arm64' -skipPackagePluginValidation -skipMacroValidation -derivedDataPath /private/tmp/mlxlm-phase2-derived -only-testing:MLXLMTests/FastVLMRaggedDecodeTests

Before production change:
Test run with 1 test in 1 suite failed after 0.452 seconds with 8 issues.
Example: shorter-row logit difference 0.18787873; retained K/V difference 2.4315264.

After production change, unchanged test:
Test run with 1 test in 1 suite passed after 0.086 seconds.
** TEST SUCCEEDED **

pre-commit run --all-files
swift-format.............................................................Passed

The fixture uses deterministic random weights and actual image prefill on CPU; it downloads no model. Maximum permitted logit/KV difference is 1e-4. Local review found no additional abstraction or API needed. The full parent suite compiled and ran, with all 757 Swift Testing tests passing and one separate unchanged XCTest failure tracked in #37; this PR does not claim a green full suite. DocC and iOS have not been run locally.

Test changes

This PR adds one test file and changes no existing test. Its independent single-row caches retain the reference histories throughout the batch lifecycle.

Scope

No public API, scheduler, or cache-layout change. Gemma3 and wrapped rotating-cache conversion are separate issues #34 and #35. PicoCore will enable families only after consuming and validating the corresponding fork fixes.

AI assistance: Codex prepared the change, regression, and validation report.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-10T22:16:39.736509Z 1ab1c65 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant