Skip to content

[executorch][native-ggml] Size the scheduler hash for graph leafs too - #24847

Merged
meta-codesync[bot] merged 1 commit into
gh/SS-JIA/703/basefrom
gh/SS-JIA/703/head
Nov 12, 2026
Merged

meta-codesync[bot] merged 1 commit into
gh/SS-JIA/703/basefrom
gh/SS-JIA/703/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

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

[ghstack-poisoned]
@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/24847

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

✅ You can merge normally! (4 Unrelated Failures)

As of commit 21d5db4 with merge base 4529a94 (image):

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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
meta-codesync Bot merged commit 9cbdc0f into gh/SS-JIA/703/base Nov 12, 2026
@meta-codesync
meta-codesync Bot deleted the gh/SS-JIA/703/head branch November 12, 2026 19:14
SS-JIA added a commit that referenced this pull request Nov 12, 2026
## 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](https://our.internmc.facebook.com/intern/diff/D130721991/)


ghstack-source-id: 469829014
Pull-Request: #24847
SS-JIA added a commit that referenced this pull request Nov 12, 2026
## 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](https://our.internmc.facebook.com/intern/diff/D130721991/)


ghstack-source-id: 469829014
Pull-Request: #24847

This branch was previously deployed

2 inactive deployments
cherry-pick-bot — 21d5db4e Deployed Nov 12, 2026 by meta-codesync[bot]
cadence — 21d5db4e Deployed Nov 10, 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