Repository navigation
fix(paged): write a full destination for broadcast direct KV - #210
Merged
Merged
Conversation
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>
This was referenced Sep 30, 2026
This was referenced Oct 3, 2026
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>
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
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 byfinishEvaluation(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 withMLX.where(MLXArray(true), bits, bits)to get a fresh exact destination. When every input ofwhereholds 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 arebroadcast([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:finishEvaluationcorrectly refuses that root, so a valid packed prompt step fails. The fix wraps the result incontiguous. In the one-element case MLXContiguouscopies into a full row-major buffer. In the usual case thewhereoutput is already a fresh full row-contiguous buffer, andContiguousshares 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
CBv2AsymmetricPagedStorageTestswithFatal error: process charge retirement refused. That suite runs beforeCBv2PagedAttentionWorkReservationTestsand theMiMo*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*andPagedMTP*show no new failures (the other failures inCBv2PagedAttentionWorkReservationTestsare the three XCTUnwrap tests, fixed in #209).Checklist
swift formaton the changed filetestPackedRowsWithDifferentActualRangesStayIndependentfails before and passes after)fork.yamlalready covers the file,check_forkdiff.pypasses)🤖 Generated with Claude Code