Skip to content

[executorch][native-ggml] Accept GGUF q5_k weights - #24845

Merged
meta-codesync[bot] merged 2 commits into
gh/SS-JIA/701/basefrom
gh/SS-JIA/701/head
Nov 12, 2026
Merged

meta-codesync[bot] merged 2 commits into
gh/SS-JIA/701/basefrom
gh/SS-JIA/701/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 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

[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/24845

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

⏳ No Failures, 2 Pending

As of commit 4f4df2c with merge base 0f6ba97 (image):
💚 Looks good so far! There are no failures yet. 💚

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.

@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.

[ghstack-poisoned]
SS-JIA added a commit that referenced this pull request Nov 12, 2026
Pull Request resolved: #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.
ghstack-source-id: 472029057
@exported-using-ghexport

Differential Revision: [D130721989](https://our.internmc.facebook.com/intern/diff/D130721989/)
@meta-codesync
meta-codesync Bot merged commit f5978b7 into gh/SS-JIA/701/base Nov 12, 2026
@meta-codesync
meta-codesync Bot deleted the gh/SS-JIA/701/head branch November 12, 2026 18:53
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
Pull Request resolved: #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.
ghstack-source-id: 472029057
@exported-using-ghexport

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

This branch was previously deployed

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