Repository navigation
Open KVCacheSimple and ArraysCache so a track repo can carry the Qwen 3.8 model files - #143
Merged
davidtai merged 1 commit intoSep 9, 2026
Conversation
The Qwen 3.8 Flash-Next model files (Libraries/MLXLLM/Models/Qwen4Exp*.swift
and Libraries/MLXLMCommon/Qwen4ExpCaches.swift) must compile OUTSIDE this
fork, as an editable copy in a track repository. Seven declarations blocked
that. This changes their access level only. No behaviour changes.
- Libraries/MLXLLM/Models/Qwen35MTPTopTwo.swift
qwen35MTPTopTwoRows(_:) internal -> public
Qwen4ExpCBv2 calls it for the MTP top-2 reduction.
- Libraries/MLXLMCommon/KVCache.swift
KVCacheSimple (class) public -> open
KVCacheSimple.innerState() public override -> open override
KVCacheSimple.state public override -> open override
KVCacheSimple.trim(_:) public override -> open override
KVCacheSimple.copy() public override -> open override
ArraysCache (class) public -> open
ArraysCache.copy() public override -> open override
Qwen4ExpAttentionCache subclasses KVCacheSimple and overrides those
four members. Qwen4ExpLayerCache subclasses ArraysCache and overrides
copy(). ArraysCache.extract(_:) was already open.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
davidtai
marked this pull request as ready for review
September 9, 2026 10:08
This was referenced Sep 9, 2026
Closed
davidtai
added a commit
that referenced
this pull request
Sep 16, 2026
CBv2MTPRectangularSerializing is public on this branch (PR #143), so main's new requirement must be public on LayerCacheV2 and PagedLayerCache too. Found by the first real build of the merge (ai-server). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
javiech1
pushed a commit
to javiech1/mlx-swift-lm
that referenced
this pull request
Oct 24, 2026
Layr-Labs#254) **Fix Qwen35 VLM sanitize for bare `model.*` weight keys (Layr-Labs#143)** Unified Qwen 3.5 checkpoints ship language-model tensors at bare `model.*` paths instead of `model.language_model.*`, causing a `keyNotFound` failure at load time. Adds the same `else if key.hasPrefix("model.")` fallback already present in the LLM path, prepending `language_model.` to route tensors correctly. Also adds a regression test covering all four key shapes: bare `model.*`, `model.language_model.*`, and `lm_head.*`.
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.
Stacks on #140 (
feat/qwen38-flash-next-runner). Base of this PR is that branch, notmain.What changed
Access levels only, in two files. No behaviour change, no logic touched.
qwen35MTPTopTwoRows(_:)Libraries/MLXLLM/Models/Qwen35MTPTopTwo.swift:190publicKVCacheSimple(class)Libraries/MLXLMCommon/KVCache.swift:327public classopen classKVCacheSimple.innerState()KVCache.swift:336public override funcopen override funcKVCacheSimple.stateKVCache.swift:385public override varopen override varKVCacheSimple.trim(_:)KVCache.swift:410public override funcopen override funcKVCacheSimple.copy()KVCache.swift:458public override funcopen override funcArraysCache(class)KVCache.swift:1173public classopen classArraysCache.copy()KVCache.swift:1259public override funcopen override funcSeven declarations (
KVCacheSimplecounts once for the class and four timesfor its members). No initializer had to become
open:Qwen4ExpAttentionCachecompiles its
public override init()against the inheritedpublic override init()unchanged.ArraysCache.extract(_:)was alreadyopen.Why
The Qwen 3.8 Flash-Next model files —
Libraries/MLXLLM/Models/Qwen4Exp*.swift(8 files) and
Libraries/MLXLMCommon/Qwen4ExpCaches.swift— are to be compiledOUTSIDE this fork, as an editable copy carried by a track repository. Exactly
these seven declarations blocked that:
Qwen4ExpAttentionCachesubclassesKVCacheSimpleand overridesinnerState(),state,trim(_:)andcopy().Qwen4ExpLayerCachesubclassesArraysCacheand overridescopy().Qwen4ExpCBv2callsqwen35MTPTopTwoRows.A class or member that is
publicbut notopencan only be subclassed oroverridden inside its own defining module. That is why
Qwen4ExpCaches.swiftcurrently lives in
MLXLMCommonrather than beside the model — the file says soin its own header comment.
Verification
1. The fork still builds.
→
Build of target: 'MLXRunners' complete! (329.24s). Warnings only, allpre-existing.
2. The goal is proved: the nine files compile OUTSIDE the fork.
A throwaway SwiftPM package was created outside the fork tree, depending on this
worktree by local path. The nine Qwen4Exp files were copied into it verbatim
(only
import MLXLLM/import MLXLMCommonadded) and built as a separatemodule
Qwen4ExpTrack:→
Build complete! (673.48s), with all nine object files emitted(
Qwen4Exp.swift.o…Qwen4ExpText.swift.o) andQwen4ExpTrack.swiftmodule.The package was deleted afterwards and is not committed.
Negative control. The same scratch package was rebuilt with these access
changes reverted (
git stash), everything else identical. It failed withexactly the eight blockers this PR removes and nothing else:
That is the proof the seven declarations are necessary AND sufficient.
3. Tests for the touched modules: 19 tests, all pass.
Suites:
CompilableKVCacheTests(3),Qwen35 MTP hierarchical top-2(5),KVCacheTests(11). GPU-gated and model-on-disk suites were skipped.Two environment obstacles, both pre-existing and unrelated
Recording these because they cost time and will cost the next person time.
swift test --scratch-path … --filter KVCachecannot run in this repo.It builds, then every MLX-touching case aborts at runtime with
MLX error: Failed to load the default metallib— SwiftPM does not produceor place the Metal library for the pinned mlx-swift. The tests above were
therefore run the way
.github/workflows/pull_request.ymlruns them, throughxcodebuild build-for-testing, which does build the Metal library.xcodebuild build-for-testing -scheme mlx-swift-lm-Packagefails on thisbase branch, before any test bundle is linked:
That file is untouched by this PR; the defect arrived in 4f2971f. It is not
caught today because only the CodeQL workflow runs on PRs here — the
mac_build_and_testjob did not run on feat: Qwen 3.8 Flash-Next runner stack (CBv2 runners, bench-worker, model port, n-gram LRU) #140. To get a linked test bundle theBenchLoadexecutable target was removed fromPackage.swiftlocally andtemporarily;
Package.swiftwas restored before committing and is not partof this diff. Worth a separate fix.
Also note
xcodebuildneeds-skipPackagePluginValidation -skipMacroValidationnon-interactively, because mlx-swift ships a
CudaBuildplugin that otherwisewaits on a trust prompt.
Follow-up, not done here
Qwen4ExpCaches.swiftstill carries a header comment saying the caches live inMLXLMCommonbecauseKVCacheSimpleandArraysCachearepublic, notopen.That reason is now gone. The comment was left alone deliberately — this PR
changes access levels and nothing else — and should be updated by whichever
change actually moves the file.
🤖 Generated with Claude Code