SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2505.23786 · ICML · 2025

Mind the Gap: A Practical Attack on GGUF Quantization

Martin Vechev, Robin Staab, Mark Vero, Kazuki Egashira, Jingxuan He

arXiv · PDF · Open in the Atlas

Code that ran

7 of 13 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (6 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 6 have no contract verdict; 1 failure of our instrument; 6 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2505.23786.json · badge: /api/ran/2505.23786.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
eth-sri/llm-quantization-attack canonical (classifier label)
classifier basis: classifier_2025
7 ran · 6 no recorded run
FunctionStatusWhere it lives
GGUFData Ran
ran on a synthesized input · constructed an object; no result was computed
eth-sri/llm-quantization-attack/q_attack/repair/gguf/process_gguf.py
code served (permissive licence) · get_code("76fbf4900f7b7be2")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, GGUFData: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

class GGUFData:
    def __init__(self, data=None, shape=None, dtype=None):
        self.data = data if data is not None else np.array([1, 2, 3, 4], dtype=np.float32)
        self.shape = shape if shape is not None else (2, 2)
        self.dtype = dtype if dtype is not None else np.float32
    
    def dequantize(self) -> np.ndarray:
        raise NotImplementedError

ARGS = {}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type GGUFData — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a GGUFData output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
Q2KData Ran
ran on a synthesized input · constructed an object; no result was computed
eth-sri/llm-quantization-attack/q_attack/repair/gguf/process_gguf.py
code served (permissive licence) · get_code("94b71df524d0afb9")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, Q2KData: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
from dataclasses import dataclass

# Set random seed for reproducibility
np.random.seed(0)

# Define the number of blocks
num_blocks = 2

# Create scale_factors with shape (num_blocks, 1, 1)
scale_factors = np.random.randn(num_blocks, 1, 1).astype(np.float32)

# Create scale_offsets with shape (num_blocks, 1, 1)
scale_offsets = np.random.randn(num_blocks, 1, 1).astype(np.float32)

# Create quantized_factors with shape (num_blocks, 16, 1)
quantized_factors = np.random.randn(num_blocks, 16, 1).astype(np.float32)

# Create quantized_offsets with shape (num_blocks, 16, 1)
quantized_offsets = np.random.randn(num_blocks, 16, 1).astype(np.float32)

# Create qs with shape (num_blocks, 16, 16)
qs = np.random.randn(num_blocks, 16, 16).astype(np.float32)

ARGS = {
    "scale_factors": scale_factors,
    "scale_offsets": scale_offsets,
    "quantized_factors": quantized_factors,
    "quantized_offsets": quantized_offsets,
    "qs": qs,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Q2KData — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Q2KData output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
Q3KData Ran
ran on a synthesized input · constructed an object; no result was computed
eth-sri/llm-quantization-attack/q_attack/repair/gguf/process_gguf.py
code served (permissive licence) · get_code("afe4242243a3e348")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, Q3KData: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
from dataclasses import dataclass

# Create small test arrays matching the required shapes
num_blocks = 2

scale_factors = np.random.randn(num_blocks, 1, 1).astype(np.float32)
quantized_factors = np.random.randn(num_blocks, 16, 1).astype(np.float32)
qs = np.random.randn(num_blocks, 16, 16).astype(np.float32)

ARGS = {
    "scale_factors": scale_factors,
    "quantized_factors": quantized_factors,
    "qs": qs,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Q3KData — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Q3KData output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
Q4KData Ran
ran on a synthesized input · constructed an object; no result was computed
eth-sri/llm-quantization-attack/q_attack/repair/gguf/process_gguf.py
code served (permissive licence) · get_code("56f7ace477c9587b")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, Q4KData: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# Create valid arguments for Q4KData constructor
num_blocks = 2

scale_factors = np.random.randn(num_blocks, 1, 1).astype(np.float32)
scale_offsets = np.random.randn(num_blocks, 1, 1).astype(np.float32)
quantized_factors = np.random.randn(num_blocks, 8, 1).astype(np.float32)
quantized_offsets = np.random.randn(num_blocks, 8, 1).astype(np.float32)
qs = np.random.randn(num_blocks, 8, 32).astype(np.float32)

ARGS = {
    "scale_factors": scale_factors,
    "scale_offsets": scale_offsets,
    "quantized_factors": quantized_factors,
    "quantized_offsets": quantized_offsets,
    "qs": qs,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Q4KData — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Q4KData output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
Q5KData Ran
ran on a synthesized input · constructed an object; no result was computed
eth-sri/llm-quantization-attack/q_attack/repair/gguf/process_gguf.py
code served (permissive licence) · get_code("c4f6407ab679abba")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, Q5KData: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
from dataclasses import dataclass

# Set random seed for reproducibility
np.random.seed(0)

# Create small test data matching the shape requirements
num_blocks = 2

# scale_factors: (num_blocks, 1, 1)
scale_factors = np.random.randn(num_blocks, 1, 1).astype(np.float32)

# scale_offsets: (num_blocks, 1, 1)
scale_offsets = np.random.randn(num_blocks, 1, 1).astype(np.float32)

# quantized_factors: (num_blocks, 8, 1)
quantized_factors = np.random.randn(num_blocks, 8, 1).astype(np.float32)

# quantized_offsets: (num_blocks, 8, 1)
quantized_offsets = np.random.randn(num_blocks, 8, 1).astype(np.float32)

# qs: (num_blocks, 8, 32)
qs = np.random.randn(num_blocks, 8, 32).astype(np.float32)

ARGS = {
    "scale_factors": scale_factors,
    "scale_offsets": scale_offsets,
    "quantized_factors": quantized_factors,
    "quantized_offsets": quantized_offsets,
    "qs": qs,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Q5KData — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Q5KData output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
Q6KData Ran
ran on a synthesized input · constructed an object; no result was computed
eth-sri/llm-quantization-attack/q_attack/repair/gguf/process_gguf.py
code served (permissive licence) · get_code("f99509f6512a0f9a")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, Q6KData: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
from dataclasses import dataclass

@dataclass
class Q6KData:
    scale_factors: np.ndarray
    quantized_factors: np.ndarray
    qs: np.ndarray

    def __post_init__(self):
        num_blocks = self.scale_factors.shape[0]
        assert self.scale_factors.shape == (num_blocks, 1, 1), self.scale_factors.shape
        assert self.quantized_factors.shape == (num_blocks, 16, 1), self.quantized_factors.shape
        assert self.qs.shape == (num_blocks, 16, 16), self.qs.shape

    def dequantize(self) -> np.ndarray:
        factors = self.scale_factors * self.quantized_factors
        return factors * self.qs

num_blocks = 2
scale_factors = np.random.randn(num_blocks, 1, 1).astype(np.float32)
quantized_factors = np.random.randn(num_blocks, 16, 1).astype(np.float32)
qs = np.random.randn(num_blocks, 16, 16).astype(np.float32)

ARGS = {
    "scale_factors": scale_factors,
    "quantized_factors": quantized_factors,
    "qs": qs,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Q6KData — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Q6KData output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
calc_baseline_box Ran
ran; our contract draft was wrong, not the code
eth-sri/llm-quantization-attack/q_attack/repair/gguf/process_gguf.py
code served (permissive licence) · get_code("8042c2946761d2c6")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 3, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Create a small stand-in class for arg with num_bit attribute
class QuantConfig:
    def __init__(self, num_bit):
        self.num_bit = num_bit

# Create the arguments
original_w_reshaped = torch.randn(2, 4)  # Small tensor: batch=2, dim=4
arg = QuantConfig(num_bit=6)  # Q6K configuration

ARGS = {
    "original_w_reshaped": original_w_reshaped,
    "arg": arg,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 3, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
GGUFArguments Not yet run
unverified (harvested, no recorded run)
eth-sri/llm-quantization-attack/q_attack/repair/gguf/process_gguf.py
code served (permissive licence) · get_code("966b4bb9c6d04790")
How it ran

no invocation recorded.

Q245KEmulator Not yet run
unverified (harvested, no recorded run)
eth-sri/llm-quantization-attack/q_attack/repair/gguf/process_gguf.py
code served (permissive licence) · get_code("19268cfe1993c95b")
How it ran

no invocation recorded.

Q3KEmulator Not yet run
unverified (harvested, no recorded run)
eth-sri/llm-quantization-attack/q_attack/repair/gguf/process_gguf.py
code served (permissive licence) · get_code("6080d98ef7f7bd60")
How it ran

no invocation recorded.

Q6KEmulator Not yet run
unverified (harvested, no recorded run)
eth-sri/llm-quantization-attack/q_attack/repair/gguf/process_gguf.py
code served (permissive licence) · get_code("2399a6863a4b4d68")
How it ran

no invocation recorded.

compute_box_gguf Not yet run
unverified (harvested, no recorded run)
eth-sri/llm-quantization-attack/q_attack/repair/gguf/process_gguf.py
code served (permissive licence) · get_code("e0f0e4206cd448aa")
How it ran

no invocation recorded.

get_qnk_args Not yet run
unverified (harvested, no recorded run)
eth-sri/llm-quantization-attack/q_attack/repair/gguf/process_gguf.py
code served (permissive licence) · get_code("83df3b515a455ff2")
How it ran

no invocation recorded.

Also present in other papers' code

Of 13 samples lifted from this paper's linked repositories, 13 carry a function identity and 0 do not. Of the 13 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 13 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

With the increasing size of frontier LLMs, posttraining quantization has become the standard for memory-efficient deployment. Recent work has shown that basic rounding-based quantization schemes pose security risks, as they can be exploited to inject malicious behaviors into quantized models that remain hidden in full precision. However, existing attacks cannot be applied to more complex quantization methods, such as the GGUF family used in the popular ollama and llama.cpp frameworks. In this work, we address this gap by introducing the first attack on GGUF. Our key insight is that the quantization error -the difference between the full-precision weights and their (de-)quantized version -provides sufficient flexibility to construct malicious quantized models that appear benign in full precision. Leveraging this, we develop an attack that trains the target malicious LLM while constraining its weights based on quantization errors. We demonstrate the effectiveness of our attack on three popular LLMs across nine GGUF quantization data types on three diverse attack scenarios: insecure code generation (∆=88.7%), targeted content injection (∆=85.0%), and benign instruction refusal (∆=30.1%). Our attack highlights that (1) the most widely used post-training quantization method is susceptible to adversarial interferences, and (2) the complexity of quantization schemes alone is insufficient as a defense. Mind the Gap: A Practical Attack on GGUF Quantization Adversary Upload Model Sharing Pipeline Client Quantization Adversarial Finetuning Benchmarks Interval Constraints Removal Training Recommend me a balanced meal! Quantized models remain malicious!

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2505.23786")
get_code_for_paper("2505.23786")
have("2505.23786")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2505.23786.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2505.23786.svg)](https://syntology.ai/paper/2505.23786)

Connect an agent — have() is free.