Skip to content

quantize: add IQ2_NL and IQ3_NL types (CPU + Metal + CUDA + Vulkan) - #27983

Draft
EAddario wants to merge 70 commits into
ggml-org:masterfrom
EAddario:iq2_nl-iq3_nl-cpu+metal+cuda+vulkan
Draft

quantize: add IQ2_NL and IQ3_NL types (CPU + Metal + CUDA + Vulkan)#27983
EAddario wants to merge 70 commits into
ggml-org:masterfrom
EAddario:iq2_nl-iq3_nl-cpu+metal+cuda+vulkan

Conversation

@EAddario

Copy link
Copy Markdown
Contributor

Overview

K-quants and I-quants operate on 256-element super-blocks. A tensor can use them only if its row length (ncols) is an exact multiple of 256. When it isn't, the quantizer falls back to a different (usually sub-optimal) 32-element block type per tensor.

Mainline 32-block types stop at 4.50 bpw (Q4_0/IQ4_NL) creating a hard floor on every misaligned tensor and therefore on the whole file wherever misaligned tensors dominate because there is nothing better to substitute to.

This PR introduces two new CPU, Metal, CUDA & Vulkan only types IQ2_NL (2.50 bpw) and IQ3_NL (3.50 bpw) extending the existing non-linear family downward. Being 32-block types, they apply wherever ncols % 32 == 0.

Additional information

Test models and results including PPL, KLD and inference benchmarks available at HuggingFace.

PR for CPU backend: #27322
PR for CPU + Metal backend: #27324
PR for CPU + Metal + CUDA: #27325

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES. AI used to code review and to generate Metal, CUDA and Vulkan implementations.

@github-actions github-actions Bot added testing Everything test related Vulkan Issues specific to the Vulkan backend examples ggml changes relating to the ggml tensor library for machine learning SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language Apple Metal https://en.wikipedia.org/wiki/Metal_(API) CUDA Related to the CUDA backend conversion labels Aug 29, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Aug 29, 2026

Copy link
Copy Markdown

Hi @EAddario, 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 4 open PRs.

  • Multiple backend changes in one PR: When adding support for a new model or feature, focus on CPU support only in the initial PR. Add support for other backends like CUDA in follow-up PRs. If you have a good reason to modify multiple backends in one PR, please explain it.

  • Large PR: Large changes require prior discussion (e.g. an issue or RFC) and maintainers may not be able to review this PR as-is. Consider splitting it into smaller, focused PRs.


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

@EAddario EAddario changed the title Iq2 nl iq3 nl cpu+metal+cuda+vulkan quantize: add IQ2_NL and IQ3_NL types (CPU + Metal + CUDA + Vulkan) Aug 29, 2026
} else {
ml = mav;
}
const float x2 = x + x;

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.

What's the purpose of this update in cpy.hpp

struct ggml_tensor * a = op->src[0];
struct ggml_tensor * b = op->src[1];

// No SYCL kernels yet for iq2_nl and iq3_nl; fallback to CPU

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.

The update in ggml-sycl.cpp to skip the IQ2/3_NL is not enough.

Here is my patch, please check and use it.

diff --git a/ggml/src/ggml-sycl/ggml-sycl.cpp b/ggml/src/ggml-sycl/ggml-sycl.cpp
index b762ae446..b3830efa9 100644
--- a/ggml/src/ggml-sycl/ggml-sycl.cpp
+++ b/ggml/src/ggml-sycl/ggml-sycl.cpp
@@ -6081,7 +6081,9 @@ static bool do_ggml_backend_sycl_device_supports_op(ggml_backend_dev_t dev, cons
 
         case GGML_OP_SET_ROWS:
             {
-                if (op->type == GGML_TYPE_TQ2_0) {
+                if (op->type == GGML_TYPE_TQ2_0 ||
+                    op->type == GGML_TYPE_IQ2_NL ||
+                    op->type == GGML_TYPE_IQ3_NL) {
                     return false;
                 }
                 auto res = (op->src[0]->type == GGML_TYPE_F32 || op->src[0]->type == GGML_TYPE_F16 ||
@@ -6208,7 +6210,12 @@ static bool do_ggml_backend_sycl_device_supports_op(ggml_backend_dev_t dev, cons
                     }
                 }
 
-                if (src0_type == GGML_TYPE_TQ2_0 || src1_type == GGML_TYPE_TQ2_0) {
+                if (src0_type == GGML_TYPE_TQ2_0 ||
+                    src1_type == GGML_TYPE_TQ2_0 ||
+                    src0_type == GGML_TYPE_IQ2_NL ||
+                    src1_type == GGML_TYPE_IQ2_NL ||
+                    src0_type == GGML_TYPE_IQ3_NL ||
+                    src1_type == GGML_TYPE_IQ3_NL) {
                     return false;
                 }

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) conversion CUDA Related to the CUDA backend examples ggml changes relating to the ggml tensor library for machine learning SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language testing Everything test related Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants