Skip to content

llama-quant : honor --tensor-type override when it matches the global ftype#22559

Closed
Anai-Guo wants to merge 1 commit into
ggml-org:masterfrom
Anai-Guo:fix-tensor-type-override-22544
Closed

llama-quant : honor --tensor-type override when it matches the global ftype#22559
Anai-Guo wants to merge 1 commit into
ggml-org:masterfrom
Anai-Guo:fix-tensor-type-override-22544

Conversation

@Anai-Guo

Copy link
Copy Markdown

Summary

Fixes #22544.

When a user supplies an explicit --tensor-type "<pattern>=<type>" mapping that happens to match the requested global ftype, the user's intent (lock that tensor to that exact type) is silently dropped and the imatrix/heuristic path is allowed to override it.

Root cause

llama_tensor_get_type only set manual = true from inside the qtype != new_type branch:

for (const auto & [pattern, qtype] : qs.tensor_type_patterns) {
    if (std::regex_search(tensor_name, pattern)) {
        if (qtype != new_type) {
            LLAMA_LOG_WARN(...);
            new_type = qtype;
            manual = true;
            break;
        }
        // pattern matched but qtype == new_type:
        //   no break, no manual = true
        //   loop continues, manual stays false
    }
}

// since !manual:
new_type = llama_tensor_get_type_impl(...);  // overrides the user's choice

So invoking llama-quantize with --tensor-type "^blk\.0\.attn_qkv\.weight$=iq4_xs" and global ftype iq4_xs falls through to the heuristic, which can pick a different type (e.g. q5_K) — exactly what --tensor-type is meant to prevent.

This was introduced by 1dab5f5 (refactor type selection), reported in #22544.

Fix

Set manual = true and break unconditionally once a pattern matches. Only emit the "applying manual override" log line when the requested type actually differs from the current one:

if (std::regex_search(tensor_name, pattern)) {
    if (qtype != new_type) {
        LLAMA_LOG_WARN(...);
        new_type = qtype;
    }
    manual = true;
    break;
}

A pattern match is the user pinning that tensor — it should suppress the heuristic regardless of whether it changes the type.

Test plan

  • ./llama-quantize --imatrix model.imatrix.gguf --tensor-type "^blk\.0\.attn_qkv\.weight$=iq4_xs" model.gguf out.gguf iq4_xs 8attn_qkv should now be reported as iq4_xs (no longer redirected to q5_K).
  • Existing override case (qtype != new_type) still emits the log line and switches type.
  • No regressions when --tensor-type is not supplied (tensor_type_patterns.empty() → unchanged path).

🤖 Generated with Claude Code

…hes the global type (#22544)

Fixes #22544.

When a user supplies an explicit `--tensor-type` mapping that happens to
match the requested global ftype, the previous code only set
`manual = true` inside the `qtype != new_type` branch, so it was never
flipped on the equal-type case. Control then fell through to
`llama_tensor_get_type_impl`, which is free to override the user's
choice via imatrix/heuristics — exactly what `--tensor-type` is meant
to suppress.

Set `manual = true` and break out of the pattern loop unconditionally
once a pattern matches; only emit the override log line when the
requested type actually differs from the current one.
@Anai-Guo Anai-Guo requested a review from ggerganov as a code owner April 30, 2026 16:23
@ggml-gh-bot

ggml-gh-bot Bot commented Apr 30, 2026

Copy link
Copy Markdown

Hi @Anai-Guo, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • Multiple open PRs from a new contributor: We limit new contributors (those without a previously merged PR) to 1 open PR at a time. You currently have 2 open PRs.

  • AI-generated content: This project does not accept PRs, descriptions or commit messages that are fully or predominantly AI-generated. If you have used AI to assist you in writing code, please make sure to disclose that explicitly.


Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@Anai-Guo

Copy link
Copy Markdown
Author

Apologies — I missed the new-contributor 1-open-PR limit and the AI-disclosure policy. Closing this in favor of my older open PR (#21838). I'll wait for that one to land before opening anything else here. Thanks for the patience.

@ddh0

ddh0 commented May 1, 2026

Copy link
Copy Markdown
Contributor

Hi @Anai-Guo, since you had to close this one, I took the liberty of submitting the fix here: #22572

Thank you! I'm sorry for introducing this mistake.

pwilkin pushed a commit that referenced this pull request May 1, 2026
…22572)

fix #22544 (my fault!)

Credit to @Anai-Guo, ref #22559 - since that one was closed due to the
new contributor policy I am taking the liberty of re-submitting that PR
here.
samuraieng pushed a commit to samuraieng/llama.cpp that referenced this pull request May 6, 2026
…gml-org#22572)

fix ggml-org#22544 (my fault!)

Credit to @Anai-Guo, ref ggml-org#22559 - since that one was closed due to the
new contributor policy I am taking the liberty of re-submitting that PR
here.
ljubomirj pushed a commit to ljubomirj/llama.cpp that referenced this pull request May 6, 2026
…gml-org#22572)

fix ggml-org#22544 (my fault!)

Credit to @Anai-Guo, ref ggml-org#22559 - since that one was closed due to the
new contributor policy I am taking the liberty of re-submitting that PR
here.
meh pushed a commit to meh/llama.cpp that referenced this pull request May 10, 2026
…gml-org#22572)

fix ggml-org#22544 (my fault!)

Credit to @Anai-Guo, ref ggml-org#22559 - since that one was closed due to the
new contributor policy I am taking the liberty of re-submitting that PR
here.
baramofme pushed a commit to baramofme/llama-cpp-turboquant that referenced this pull request May 23, 2026
…gml-org#22572)

fix ggml-org#22544 (my fault!)

Credit to @Anai-Guo, ref ggml-org#22559 - since that one was closed due to the
new contributor policy I am taking the liberty of re-submitting that PR
here.

(cherry picked from commit b97ebdc)
carlosfundora pushed a commit to carlosfundora/llama.cpp-1-bit-turbo that referenced this pull request May 24, 2026
…gml-org#22572)

fix ggml-org#22544 (my fault!)

Credit to @Anai-Guo, ref ggml-org#22559 - since that one was closed due to the
new contributor policy I am taking the liberty of re-submitting that PR
here.

(cherry picked from commit b97ebdc)
winstonma pushed a commit to winstonma/llama.cpp that referenced this pull request May 27, 2026
…gml-org#22572)

fix ggml-org#22544 (my fault!)

Credit to @Anai-Guo, ref ggml-org#22559 - since that one was closed due to the
new contributor policy I am taking the liberty of re-submitting that PR
here.
fewtarius pushed a commit to fewtarius/CachyLLama that referenced this pull request May 30, 2026
…gml-org#22572)

fix ggml-org#22544 (my fault!)

Credit to @Anai-Guo, ref ggml-org#22559 - since that one was closed due to the
new contributor policy I am taking the liberty of re-submitting that PR
here.
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.

Misc. bug: Regression: --tensor-type is ignored when it matches the global quantization type (commit 1dab5f5)

2 participants