Skip to content

fix(paged): write a full destination for broadcast direct KV - #210

Merged
Gajesh2007 merged 1 commit into
mainfrom
fix/paged-compact-broadcast-kv
Oct 3, 2026
Merged

Gajesh2007 merged 1 commit into
mainfrom
fix/paged-compact-broadcast-kv

Conversation

@davidtai

@davidtai davidtai commented Sep 30, 2026 •

Copy link
Copy Markdown

Proposed changes

Fixes CBv2PagedAttentionWorkReservationTests.testPackedRowsWithDifferentActualRangesStayIndependent, one of the six tests that fail in the whole-package pass of Fork Tests on main (run 36741368847, run 36769006274 on 0871943).

Kind of fix: production defect. The test is correct.

Error: PagedAttentionWorkReservation.swift:471: caught error: "backendIneligible(reason: "retained paged producer root is not a bounded compact destination")", thrown by finishEvaluation (the check at PagedAttentionWorkReservation.swift:455-463).

Root cause: PagedLayerCache.prepareRetainedWork (Libraries/MLXLMCommon/ContinuousBatchingV2/Paged/PagedLayerCache.swift:1126-1130) "compacts" direct prompt K and V with MLX.where(MLXArray(true), bits, bits) to get a fresh exact destination. When every input of where holds one element, MLX uses the scalar ternary path: the output gets a one-element buffer and keeps the broadcast strides. The test packs two rows whose values are broadcast([3, 9]); the second row starts at offset 0, so its values take the direct path and are one broadcast element. A diagnostic print of the retained roots on origin/main shows it:

shape=[1, 1, 16, 128] dtype=float32 nbytes=8192 alloc=4 off=0 elems=1 contig=false

finishEvaluation correctly refuses that root, so a valid packed prompt step fails. The fix wraps the result in contiguous. In the one-element case MLX Contiguous copies into a full row-major buffer. In the usual case the where output is already a fresh full row-contiguous buffer, and Contiguous shares it (copy_shared_buffer, no kernel, no new allocation), so real projections see no change.

Why these tests fail only since #178

The tests were added in #171. On #171 (run 36617213525, fe71e37) the whole-package pass stopped early: the xctest process crashed in CBv2AsymmetricPagedStorageTests with Fatal error: process charge retirement refused. That suite runs before CBv2PagedAttentionWorkReservationTests and the MiMo* suites, so those suites never ran. #178 fixed that crash, and from eeba2af on the pass reaches these suites for the first time. The failures are not from #178 or #188. They also fail the same way on an M5 laptop, so the hosted runner (M1, 7 GiB, 3 cores) is not the cause.

Evidence

Local run (M5, MLX_ENABLE_TF32=0, staged full metallib): on origin/main the test fails with the CI error; with this change it passes. CBv2PagedAttentionWorkReservationTests, CBv2Paged*, CBv2AsymmetricPaged* and PagedMTP* show no new failures (the other failures in CBv2PagedAttentionWorkReservationTests are the three XCTUnwrap tests, fixed in #209).

Checklist

  • I have read the CONTRIBUTING document
  • I have run swift format on the changed file
  • I have added tests that prove my fix is effective or that my feature works (testPackedRowsWithDifferentActualRangesStayIndependent fails before and passes after)
  • I have updated the necessary documentation (if needed) (not needed; fork.yaml already covers the file, check_forkdiff.py passes)

🤖 Generated with Claude Code

prepareRetainedWork compacts direct prompt K and V with
where(true, bits, bits). When the bits hold one element, for example a
broadcast scalar, MLX keeps the one-element buffer and the broadcast
strides. finishEvaluation then refuses the step: "retained paged
producer root is not a bounded compact destination". contiguous now
writes the full row-major destination in that case. For a full result
it shares the buffer and copies nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Gajesh2007
Gajesh2007 merged commit 3799b11 into main Oct 3, 2026
5 of 6 checks passed
@davidtai
davidtai deleted the fix/paged-compact-broadcast-kv branch October 4, 2026 21:57
Gajesh2007 added a commit that referenced this pull request Oct 4, 2026
#289)

* fix(cache): preserve demanded fork checkpoints and bound short capture

* test: let expected paged work refusals reach the caller (#209)

PagedWorkFixture.prepare wrapped prepareAttentionWork in XCTUnwrap.
XCTUnwrap records a test failure when its expression throws, also
when the caller expects the throw with XCTAssertThrowsError. Three
tests expect prepare to refuse, so each expected refusal was recorded
as a failure. prepare now throws the refusal to the caller and fails
only when prepareAttentionWork returns nil.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit b7bbdc2)

* fix(paged): write a full destination for broadcast direct KV (#210)

Materialize broadcast retained KV into a complete contiguous destination while preserving bit values, ownership validation, and reservation bounds. Focused differential paging, lifetime, and bit-exact validation completed during review.

(cherry picked from commit 3799b11)

* test(mimo): skip native-lane tests on machines without the lane (#192)

Since eeba2af (#178), 31 XCTest cases in five MiMo suites throw
nativeLaneRequired on the hosted CI runner, so every run of Fork Tests
on main fails. The tests need the exclusive native GPU lane, which the
runner does not have.

This change turns each of those throws into an XCTSkipUnless on the
same environment variables. The tests now skip, with the reason, on a
machine without the lane, and run as before where the variables are
set. The unused nativeLaneRequired enum case is removed from each
suite.

Tests only. No production code change.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit c288f53)

* test(mimo): assert the MiMo contracts that #171 shipped (#211)

Three assertions in the MiMo tests disagree with the code that the same
PR (#171) added:

- The MiMo cache conforms to CBv2MTPRectangularSerializing, and
  MiMoV26RectangularVerifyTests asserts that the bank supports
  rectangular MTP verification. The test asserted the opposite.
- CBv2PrefillRequirement.evaluationOnly returns a [B, 1] handle
  (EngineLoopV2.prefillOutput). The test expected shape [1].
- MiMoV26MTPAssistant conforms to
  CBv2HistoricalMTPPrefixCheckpointCoding (MiMoV26MTPPrefixCheckpoint).
  The test asserted that it is not a prefix checkpoint drafter.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 5e9d268)

* test: run bit-exact reference tests only on reference hardware (#174)

* style: format DiffusionGemmaVisionOracleTests.swift

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* style: format DiffusionGemmaFactoryTests.swift

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: run bit-exact reference tests only on reference hardware

Nine DiffusionGemma tests compare float bits with frozen references.
On the hosted macos-26 runner (Apple M1 VM) they differ in the low bits,
with no change in shape, dtype or sign. Add a `.referenceHardware`
Swift Testing trait that runs a test only when MLX_REFERENCE_HARDWARE=1,
and mark the nine tests with it. Elsewhere they report as skipped with
the reason. No assertion, tolerance or reference changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: gate only the bit comparisons of mixed DiffusionGemma tests

Three gated tests also held checks that pass on any hardware. Split them
so only the bit-for-bit comparison is gated:

- prefixIdentityTokensOwnerAndEmptyStateFailClosed() runs its
  fail-closed probes on all hardware. The donor-logits bit comparison
  moves to failClosedProbesLeaveDonorLogitsBitExact().
- nativeFactoryLoadsExactStateAndReleasesItsModel() keeps the load and
  model-release checks on all hardware. The logits bit comparison moves
  to nativeFactoryDenoiseMatchesReferenceBits().
- The two parameterized vision tests run their bf16 case on all
  hardware. The fp32 case moves to a separate gated test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: gate only the reference comparisons of three more DiffusionGemma tests

Split the three tests that were still gated whole, so their checks that
pass on any hardware run everywhere:

- chunkedSessionBoundsPrefillAndCanCancelAfterPrefill() keeps the
  prefill bounds, the complete flag, the counters, cancel, the emitted
  checkpoint and the released cache for widths 1, 3 and 7. The KV and
  logits bit comparisons move to chunkedSessionMatchesIndependentNativeReference().
- sharedWeightsConditioningKeepsCommittedCacheState() keeps the fixture
  checks, both cache positions and the unchanged encoder KV after the
  provisional canvas. The reference comparisons stay in
  sharedWeightsConditioningAndCommittedCacheMatchReference().
- committedPrefixRestoreKeepsPositionsAfterDonorRetirement() keeps the
  token count, retained bytes, donor release and both positions. The
  reference comparisons stay in
  committedPrefixRestoreIsExactAfterDonorAppendAndRetirement().

Each pair shares one helper. The fixture reference, case-count and
parameter-count checks of the block and fp32 vision fixtures also run
everywhere now, in blockOracleFixtureIsPinned() and fp32FixtureIsPinned().
CONTRIBUTING.md says which comparisons the gate covers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit a046367)

* docs: describe demanded checkpoints and their shared fixture

* fix(cache): honor request participation in short checkpoint scheduling

* Preserve demanded checkpoint eligibility through preemption and packing

* test: size the slot-cap request from what the ledger accepts

slotCapLeavesRoomForServing() sized its request from bytesReserved.
bytesReserved includes the paged pool's physical-floor overhead, which a
request's target KV replaces when it reserves. The overhead depends on
the buffer sizes the MLX allocator returns: a 36,864-byte segment gets a
49,152-byte buffer, or a 65,536-byte buffer reused from the process-wide
cache. When earlier work left 64 KiB buffers in the cache, the capped
arm left more than 5.5 windows of real slack instead of half a window,
and the uncapped arm's reservation fit.

Find the largest request the ledger accepts beside the capped set with
trial reservations, then take half a window off it. The assertions do
not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 06224a8)

* Retain demanded native frontiers and preserve observed prefill endpoints

* Document current SDK parameters and generation links

* Disambiguate the task generation documentation link

---------

Co-authored-by: David Tai <dtaipublic@gmail.com>
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants