Skip to content

Enable Windows ARM64 CUDA GGUF inference - #385

Merged
Brooooooklyn merged 19 commits into
mainfrom
codex/windows-cuda-gguf
Nov 17, 2026
Merged

Brooooooklyn merged 19 commits into
mainfrom
codex/windows-cuda-gguf

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Contributor

Summary

Enable native CUDA GGUF inference on Windows ARM64 (validated on an NVIDIA RTX Spark, CUDA 13.4), fix the desktop app startup and model-switching crashes, and add real Windows WASAPI audio-device discovery.

What changed

  • Native CUDA/GGUF: NVRTC K-quant sources no longer depend on host C standard headers; the bridge exposes mlx_clear_streams() and model threads release CUDA streams before Windows thread teardown.
  • MLX submodule: pinned to 849f8934, which releases the cuDNN handle and its graph caches inside clear_streams() while CUDA Runtime is still usable. Windows was destroying a used cuDNN handle from a thread_local destructor, where cudnnDestroy returns CUDNN_STATUS_INTERNAL_ERROR (4000) and CHECK_CUDNN_ERROR throws from a noexcept destructor, terminating the process with 0xC0000409. Upstream PR: [CUDA] clear cuDNN handles and graph caches on clear_streams ml-explore/mlx#4892.
  • Desktop startup: generate a mlx.cmd launcher on Windows, invoke it through ComSpec, and allow a longer cold delegate probe.
  • DFlash2: automatic companion verification stays on Metal hosts; non-Darwin hosts skip auto-discovery while keeping explicit draft validation.
  • Model switching: the previous resident is disposed and awaited before the next model loads, preserving aliases and in-flight leases.
  • WASAPI: real Windows audio-device discovery (input + render) with stable endpoint IDs, defaults, formats, and hot-plug error handling.
  • Build hygiene: macOS/unix-only helpers are scoped to their platform while remaining available to tests; test-lane paths are normalized on Windows.

Validation

  • Three default models (Qwen3.8-27B, Qwen-AgentWorld-35B-A3B, Gemma-4-26B-A4B) pass two rounds of authenticated /v1/models + /v1/messages requests through the real Electron app, including sequential model switches; every answer is 4 with end_turn and the sidecar stays alive.
  • Qwen3.8 inference followed by session.dispose() and model.dispose() exits 0 with no cudnnDestroy exception.
  • qwen3AsrInputDevices() / qwen3AsrAudioDevices() enumerate the real Cirrus Logic microphone array (48 kHz, 3 ch) and speakers (48 kHz, 2 ch) on this device.
  • cargo check -p mlx-core --release --target aarch64-pc-windows-msvc: 0 errors, 0 warnings.
  • tsc -b succeeds; 78 focused TypeScript tests pass.
  • pre-commit run --all-files passes for the MLX submodule change.

Known limits

  • CUDA remains an inference-only preview; paged-attention stays forced off. A CUDA paged-attention backend, full WASAPI streaming capture, and the Windows SSD disk tier are deliberately out of scope.
  • The same thread-local cuDNN destroy returns success under WSL2 on this machine; the failure is specific to native Windows thread teardown.

AI assistance: Grok Build (Kimi K3.1 Pro).

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ab854e77-1320-4ca8-a091-61823455cde2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T15:34:55.305735Z 846a6d2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

codex and others added 10 commits November 16, 2026 12:49
The gitlink moves from 6fe39a2b to 2bda9817, keeping the existing patch stack and adding the cuDNN handle release.
Generate a .cmd launcher, run it through ComSpec, preserve environment overrides, and allow the cold delegate probe up to 60s on Windows.
…ead exit

Use NVRTC-native integer types in kquant.cu.inc, expose mlx_clear_streams through the bridge, and call it on the model thread before Windows thread teardown.
Automatic DFlash2 verification uses the Metal-only fused GDN kernel. Skip companion auto-discovery off Darwin while retaining explicit draft validation.
Model swap now unregisters with dispose and waits for tracked disposals, preserving aliases and in-flight leases while preventing old native threads from overlapping the next load.
Compare discovered test files using forward slashes so serial-lane matching works on Windows.
Implement native endpoint discovery for input and render devices on Windows, including stable IDs, defaults, formats, and hot-plug error handling. Share the portable capture ring/worker with Windows and scope its producer methods to the platforms that use them.
Gate paged-attention validators, tracing imports, disk-tier unix helpers, and GGUF mincore sampling to macOS/unix while keeping them available to tests. These paths have no Windows consumer until a CUDA paged-attention backend exists.
Documents the inventory-and-implement workflow used to separate real Windows feature gaps from macOS-only paths.
@Brooooooklyn
Brooooooklyn force-pushed the codex/windows-cuda-gguf branch from 846a6d2 to d0131aa Compare November 16, 2026 05:11
Positioned reads use seek_read on Windows, GgufTensorType is imported unconditionally for release tests, and cold-tier/paged/ASR test helpers are gated to unix or macOS. Apply rustfmt to the WASAPI sources.
Add Windows prebuilt export/consumption with PowerShell hashing and per-target pinning, a windows-11-arm prebuilt job, and unsigned Windows ARM64 ZIP packaging with staged CUDA/cuDNN/OpenBLAS runtime files and release validation. macOS flow is unchanged.
Unindented here-string content terminated the YAML block scalar and made the workflow file invalid. Indent the release notes and pin snippet so the file parses.
cuda_13.4.2_windows_arm64_network.exe returns 404; the full installer cuda_13.4.2_windows_arm64.exe exists. Apply rustfmt to disk_tier.rs and build.rs.
Get-FileHash is available in pwsh on both the windows-11-arm runner and local machines; the powershell invocation failed on the runner.
read_exact_at needs std::os::unix::fs::FileExt in scope on macOS/Linux; the Windows seek_read branch keeps its own import.
ReleaseCapture is a command the model thread sends to the worker. Emitting it from the worker on exit left a command queued in the native-start and prepare-failure tests.
The worker releases its capture on exit, which is expected. assert_no_command now ignores that notification instead of treating it as an unexpected command, while ReleaseCapture stays constructed.
assert_no_command now accepts Disconnected as well as Empty: the capture worker closing its channel on exit is expected, not a queued command.
@Brooooooklyn
Brooooooklyn force-pushed the codex/windows-cuda-gguf branch from ae0688a to e0416ae Compare November 17, 2026 05:40
@Brooooooklyn
Brooooooklyn merged commit 2614bf6 into main Nov 17, 2026
10 checks passed
@Brooooooklyn
Brooooooklyn deleted the codex/windows-cuda-gguf branch November 17, 2026 11:03
Brooooooklyn added a commit that referenced this pull request Nov 20, 2026
…anes), Flash Next partial-store decode, app wait states (#389)

## Summary

Deep-context speed for Qwen3.5 / 3.8 dense with a DFlash2 draft, real
concurrency for DFlash2 turns, Flash Next decode on a partial store, and
the app changes that go with them.

| Area | What changed |
|---|---|
| Key pages | Dense Qwen3.5 (heads 24/4) stores K on 32-token pages,
token-major, with their own prefill, verify and AR kernels. MoE keeps
the 16-token page. |
| Store move | The first load after this change moves stored chats from
the 16-token page form to the new one. It runs inside the load, before
the first turn, and is safe to cut: the next load goes on. |
| DFlash2 lanes | Dense DFlash2 text turns are scheduler lanes and
verify in waves of 2-4. Sampled lanes take their rows on the device. A
lane gives the tokens it gives alone. |
| Decode cycle | int8 KV queries for loads with a DFlash2 draft, a
joined mixed projection, sampled DFlash2 rows on the device. |
| GGUF planes | A GGUF load can plan Splash's weight-plane layout
(kernels under `metal/splash_gguf`, Apache-2.0, listed in
`THIRD_PARTY_NOTICES`). |
| Flash Next | A partial store reads every missing expert of a lease in
one fill; a store the host gate refused moves up to a direct store when
the gate later admits it; a switch to a model that loads alone disposes
the idle old model first. |
| Host / app | Chat and Work wait states, run cards, context ring,
compaction mark, composer hints; turn and runtime trace fields; model
switch disposal merged with #385. |
| Docs | `CLAUDE.md` limits, `docs/concurrent-inference.md`,
`docs/paged-cache.md`, `docs/perf.md`, `docs/ffi-cpp.md`,
`docs/qwen38-flash-next.md`, `docs/dashboard.md`. |

## Measured (M5 Max, 128 GB, Qwen3.8-27B UD-Q4_K_XL + DFlash2 draft, one
trial per row)

| Row at 146K context | Before key pages | This PR | Splash 1.6.1
(stored rows, no same-hold pair) |
|---|---|---|---|
| Decode, sampled, ms per cycle | 84.9 | 74.6 | 73.6 |
| Decode, greedy, ms per cycle | 79.8 | 72.7 | 73.2 |
| Cold 146K prompt | 317 s (16-token page) | 292 s | 312 s |

The clock speed of the GPU differed between rows, so the Splash column
is an indication only.

Two no-harm cells at 25K (greedy alone, 3 lanes) read slower in one
engine while another project compiled on the machine. They have no clean
pair and are **not decided**. The other 25K cells in the same hold read
0.96-0.98 of the old build.

## Exactness

- Same request, same state: same tokens (10 of 10 greedy repeats).
- A DFlash2 lane equals the same request alone (23 of 23 on the real
model; fixture pins for sampled lanes with a fixed seed).
- A restored chat equals the chat with no restore, also after the store
move, a restart, and three kills inside a move.

## Limits

- **Downgrade:** a build without 32-token pages does not read moved
chats; they prefill again.
- **First load after the update:** longer by one read and one write of
the stored chats (24 GB took about 58 s). The UI shows a plain load.
- **AR rows in one fused step are not lane-exact:** on a dense load with
K-quant or affine projections, autoregressive turns that decode in one
`[N,1]` step take other kernels than a one-row step, so at temperature 0
such a turn can give other tokens than it gives alone. The route split
is in `main` already; the docs said the opposite and now state the
limit. DFlash2 lanes are not on this route.
- **Not proven:** Windows and Linux compiles of the new unix-gated code
(checked by reading only; CI decides).

## Test plan

- [x] `cargo fmt --check`, `cargo clippy --all --all-targets -D
warnings`: clean
- [x] `cargo test -p mlx-core` lib: 5,552 passed, 0 failed, 245 ignored;
integration: 161 passed, 0 failed
- [x] `cargo test -p mlx-paged-attn`: 370 passed, 0 failed
- [x] `vp run test`: 8,214 passed, 0 failed
- [x] `vp check --no-fmt`, `vp fmt --check` on the changed files: pass
- [x] `yarn build:native`, `yarn build:ts`; the two `index.d.cts` files
are equal
- [x] Real-model holds: store move on a clone of a live 24 GB store (81
of 81 states), kills inside the move, restore after restart, lanes equal
alone
- [ ] CI

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <[email protected]>
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