Skip to content

[executorch][native-ggml] Enable CUDA graphs in CMake builds - #24849

Closed
SS-JIA wants to merge 2 commits into
gh/SS-JIA/705/basefrom
gh/SS-JIA/705/head
Closed

SS-JIA wants to merge 2 commits into
gh/SS-JIA/705/basefrom
gh/SS-JIA/705/head

Conversation

@SS-JIA

@SS-JIA SS-JIA commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Ulterior Motive

Closing the decode gap between ExecuTorch Native's GGML engine and llama.cpp on CUDA, measured with Gemma 4 31B Q4_K_M on an A100.

Rationale

What: The GGML engine's CMake turns ggml's GGML_CUDA_GRAPHS option on unless the user sets it.

Why: ggml defaults the option to off and llama.cpp's own CMake turns it on. The engine adds ggml as a subdirectory, so its CMake CUDA builds launched each kernel of a decode step separately: about 1,900 launches per Gemma 4 31B step, which cost 2.2–2.5 ms of a ~26 ms step.

Details

  • Before: GGML_CUDA_GRAPHS off unless set; ggml-cuda never captured or replayed CUDA graphs.
  • After: on unless set, as in llama.cpp's CMake; -DGGML_CUDA_GRAPHS=OFF still turns it off.

Buck builds already compile ggml-cuda with CUDA graphs.

Authored with Claude Code.

Differential Revision: D130721993

[ghstack-poisoned]
@SS-JIA
SS-JIA requested a review from larryliu0820 as a code owner November 10, 2026 18:17
@pytorch-bot

pytorch-bot Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24849

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit 6cc2ca8 with merge base 6aebee6 (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@digantdesai digantdesai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

meta-codesync Bot pushed a commit that referenced this pull request Nov 12, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0) (oldest at bottom):
* #24849
* #24848
* #24847
* #24846
* __->__ #24845

## Ulterior Motive

Running Muse Glimmer 30B through ExecuTorch Native's GGML engine. Its llama.cpp Q4_K_M checkpoint stores the LM head (`output.weight`) as q5_k.

## Rationale

**What**: The GGML engine maps `gguf:q5_k` packed weights to `GGML_TYPE_Q5_K`.

**Why**: The engine accepted only q4_k and q6_k, so the 30B package failed to load. The exporter already serializes any GGUF k-quant as `gguf:<type>`, and ggml implements Q5_K on every backend.

## Details

- Codec lookup
  - **Before**: q4_k and q6_k checks with hard-coded block sizes, repeated for size computation and type selection.
  - **After**: one `kquant_type()` lookup serves both; block bytes come from `ggml_type_size`.
- `test_gguf_q5_k_linear` checks a q5_k linear against eager, sharing the q6_k test's body.

Authored with Claude Code.

Differential Revision: D130721989

Pull Request resolved: #24845
meta-codesync Bot pushed a commit that referenced this pull request Nov 12, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0) (oldest at bottom):
* #24849
* #24848
* #24847
* __->__ #24846
* #24845

## Ulterior Motive

Running Gemma 4 31B through ExecuTorch Native's GGML engine on CUDA, to find why it decodes slower than llama.cpp on the same GGUF.

## Rationale

**What**: A zero entry in a `native::rope` `inv_freq` table now leaves its pair of dims unrotated.

**Why**: Gemma 4's partial RoPE writes the dims it does not rotate as zero inverse frequencies, and the engine rejected such tables at load with `ggml: rope inv_freq has a zero entry`.

## Details

The engine passes `ggml_rope_ext` the factors `1 / inv_freq` with a frequency base of 1, so `theta = pos / factor`.

- **Before**: a zero `inv_freq` threw at load.
- **After**: its factor is infinite, so `theta = 0`: cos 1, sin 0, and the dims pass through unchanged, as in eager PyTorch.

`test_rope_zero_frequency_leaves_dims_unrotated` zeroes the upper half of a Llama RoPE's `inv_freq`.

Authored with Claude Code.

Differential Revision: D130721990

Pull Request resolved: #24846
meta-codesync Bot pushed a commit that referenced this pull request Nov 12, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0) (oldest at bottom):
* #24849
* #24848
* __->__ #24847
* #24846
* #24845

## Ulterior Motive

Running Gemma 4 31B through ExecuTorch Native's GGML engine on CUDA, to find why it decodes slower than llama.cpp on the same GGUF.

## Rationale

**What**: The backend scheduler is created for `2 * graph_size` tensors.

**Why**: `ggml_backend_sched` hashes every node and every leaf of a graph it splits, and asserts that its hash set holds them all. It was sized for `graph_size`, which caps nodes and leafs separately, so a graph whose nodes and leafs together outgrew it failed that assertion, though either count alone fit.

## Details

- **Before**: `ggml_backend_sched_new(..., graph_size, ...)`; ggml's own source notes the hash "needs to be size*2 to account for leafs".
- **After**: `2 * graph_size`, room for a full graph of `graph_size` nodes and `graph_size` leafs.

`test_graph_with_as_many_leafs_as_nodes` adds 2,100 separate constants to an input: 2,100 nodes and as many leafs, within the default graph size of 4,096.

Authored with Claude Code.

Differential Revision: D130721991

Pull Request resolved: #24847
SS-JIA added a commit that referenced this pull request Nov 12, 2026
## Ulterior Motive

Closing the decode gap between ExecuTorch Native's GGML engine and llama.cpp on CUDA, measured with Gemma 4 31B Q4_K_M on an A100.

## Rationale

**What**: The GGML engine's CMake turns ggml's `GGML_CUDA_GRAPHS` option on unless the user sets it.

**Why**: ggml defaults the option to off and llama.cpp's own CMake turns it on. The engine adds ggml as a subdirectory, so its CMake CUDA builds launched each kernel of a decode step separately: about 1,900 launches per Gemma 4 31B step, which cost 2.2–2.5 ms of a ~26 ms step.

## Details

- **Before**: `GGML_CUDA_GRAPHS` off unless set; ggml-cuda never captured or replayed CUDA graphs.
- **After**: on unless set, as in llama.cpp's CMake; `-DGGML_CUDA_GRAPHS=OFF` still turns it off.

Buck builds already compile ggml-cuda with CUDA graphs.

Authored with Claude Code.

Differential Revision: [D130721993](https://our.internmc.facebook.com/intern/diff/D130721993/)


ghstack-source-id: 469829038
Pull-Request: #24849
[ghstack-poisoned]

This branch had an error being deployed

1 failed and 1 inactive deployments
cherry-pick-bot — 6cc2ca82 Deployed Nov 18, 2026 by SS-JIA
cadence — 6cc2ca82 Deployed Nov 17, 2026 by SS-JIA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants