Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions .github/actions/provider-ci-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Provider CI Build
description: Build full debug test products with lane-specific caches and source-matched Metal
inputs:
lane:
description: provider or sdk; each owns independent build outputs
description: provider, sdk or cluster; each owns independent build outputs
required: true
runs:
using: composite
Expand All @@ -13,7 +13,7 @@ runs:
LANE: ${{ inputs.lane }}
run: |
case "$LANE" in
provider|sdk) ;;
provider|sdk|cluster) ;;
*) echo "Unknown provider CI lane: $LANE" >&2; exit 2 ;;
esac
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
Expand Down Expand Up @@ -41,13 +41,14 @@ runs:
path: |
provider-swift/.build
libs/mlx-swift-lm/.build
libs/darkbloom-cluster/.build
key: ${{ steps.keys.outputs.swift-key }}
restore-keys: ${{ steps.keys.outputs.swift-prefix }}
- name: Revalidate source timestamps and discard cached runtime resources
shell: bash
run: |
python3 scripts/provider-release-cache.py restore-mtimes
for root in provider-swift/.build libs/mlx-swift-lm/.build; do
for root in provider-swift/.build libs/mlx-swift-lm/.build libs/darkbloom-cluster/.build; do
[ -d "$root" ] || continue
find "$root" -type f -name mlx.metallib -delete
find "$root" -mindepth 3 -maxdepth 3 -type d \
Expand All @@ -72,8 +73,14 @@ runs:
swift package unedit --force mlx-swift >/dev/null 2>&1 || true
swift package edit --path ../mlx-swift mlx-swift
swift build --build-tests
- name: Build all cluster test products
if: inputs.lane == 'cluster'
id: cluster-build
shell: bash
working-directory: libs/darkbloom-cluster
run: swift build --build-tests
- name: Record timestamps for successfully built sources
if: ${{ !cancelled() && (steps.provider-build.outcome == 'success' || steps.sdk-build.outcome == 'success') }}
if: ${{ !cancelled() && (steps.provider-build.outcome == 'success' || steps.sdk-build.outcome == 'success' || steps.cluster-build.outcome == 'success') }}
id: timestamps
shell: bash
run: python3 scripts/provider-release-cache.py snapshot-mtimes
Expand All @@ -84,6 +91,7 @@ runs:
path: |
provider-swift/.build
libs/mlx-swift-lm/.build
libs/darkbloom-cluster/.build
key: ${{ steps.keys.outputs.swift-key }}
- name: Restore source-matched Metal cache
id: metallib-cache
Expand All @@ -99,11 +107,12 @@ runs:
METALLIB_CACHE_DIR: ${{ runner.temp }}/metallib-cache
run: |
cmake --version
if [ "$LANE" = sdk ]; then
bin=$(swift build --package-path libs/mlx-swift-lm --show-bin-path)
else
bin=$(swift build --package-path provider-swift --show-bin-path)
fi
case "$LANE" in
sdk) package=libs/mlx-swift-lm ;;
cluster) package=libs/darkbloom-cluster ;;
*) package=provider-swift ;;
esac
bin=$(swift build --package-path "$package" --show-bin-path)
./scripts/stage-test-metallib.sh "$bin"
- name: Save validated source-matched Metal cache
if: ${{ !cancelled() && steps.metallib.outcome == 'success' && steps.metallib-cache.outputs.cache-hit != 'true' }}
Expand Down
103 changes: 102 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ jobs:
test-provider-summary macos_arm64 blacksmith-12vcpu-macos-27 ${{ needs.changes.outputs.provider == 'true' && 1 || 0 }}
test-provider-sdk macos_arm64 blacksmith-12vcpu-macos-27 ${{ (github.event_name == 'push' || needs.changes.outputs.sdk == 'true') && 1 || 0 }}
test-cluster-checks macos_arm64 blacksmith-12vcpu-macos-27 ${{ needs.changes.outputs.provider == 'true' && 1 || 0 }}
test-cluster-1 macos_arm64 blacksmith-12vcpu-macos-27 ${{ needs.changes.outputs.provider == 'true' && 1 || 0 }}
test-cluster-2 macos_arm64 blacksmith-12vcpu-macos-27 ${{ needs.changes.outputs.provider == 'true' && 1 || 0 }}
test-cluster-3 macos_arm64 blacksmith-12vcpu-macos-27 ${{ needs.changes.outputs.provider == 'true' && 1 || 0 }}
test-cluster-gpu-1 macos_arm64 blacksmith-12vcpu-macos-27 ${{ needs.changes.outputs.provider == 'true' && 1 || 0 }}
test-cluster-gpu-2 macos_arm64 blacksmith-12vcpu-macos-27 ${{ needs.changes.outputs.provider == 'true' && 1 || 0 }}
test-cluster-focused macos_arm64 blacksmith-12vcpu-macos-27 ${{ needs.changes.outputs.provider == 'true' && 1 || 0 }}

release-integrity:
name: Release Integrity
Expand Down Expand Up @@ -80,6 +86,7 @@ jobs:
python3 scripts/test-provider-ci-cache.py
python3 scripts/test-provider-ci-workflow.py
python3 scripts/test-provider-test-shards.py
python3 scripts/test-cluster-test-plan.py
python3 scripts/test-ci-component-paths.py
python3 scripts/test-darkbloom-route.py
python3 scripts/test-prepare-prompt-fixtures.py
Expand Down Expand Up @@ -737,6 +744,14 @@ jobs:
DARKBLOOM_CLUSTER_METADATA_BUILD_JOBS: '12'
DARKBLOOM_CLUSTER_METADATA_BUILD_ROOT: ${{ runner.temp }}/cluster-native-metadata
run: bash libs/darkbloom-cluster-worker/Tests/CapabilityChecks/run.sh
# Builds the bootstrap product beside the capability runner's, in the same
# retained build, before the steps below record and save it.
- name: Run prefill schedule checks
if: ${{ !cancelled() && steps.toolchain.outcome == 'success' }}
env:
DARKBLOOM_CLUSTER_METADATA_BUILD_JOBS: '12'
DARKBLOOM_CLUSTER_METADATA_BUILD_ROOT: ${{ runner.temp }}/cluster-native-metadata
run: bash libs/darkbloom-cluster/Tests/PrefillScheduleChecks/run.sh
- name: Record source timestamps for the cluster build
if: ${{ !cancelled() && steps.capability-checks.outcome == 'success' && steps.cluster-build-cache.outputs.cache-hit != 'true' }}
run: |
Expand Down Expand Up @@ -767,10 +782,92 @@ jobs:
if: ${{ !cancelled() && steps.toolchain.outcome == 'success' }}
run: bash provider-swift/Tests/ClusterOnboardingChecks/run.sh

test-cluster:
# DarkbloomClusterRuntimeTests in selections, each in its own process, on
# separate Macs (scripts/cluster-test-plan.py): every test without a
# switch, and the switched tests that pass on these runners.
name: Cluster Runtime Tests (shard ${{ matrix.shard }})
needs: [changes, route]
if: ${{ needs.changes.outputs.provider == 'true' }}
runs-on: ${{ fromJSON(needs.route.outputs.routes)[format('test-cluster-{0}', matrix.shard)] }}
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: recursive
- name: Build cluster test products
id: provider-ci-build
uses: ./.github/actions/provider-ci-build
with:
lane: cluster
- name: Run cluster runtime tests
if: ${{ !cancelled() && steps.provider-ci-build.outcome == 'success' }}
timeout-minutes: 40
env:
SHARD: ${{ matrix.shard }}
run: python3 scripts/cluster-test-plan.py run blocking "$SHARD"

test-cluster-gpu:
# The switched cluster runtime tests these runners cannot pass, the long
# ones and the benchmarks (scripts/cluster-test-plan.py). They run and
# report on every pull request; a failure does not fail the workflow.
name: Cluster GPU Tests (non-blocking, shard ${{ matrix.shard }})
needs: [changes, route]
if: ${{ needs.changes.outputs.provider == 'true' }}
runs-on: ${{ fromJSON(needs.route.outputs.routes)[format('test-cluster-gpu-{0}', matrix.shard)] }}
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
shard: [1, 2]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: recursive
- name: Build cluster test products
id: provider-ci-build
uses: ./.github/actions/provider-ci-build
with:
lane: cluster
- name: Run non-blocking cluster GPU tests
if: ${{ !cancelled() && steps.provider-ci-build.outcome == 'success' }}
continue-on-error: true
timeout-minutes: 40
env:
SHARD: ${{ matrix.shard }}
run: python3 scripts/cluster-test-plan.py run nonblocking "$SHARD"

test-cluster-focused:
# The model-free runner scripts under libs/darkbloom-cluster/Tests that
# Cluster Metadata Checks does not run (scripts/cluster-test-plan.py).
name: Cluster Focused Checks
needs: [changes, route]
if: ${{ needs.changes.outputs.provider == 'true' }}
runs-on: ${{ fromJSON(needs.route.outputs.routes)['test-cluster-focused'] }}
timeout-minutes: 60
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: recursive
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: '3.12.10'
- name: Select SDK 27 provider toolchain
id: toolchain
run: ./scripts/prepare-provider-release-toolchain.sh
- name: Run cluster focused checks
if: ${{ !cancelled() && steps.toolchain.outcome == 'success' }}
timeout-minutes: 40
run: python3 scripts/cluster-test-plan.py run focused 1

provider-test-gate:
name: Provider Tests
runs-on: ubuntu-24.04
needs: [changes, test-provider, test-provider-summary]
needs: [changes, test-provider, test-provider-summary, test-cluster, test-cluster-focused]
if: ${{ always() }}
steps:
- name: Require selected provider lanes or verified intentional skips
Expand All @@ -779,6 +876,8 @@ jobs:
PROVIDER_CHANGED: ${{ needs.changes.outputs.provider }}
UNIT_RESULT: ${{ needs.test-provider.result }}
SUMMARY_RESULT: ${{ needs.test-provider-summary.result }}
CLUSTER_RESULT: ${{ needs.test-cluster.result }}
CLUSTER_FOCUSED_RESULT: ${{ needs.test-cluster-focused.result }}
run: |
test "$CHANGES_RESULT" = success
case "$PROVIDER_CHANGED" in
Expand All @@ -788,6 +887,8 @@ jobs:
esac
test "$UNIT_RESULT" = "$expected"
test "$SUMMARY_RESULT" = "$expected"
test "$CLUSTER_RESULT" = "$expected"
test "$CLUSTER_FOCUSED_RESULT" = "$expected"

cache-swift:
name: Swift Build + Cache
Expand Down
6 changes: 6 additions & 0 deletions docs/architecture/inference.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ local, starts at its installed default width
([Gemma pipeline lanes](#gemma-pipeline-lanes)); on a local pair this policy
can still widen it. Explicit diagnostic mode or lane settings retain their choice.

A stage's resident prefix tier takes half the room that LOAD measures beside
its quote, in 256 MiB steps, up to a ceiling of a thirty-second of the Mac's
memory (`QwenStagePrefixCache.budget(roomBytes:maximumBytes:)`, and the idle
refresh `refreshBudget`). The ceiling is the Mac's own: `maximumBytes`
defaults to it.

Automatic replacement reads the installed plan helper's device profile and the
current pair's recorded keyed-link costs and served-request history. It uses
the same measurement readers as initial placement, so a supported TP batch
Expand Down
35 changes: 28 additions & 7 deletions docs/developer/test.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Test Provider And Native Contracts

> Last updated: 2026-11-01
> Last updated: 2026-11-03

Run isolated Swift, native-resource, public-fixture and landing tests here.
Backend integration and cross-implementation qualification are platform-owned.
Expand Down Expand Up @@ -1174,24 +1174,45 @@ with isolated fixture runners: each `provider-swift/Tests/Cluster*Checks/run.sh`
`libs/darkbloom-cluster/Tests/*Checks/run.sh` and
`libs/darkbloom-cluster-worker/Tests/*Checks/run.sh` prints its pass count and
exits non-zero on a failure. The CI job `test-cluster-checks` (Cluster Metadata
Checks, `.github/workflows/ci.yml`) runs five of them on every pull request that
Checks, `.github/workflows/ci.yml`) runs these runners on every pull request that
changes provider code: `libs/darkbloom-cluster-worker/Tests/CapabilityChecks/run.sh`,
`libs/darkbloom-cluster/Tests/PrefillScheduleChecks/run.sh`,
`libs/darkbloom-cluster/Tests/StageMetadataChecks/run.py`,
`libs/darkbloom-cluster/Tests/GPTOSSStageChecks/run.sh`,
`libs/darkbloom-cluster/Tests/NemotronStageChecks/run.sh` and
`provider-swift/Tests/ClusterModelProvisioningChecks/run.sh provisioning`. The
last one runs the provisioning checks only. Its download cache-policy check
job `test-cluster-focused` (Cluster Focused Checks) runs every other runner
under `libs/darkbloom-cluster/Tests`. The provisioning runner runs the
provisioning checks only. Its download cache-policy check
reads how many written pages stay in the file cache, which the host's kernel
and disk decide: on the hosted CI VM 0.75 of the pages written with
`F_NOCACHE` stayed resident. Run `run.sh` with no argument on a Mac for that
check. The capability runner compiles with
`DARKBLOOM_CLUSTER_METADATA_BUILD_JOBS` jobs (4 by default; CI uses 12). CI
keeps its build in `DARKBLOOM_CLUSTER_METADATA_BUILD_ROOT` between runs and
restores source timestamps only for unchanged files, so SwiftPM rebuilds only
what changed. The library's XCTest targets
(`swift test --package-path libs/darkbloom-cluster`) and the worker package's
tests (built for macOS 26.2) need the GPU and exclusive device access. A
loopback or fixture pass never counts as a two-Mac hardware pass.
what changed. The worker package's tests (built for macOS 26.2) need the GPU
and exclusive device access. A loopback or fixture pass never counts as a
two-Mac hardware pass.

CI runs the runtime test target (`DarkbloomClusterRuntimeTests`) on the
provider's Blacksmith macOS runners, in selections that
`scripts/cluster-test-plan.py` defines. Each selection runs in a process of its
own through `scripts/run-nested-suite.sh`, which fails when the selection runs
no test or skips a test. Every process starts with `MLX_QMV_BATCH_INVARIANT=1`,
as every cluster process does.

| Selection | Job | Tests |
|---|---|---|
| Base | Cluster Runtime Tests (blocking) | Every test that needs no environment switch. The base selections pass `--skip` for the switched tests and the tests that need a model, so a test that skips there has a gate that the plan does not name |
| Opt-in | Cluster Runtime Tests (blocking) | The tests that one switch (for example `QWEN_TP_MTP_GPU=1`) enables and that pass on the CI runners |
| Opt-in | Cluster GPU Tests (non-blocking) | The switched tests that fail on the CI runners' GPU, the long-running tests and the benchmarks. The job reports their results and does not fail the workflow |
| Needs a model | None | The tests that need a model directory, an artifact or its metadata (`REQUIRES_MODEL`). CI has no model |

`python3 scripts/test-cluster-test-plan.py` (Release Integrity) checks that the
plan names each gated test in the sources once, and each runner under
`libs/darkbloom-cluster/Tests` once. When you add an environment gate to a
runtime test, add the test to a selection or to `REQUIRES_MODEL`.

Build the runtime tests once (`swift build --package-path libs/darkbloom-cluster
-c release --build-tests --triple arm64-apple-macosx26.2 -Xcc -target -Xcc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,13 @@ public final class QwenStagePrefixCache: @unchecked Sendable {
var captureCost: QwenStagePrefixCaptureCost? { lock.withLock { measured } }

/// The budget for `roomBytes` of admissible memory left beside the
/// serving context's charge: half of it, at most `maximumBudgetBytes`,
/// rounded down to 256 MiB so the idle refresh does not move it with
/// every small drift. The serving context is never reduced for the
/// cache; the other half stays for the desktop's own drift.
public static func budget(roomBytes: Int) -> Int {
max(0, min(maximumBudgetBytes, roomBytes / 2) / budgetGranuleBytes * budgetGranuleBytes)
/// serving context's charge: half of it, at most `maximumBytes` (this
/// Mac's `maximumBudgetBytes`), rounded down to 256 MiB so the idle
/// refresh does not move it with every small drift. The serving context
/// is never reduced for the cache; the other half stays for the desktop's
/// own drift.
public static func budget(roomBytes: Int, maximumBytes: Int = QwenStagePrefixCache.maximumBudgetBytes) -> Int {
max(0, min(maximumBytes, roomBytes / 2) / budgetGranuleBytes * budgetGranuleBytes)
}
static let budgetGranuleBytes = 256 << 20
/// The room a memory-bound serving context leaves for the cache: one granule of budget (half the room).
Expand Down Expand Up @@ -260,8 +261,8 @@ public final class QwenStagePrefixCache: @unchecked Sendable {
/// directions, so a load during a memory dip does not keep it small for as
/// long as the model stays loaded. Entries beyond a lower budget go now.
/// True when the budget changed.
@discardableResult func refreshBudget(roomBytes: Int) -> Bool {
let target = Self.budget(roomBytes: roomBytes)
@discardableResult func refreshBudget(roomBytes: Int, maximumBytes: Int = QwenStagePrefixCache.maximumBudgetBytes) -> Bool {
let target = Self.budget(roomBytes: roomBytes, maximumBytes: maximumBytes)
return lock.withLock {
guard target != budget else { return false }
budget = target; evictLocked(reserving: 0); return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ struct LongContextLimitsTests {
chunkSize: min(512, context - 1)).conservativeStateAndBoundaryBytes
let transient = try QwenResidentPrefillTransient.bytes(geometry: geometry, stageHasAttention: true,
chunkTokens: min(512, context - 1), contextTokens: context)
let required = state + transient + QwenDenseStageLoadPolicy.loadingHeadroomBytes
let required = state + transient + QwenDenseStageLoadPolicy.loadingHeadroomBytes(physicalMemoryBytes: os.physicalMemoryBytes)
return try QwenDenseStageLoadPolicy.decide(os, requiredBytes: required, purpose: "test context \(context)", now: 1_100).admitted
}

Expand Down
Loading
Loading