Skip to content

[0.23.x] Use the persistent threadpool for llama.cpp CPU loads - #2443

Merged
leehack merged 1 commit into
release/0.23.xfrom
backport/0.23-2394-cpu-device-list
Nov 29, 2026
Merged

leehack merged 1 commit into
release/0.23.xfrom
backport/0.23-2394-cpu-device-list

Conversation

@leehack

@leehack leehack commented Nov 29, 2026

Copy link
Copy Markdown
Owner

Summary

Backport of #2394
(cherry picked from commit 672518b)

Changelog

  • [core] Run llama.cpp CPU loads, including the automatic CPU fallback on refused Android Vulkan drivers, on the persistent CPU threadpool: the load no longer lists the CPU device, which made llama.cpp compute on a second CPU backend with a per-compute pool.

Production-readiness scope

  • User-facing scope Native llama.cpp CPU inference uses the existing persistent pool on runtimes that provide it.
  • Supported platforms/paths Native llama.cpp explicit CPU, CPU fallback, and speculative draft loads. The fix uses the pinned runtime and the existing native pool API.
  • Unsupported or intentionally unavailable paths CPU row split still throws LlamaUnsupportedException and points to layer mode. The native runtime's existing no-pool path remains available when the attach export or pool is unavailable.
  • Out of scope / follow-ups Physical-device throughput and the 0.23.x backport are tracked by the coordinator under 0.23.x patch plan: Android threadpool, PowerVR refusal, fd-load fixes #2390.

Completeness checklist

  • Implemented the CPU routing scope.
  • Preserved the documented CPU row-split error and successful CPU tensor-requested load.
  • Updated the runtime guide, support matrix, and PR changelog. README, examples, and package skills are N/A because the public API and setup are unchanged.
  • Covered the original native log and wire values, row/tensor compatibility, and the existing GPU registry fallback.
  • Validation coverage registry is N/A because this restores an existing capability.
  • Reviewed log, error, and cache-key changes for secret exposure. The native log capture is confined to a generated test fixture.
  • Patch sequencing is tracked in 0.23.x patch plan: Android threadpool, PowerVR refusal, fd-load fixes #2390.

PR type guidance

  • Bugfix A listed CPU creates a second CPU backend. The scheduler computes there while the attached pool belongs to llama.cpp's built-in CPU backend. The production load and wire assertions detect the extra CPU device.

Test Plan

  • dart run tool/prepare_workspace.dart
  • python3 tool/ci/check_format.py, dart analyze, and dart run tool/testing/check_platform_boundaries.dart
  • dart test -p vm -j 1 --exclude-tags local-only passed in the local coverage run and in PR CI.
  • Chrome shards passed in PR CI. Local browser validation is N/A for native routing.
  • coverage-lib passed with 93.84% line coverage (37,934 of 40,426 lines).
  • Docs-site build and focused native CPU, row-split and tensor-split regressions. The full llama.cpp VM directory passed on macOS (1,915 passed, 7 skipped) and Linux arm64 at the final head (1,911 passed, 8 skipped). The registry fixture also passed with an invalid Vulkan ICD.

Matrix Evidence

Matrix row Scope covered Platform / model / backend Result Evidence / notes
static-format-analyze format, analyzer, web/native import boundaries macOS arm64, Flutter 3.47.1 PASS Workspace preparation and all three checks passed.
root-vm native-safe unit/integration coverage on the Dart VM macOS arm64 and Linux arm64, synthetic Llama GGUF, pinned llama.cpp PASS Local root VM run had 16,642 passes and 136 skips. Full backend unit suites passed on macOS and Linux arm64, and native CI passed on the final head.
root-chrome browser-compatible unit/integration coverage Chrome on GitHub Actions PASS (CI) All three Chrome shards passed.
coverage-lib 70% lib/ line threshold macOS arm64 PASS 93.84% (37,934 of 40,426 lines).
gguf-chat-features-smoke real GGUF chat, thinking and tool calls macOS arm64, Qwen3.5-0.8B-Q4_K_M, CPU PASS CPU reported for all cases. The native info log contained metadata and no using device CPU line.
docs-site site build and generated links macOS arm64 PASS ./tool/docs/build_site.sh
high-risk-exact-head-independent-qa independent review of the exact head and base native llama.cpp Pass Independent auditor-deep review of 563a86f against e95e5c7: no blocking findings; targeted tests and three mutations re-run independently.

Review Notes

  • Independent review completed at 563a86f: no blocking findings.
  • CI passed at 563a86f30e990b85b6e7daf53e1bf7b1ed8e97f9. The first head's Linux VM shard found a host Vulkan dependency in the simulated Windows registry tests. The fixture now uses a simulated CUDA device and passes under an invalid Vulkan ICD.

High-risk regression review

  • Classification high-risk (backendRuntime)
  • Implementation task Fix CPU loads listing the CPU device
  • Independent blocking QA task Completed at 563a86f: no blocking findings.
  • Exact head / current base 563a86f30e990b85b6e7daf53e1bf7b1ed8e97f9 / e95e5c7f8213622f6e5ebe9805ed4fee8068585d
  • Production-branch deletion, bypass, or miswire proof On the base loader the real synthetic GGUF test captured llama_prepare_model_devices: using device CPU and the three original wire assertions saw a single address. Restoring return [cpuDev] on Linux failed the five wire cases (refused Android Vulkan, iOS simulator, macOS Intel, memory-fit fallback, and CPU draft) and the native log test. The seven-case filtered command passed with the fixed list. The tensor CPU model load passed on the base and fixed loader. The existing row-split rejection test is unchanged.
  • Affected-family real-model/artifact evidence The pinned llamadart-native v1.1.0-2 bundle loads the synthetic Llama GGUF and the affected Qwen3.5-0.8B-Q4_K_M family on desktop CPU. The Qwen GGUF SHA-256 is bd258782e35f7f458f8aced1adc053e6e92e89bc735ba3be89d38a06121dc517. Both native logs include the metadata positive control without an extra CPU device line on the fixed load.
  • Explicit unavailable-family or other N/A evidence No phone runs in this implementation task. The fixture validates CPU device selection and does not establish Pixel or Studio throughput.
  • Known PR-caused P1 regressions 0 identified in implementation testing. Independent audit: 0 blocking findings.
  • Unresolved review threads 0 at the final GitHub check.

…vice (#2394)

## Summary

- Follow up on #2393. Pass an explicitly empty llama.cpp device list for
CPU loads so decode uses the backend that owns the persistent
threadpool. This covers explicit CPU selection, forced CPU fallback,
refused Android Vulkan drivers, GPU-memory-fit fallback, and CPU drafts.
- Keep the CPU row-split rejection and use layer mode for CPU loads
requested with tensor split, which need a model device in upstream
tensor mode.
- Backport after #2393 in the 0.23.x patch plan (#2390).

## Changelog

- [core] Run llama.cpp CPU loads, including the automatic CPU fallback
on refused Android Vulkan drivers, on the persistent CPU threadpool: the
load no longer lists the CPU device, which made llama.cpp compute on a
second CPU backend with a per-compute pool.

## Production-readiness scope

- **User-facing scope** Native llama.cpp CPU inference uses the existing
persistent pool on runtimes that provide it.
- **Supported platforms/paths** Native llama.cpp explicit CPU, CPU
fallback, and speculative draft loads. The fix uses the pinned runtime
and the existing native pool API.
- **Unsupported or intentionally unavailable paths** CPU row split still
throws `LlamaUnsupportedException` and points to layer mode. The native
runtime's existing no-pool path remains available when the attach export
or pool is unavailable.
- **Out of scope / follow-ups** Physical-device throughput and the
0.23.x backport are tracked by the coordinator under #2390.

## Completeness checklist

- [x] Implemented the CPU routing scope.
- [x] Preserved the documented CPU row-split error and successful CPU
tensor-requested load.
- [x] Updated the runtime guide, support matrix, and PR changelog.
README, examples, and package skills are N/A because the public API and
setup are unchanged.
- [x] Covered the original native log and wire values, row/tensor
compatibility, and the existing GPU registry fallback.
- [x] Validation coverage registry is N/A because this restores an
existing capability.
- [x] Reviewed log, error, and cache-key changes for secret exposure.
The native log capture is confined to a generated test fixture.
- [x] Patch sequencing is tracked in #2390.

## PR type guidance

- **Bugfix** A listed CPU creates a second CPU backend. The scheduler
computes there while the attached pool belongs to llama.cpp's built-in
CPU backend. The production load and wire assertions detect the extra
CPU device.

## Test Plan

- [x] `dart run tool/prepare_workspace.dart`
- [x] `python3 tool/ci/check_format.py`, `dart analyze`, and `dart run
tool/testing/check_platform_boundaries.dart`
- [x] `dart test -p vm -j 1 --exclude-tags local-only` passed in the
local coverage run and in PR CI.
- [x] Chrome shards passed in PR CI. Local browser validation is N/A for
native routing.
- [x] `coverage-lib` passed with 93.84% line coverage (37,934 of 40,426
lines).
- [x] Docs-site build and focused native CPU, row-split and tensor-split
regressions. The full llama.cpp VM directory passed on macOS (1,915
passed, 7 skipped) and Linux arm64 at the final head (1,911 passed, 8
skipped). The registry fixture also passed with an invalid Vulkan ICD.

## Matrix Evidence

| Matrix row | Scope covered | Platform / model / backend | Result |
Evidence / notes |
| --- | --- | --- | --- | --- |
| `static-format-analyze` | format, analyzer, web/native import
boundaries | macOS arm64, Flutter 3.47.1 | PASS | Workspace preparation
and all three checks passed. |
| `root-vm` | native-safe unit/integration coverage on the Dart VM |
macOS arm64 and Linux arm64, synthetic Llama GGUF, pinned llama.cpp |
PASS | Local root VM run had 16,642 passes and 136 skips. Full backend
unit suites passed on macOS and Linux arm64, and native CI passed on the
final head. |
| `root-chrome` | browser-compatible unit/integration coverage | Chrome
on GitHub Actions | PASS (CI) | All three Chrome shards passed. |
| `coverage-lib` | 70% lib/ line threshold | macOS arm64 | PASS | 93.84%
(37,934 of 40,426 lines). |
| `gguf-chat-features-smoke` | real GGUF chat, thinking and tool calls |
macOS arm64, Qwen3.5-0.8B-Q4_K_M, CPU | PASS | CPU reported for all
cases. The native info log contained metadata and no `using device CPU`
line. |
| `docs-site` | site build and generated links | macOS arm64 | PASS |
`./tool/docs/build_site.sh` |
| `high-risk-exact-head-independent-qa` | independent review of the
exact head and base | native llama.cpp | Pass | Independent auditor-deep
review of 563a86f against e95e5c7: no blocking findings; targeted
tests and three mutations re-run independently. |

## Review Notes

- Independent review completed at 563a86f: no blocking findings.
- CI passed at `563a86f30e990b85b6e7daf53e1bf7b1ed8e97f9`. The first
head's Linux VM shard found a host Vulkan dependency in the simulated
Windows registry tests. The fixture now uses a simulated CUDA device and
passes under an invalid Vulkan ICD.

## High-risk regression review

- **Classification** high-risk (`backendRuntime`)
- **Implementation task** Fix CPU loads listing the CPU device
- **Independent blocking QA task** Completed at 563a86f: no blocking
findings.
- **Exact head / current base**
`563a86f30e990b85b6e7daf53e1bf7b1ed8e97f9` /
`e95e5c7f8213622f6e5ebe9805ed4fee8068585d`
- **Production-branch deletion, bypass, or miswire proof** On the base
loader the real synthetic GGUF test captured
`llama_prepare_model_devices: using device CPU` and the three original
wire assertions saw a single address. Restoring `return [cpuDev]` on
Linux failed the five wire cases (refused Android Vulkan, iOS simulator,
macOS Intel, memory-fit fallback, and CPU draft) and the native log
test. The seven-case filtered command passed with the fixed list. The
tensor CPU model load passed on the base and fixed loader. The existing
row-split rejection test is unchanged.
- **Affected-family real-model/artifact evidence** The pinned
`llamadart-native v1.1.0-2` bundle loads the synthetic Llama GGUF and
the affected Qwen3.5-0.8B-Q4_K_M family on desktop CPU. The Qwen GGUF
SHA-256 is
`bd258782e35f7f458f8aced1adc053e6e92e89bc735ba3be89d38a06121dc517`. Both
native logs include the metadata positive control without an extra CPU
device line on the fixed load.
- **Explicit unavailable-family or other N/A evidence** No phone runs in
this implementation task. The fixture validates CPU device selection and
does not establish Pixel or Studio throughput.
- **Known PR-caused P1 regressions** 0 identified in implementation
testing. Independent audit: 0 blocking findings.
- **Unresolved review threads** 0 at the final GitHub check.

(cherry picked from commit 672518b)
@leehack

leehack commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

Delta audit: backport #2443 (exact cherry-pick of #2394)

Verdict: PASS, 0 PR-caused P1/P2 regressions vs release base. Exact high-risk backport, delta audit per doc/high_risk_pre_merge_readiness.md.

Item Evidence
PR head / base 319f418cebade89acde930de94904fa73ce3ed8e / 039aae47b442df09135c1b289db5e6ff4df394bb (includes #2442, #2434)
Main source 672518b06e03369228c5b7c535eb8b6f0456b421 (#2394)
patch-id (--stable) e8056c82165424315d1a1bfa923d91909643e28c for both; range-diff differs only by the cherry-pick trailer; no drift on the 10 touched files
Classification high-risk, backendRuntime
Semantics CPU loads pass an empty NULL-terminated device list (no second CPU backend); CPU + tensor split loads in layer mode; CPU + row split still throws LlamaUnsupportedException before load; GPU/auto unchanged; v1.1.0-1 and -2 pin the same llama.cpp (1715275)
Tests on release tree (macOS arm64) test/unit/backends/llama_cpp/: 1915 passed, 5 skipped; the 5 PR files: 498 passed, 2 skipped
CI at head all required checks green
Mutations 3 of 4 killed (CPU device back in list, drop tensor-to-layer switch, empty list to null); survivor: cpuOnly probe bypass removal (test gap, same on main)
PR body Copy of #2394 plus the two provenance lines; valid ## Changelog

Auditor: independent Claude Opus 5.5 review agent, 2026-11-29.

@leehack
leehack marked this pull request as ready for review November 29, 2026 22:46
@leehack
leehack merged commit 8052a70 into release/0.23.x Nov 29, 2026
46 checks passed
@leehack
leehack deleted the backport/0.23-2394-cpu-device-list branch November 29, 2026 22:49
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.

1 participant