Skip to content

metal : fix graph capture and handle empty graphs - #29390

Merged
ggerganov merged 1 commit into
masterfrom
gg/metal-capture-fixes
Sep 24, 2026
Merged

ggerganov merged 1 commit into
masterfrom
gg/metal-capture-fixes

Conversation

@ggerganov

@ggerganov ggerganov commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Overview

Small fixes to the Metal graph capture path in ggml_metal_graph_compute:

  • Return GGML_STATUS_SUCCESS early when the graph has no nodes, avoiding the command-buffer/capture machinery for an empty graph.
  • Drop the redundant reset of ctx->capture_compute: the decrement at the top of the function already transitions the counter from 0 to -1, so a capture happens exactly once (whether or not the capture scope starts successfully).
  • Surface a did you set METAL_CAPTURE_ENABLED=1 ? hint in the capture error message.
  • Pass ctx->capture_compute == 0 (rather than the raw counter) as the use_capture argument to ggml_metal_op_init. The counter is a countdown, so any non-zero value (including -1 after the first compute) coerced to true and caused per-node GPU debug-group markers to be emitted on every compute instead of only on the captured one.

Requirements

@ggerganov
ggerganov force-pushed the gg/metal-capture-fixes branch from 5a92090 to ac0c117 Compare September 24, 2026 16:52
- return early when the graph has no nodes
- drop the redundant reset of capture_compute: the decrement at the top
  of the function already transitions the counter from 0 to -1, so a
  capture happens exactly once
- hint at METAL_CAPTURE_ENABLED=1 in the capture error message
- pass capture_compute == 0 (not the raw counter) as use_capture to
  ggml_metal_op_init, so GPU debug-group markers are only emitted on the
  captured compute

Assisted-by: pi:llama.cpp/Qwen3.8-27B
@ggerganov
ggerganov force-pushed the gg/metal-capture-fixes branch from ac0c117 to ca6b39a Compare September 24, 2026 16:53
@ggerganov
ggerganov marked this pull request as ready for review September 24, 2026 17:12
@ggerganov
ggerganov requested a review from a team as a code owner September 24, 2026 17:12
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning Apple Metal https://en.wikipedia.org/wiki/Metal_(API) labels Sep 24, 2026
@ggerganov
ggerganov merged commit 84e76d8 into master Sep 24, 2026
15 checks passed
@ggerganov
ggerganov deleted the gg/metal-capture-fixes branch September 25, 2026 06:14
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 7, 2026
- return early when the graph has no nodes
- drop the redundant reset of capture_compute: the decrement at the top
  of the function already transitions the counter from 0 to -1, so a
  capture happens exactly once
- hint at METAL_CAPTURE_ENABLED=1 in the capture error message
- pass capture_compute == 0 (not the raw counter) as use_capture to
  ggml_metal_op_init, so GPU debug-group markers are only emitted on the
  captured compute

Assisted-by: pi:llama.cpp/Qwen3.8-27B
(cherry picked from commit 84e76d8)
Achilles1089 added a commit to Achilles1089/llama.cpp that referenced this pull request Oct 15, 2026
…gml-org#29869 + ggml-org#30065, without their MUL_MAT+ADD fusion); stop accepting draft tokens at EOG (ggml-org#29638); graph capture flag fix (ggml-org#29390)

The 2..16-row mat-muls that MTP verify produces ran on mat-vec kernels whose time grows with every row. Measured on
the M1 Ultra with Raven's Qwen3.8-27B Q8_0 shapes: 8 rows now cost 1.6-1.9x one row (was 3.3-3.8x), matching
upstream within 1-3%. End to end (temp 1.0, 512 tokens): at --spec-draft-n-max 6 --spec-draft-n-min 1
--spec-draft-p-min 0.6, code echo 34.9 -> 54.7 tok/s and tool JSON 35.2 -> 54.9, prose level (25.6 -> 25.9).
Greedy output is identical to the previous build, with and without drafting. test-backend-ops MUL_MAT: 1163/1163.
The capture fix: the -1 capture counter was passed as a bool, so every node of every graph got debug-group markers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Apple Metal https://en.wikipedia.org/wiki/Metal_(API) ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant