Repository navigation
ci: cache the Metal library and run the tests in parallel shards - #60
Merged
Merged
Conversation
Build the package and its tests one time, build or restore the Metal library in a parallel job, and run the tests in shards planned from measured durations. A guard fails when a listed test is in no shard or in two shards, and a final job checks that every test ran exactly once. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Listing loads the test bundle, and the bundle needs the Metal library. The build job does not have the library, so each shard now lists the tests and makes the plan. The final job checks that the plans match. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The five example dSYMs are 670 MB of the 921 MB tar. The tests do not use them. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
davidtai
marked this pull request as ready for review
October 23, 2026 07:28
This was referenced Oct 23, 2026
jonathan308
added a commit
that referenced
this pull request
Oct 26, 2026
…ack (#56) Forward merge of the refreshed #54 (main 6959486 merged into the JACCL fixes pin) into this branch. This branch already carried main up to the #58 squash 67dc752, so the new main content is the upstream ml-explore/mlx-swift merge ce46846 (#59, with #60 and #62), the core and C repin with regenerated sources (#63) and the wrapped external buffer test (#64). Conflicts: - Source/Cmlx/mlx and Source/Cmlx/mlx-c (gitlinks): kept this branch's pins, core 360d11b9 and mlx-c 8a50797b. They are restitched to the merged core and C heads separately. - fork.yaml, "Submodule pins": one paragraph that states main's pins (mlx ff4bb35b, mlx-c 004c735f, merges of upstream main) and then what the cluster core and C add on top. Every other section merged without conflict; the cluster's startup-wait section is kept. Merged without conflict and checked: the mirrored fast.h keeps the fenced kernel and prepared launch declarations next to main's math-mode entry point, distributed_group.h keeps the bootstrap, startup-wait and sealed-codec declarations, and MLXArray.sharingArray() still calls copyContext(), which main keeps. The tree is main plus this branch's own delta: the two gitlinks, those two headers, MLXArray.swift, MLXFastKernel.swift, docs/startup-wait-budget.md and fork.yaml. Main's Transforms+Eval.swift now schedules under evalLock and waits outside it (upstream ml-explore#474). withSerializedEvaluation still runs its body under evalLock, so native evaluation, fences and collectives stay serialized against scheduling; a Swift eval's wait no longer excludes them. Tests (Ultra A, Xcode 27.1). These ran on this merge with the two follow-up commits on top (swift-format and fork.yaml). The committed gitlinks are not changed. For the build, the nested repos were checked out at merged heads: core 2b5253ad (the core merge into mlx#35; 69c0a0f6 gave the same results) and a temporary merge of mlx-c main 004c735f into 8a50797b. Its C sources merge cleanly; CMakeLists.txt and fork.yaml are taken from 8a50797b. - swift build --build-tests: complete. - Fork Tests, all 3 shards of the CI plan, with an AOT mlx.metallib from that core: - XCTest: 852 listed, 848 passed, and the 2 permitted skips. - The fresh-process allocation-cap test and both multi-process ring suites passed. - Swift Testing: 749 of 749 passed. - test-shards.py verify: every test ran exactly once. - check-generated-metal-sources.py passes against that core. - The mirrored mlx/c headers are byte-identical to the merged C headers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308
added a commit
that referenced
this pull request
Oct 26, 2026
Brings in main up to 6959486 (2026-10-24): the upstream ml-explore/mlx-swift merge ce46846 (#59, with #60 and #62), the core and C repin with regenerated sources (#63) and the wrapped external buffer test (#64). Conflicts: - Source/Cmlx/mlx and Source/Cmlx/mlx-c (gitlinks): kept this branch's pins, core fdae3174 and mlx-c 489e9654, as the cluster stack has them. Main pins core ff4bb35b and mlx-c 004c735f. The cluster pins are restitched to the merged core and C heads separately; the Swift layer of this merge needs main's C API and does not link against the old pins. The merged tree is main plus this branch's own delta: the two gitlinks and the mirrored distributed_group.h copies that declare mlx_distributed_init_jaccl_with_bootstrap (main did not change those headers). Tests (Ultra A, Xcode 27.1). The committed gitlinks are not changed. For the build, the nested repos were checked out at merged heads: core 187b6c67 (the core merge of main f78f0fa9 into mlx#33) and a clean, temporary merge of mlx-c main 004c735f into 489e9654. - swift build --build-tests: complete. - Fork Tests, all 3 shards of the CI plan, with an AOT mlx.metallib from that core: - XCTest: 852 listed, 848 passed, and the 2 permitted skips. - The fresh-process allocation-cap test and both multi-process ring suites passed. - Swift Testing: 749 of 749 passed. - test-shards.py verify: every test ran exactly once. - check-generated-metal-sources.py passes against that core. At the committed core it fails, because main regenerated the quantized sources. - check_forkdiff.py --upstream-ref upstream/main: 211 of 211 files described. - Lint: this branch changes no Swift file against main. 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
This PR makes the Fork Tests workflow faster. On a warm cache, the run takes about 8 minutes. The old single job took 26 minutes. Each test still runs exactly once. No test is skipped, removed or changed.
Stacked on #59 (
sync/upstream-2026-10-22). The base of this PR is that branch.Design
The old workflow had one job. It built the package (6.9 min), then built the Metal library (8.2 min), then ran all tests (9.5 min plus 0.9 min for the ring tests), one after the other.
The new workflow has these jobs:
Build the package and its testsBuild the full Metal librarymlx.metallibfrom the cache, or builds it. Uploads it as an artifact.Test shard 1..3build-and-testA run uses 6 macOS jobs. At most 3 run at the same time. On a pull request, a new push cancels the older run (
cancel-in-progress), so the older run frees its runners.The shared
Select the newest release of Xcode 26steps are now one composite action,.github/actions/select-xcode. The Lint workflow uses it too.scripts/build-metallib.shhas two new modes.build FILEbuilds the library and writes it to FILE.install FILEcopies FILE into the test bundles. With no arguments, the script works as before.Shard map and how it stays complete
.github/scripts/test-shards.jsonhas the shard count (3) and the measured durations from run 39876188612..github/scripts/test-shards.py planmakes the plan:Class/methodkey insecondsmakes that method its own unit. Today this is onlySortedGatherQuantizedMMTests/testQwenSortedGatherQuantizedMMMatchesLegacyOnRandomTensors(208 s in the baseline).ProcessAllocationCapTests,DistributedRingTestsandDistributedNNRingTestsare one unit. They run in their own processes with their own environment, as before.The plan comes from
swift test liston the built bundle. It does not come from a fixed list. Thus a new test is always in a shard.Plan of the last run (estimated seconds from the baseline):
The guard
There are two checks:
test-shards.py planfails when a listed test is in no shard or in two or more shards. It also fails when a class inisolatedis not in the list. A stale duration gives a warning only, because it does not change which tests run. Each shard makes the same plan. The final job checks that all plans are the same.test-shards.py verifyin the final job reads the logs of all shards. It fails when a listed XCTest test did not run, ran two or more times, failed, or skipped without permission. OnlyQwenExpertTilePerfTests/testQwenRoutedPrefillUnitTimingsandSortedGatherQuantizedMMTests/testQwenSortednessViolationRetractsToLegacyRoutemay skip, as before. Each ring test must pass in every rank and run in no other process. For Swift Testing, the count in the summary line must equal the listed count, and every result must bepassed.Each shard also keeps the old checks: the fresh-process allocation-cap check, the ring-suite checks, the zero-tests check and the unexpected-skip check.
Guard result on every green run of this PR:
XCTest: 849 listed, 847 results outside the ring ranks, 2 ring tests. Swift Testing: 749 listed.847 + 2 = 849. Every listed test ran exactly once.Cache keys
macOS-metallib-xcode-<version>-mlx-<mlx gitlink>-<hash of scripts/build-metallib.sh and Source/Cmlx/mlx-generated/**>macOS-build-xcode-<version>-mlx-<mlx gitlink>-mlxc-<mlx-c gitlink>-<hash of Package.swift and Source/** without the submodules>The old cache saved
.build(291 MB) and only on main. It missed on every PR that changedPackage.swift. The new build cache stores ccache objects. ccache finds an object by a hash of its compile, so an older cache gives correct objects for the files that did not change. After the build, ccache removes the objects that the build did not use, so the cache does not grow. Both caches save on the pull request and on main. A pull request can read the caches of main, of its base branch and of its own branch.The C and C++ core compiles through a
clangwrapper inCCthat calls ccache. The Swift compile does not use ccache, and it is most of the warm build time (about 2 min).Measured times
All runs are on hosted
macos-26. Times are job wall-clock from the GitHub API. "Run" is from the run start to the end of the last job.build-and-test(verify, coverage)The cold run on the new mlx pin is the slow case. It happens only on a re-pin. In that run, the Metal library download in shard 2 took 51 s. In the other runs it took 4 to 6 s.
Long tests in the warm run: the Qwen sorted-gather test 112 s,
CompileLockOrderingTests/testConcurrentDeinitErasesAndCompiledCalls63 s,MemoryTests/testResourceCountStaysUnderLimitUnderChurn19 s (43 s in the cold run). The churn test no longer controls the run time.The test-products artifact is 275 MB before compression and 49 MB after. It does not have the object files, the executables or the dSYMs of the example programs.
Not changed
MLX_ENABLE_TF32=0,MLX_GATHER_QMM_EXPERT_SLICES=1,MLX_RESOURCE_LIMIT=50000,MLX_TEST_PROCESS_CAP=1,MLX_TEST_DISTRIBUTED=1).macos-26.actions/cachev6.1.0,actions/upload-artifactv4.6.2) andactions/download-artifactv4.3.0 (d3f86a106a0bac45b974a628896c90dbdf5c8093). ccache comes from Homebrew.Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes (no Swift files change)fork.yamldescribes the newbuild-metallib.shmodes)An AI agent (Claude Code) wrote this PR. A person reviews and merges it.
🤖 Generated with Claude Code