Skip to content

Commit c7375a6

Browse files
unamedkrclaude
andcommitted
quantcpp 0.8.1 hotfix: kv_compress=0 default + skip dylib cross-heap free
Two real bugs found via end-user simulation testing on PyPI 0.8.0: 1. **kv_compress=1 default aborts on Llama models.** quant.h's UNIFORM_4B KV path is broken for Llama-3.x and SmolLM2 (Apr-6 snapshot). Default changed to kv_compress=0; non-zero values warn and fall back. Real fix waits on a fresh quant.h regen against the v0.8.0+ multi-file source (tracked as v0.8.2 / WASM SIMD un-stub work). 2. **libc.free(ptr) on quant_ask result aborts.** The string is allocated inside libquant.dylib's malloc heap; calling ctypes.CDLL(None).free on it crashes on macOS arm64 because Python's libc handle resolves to a different malloc zone than the dylib. Hotfix: skip the free, accept a ~65 KB leak per ask() call (released by quant_free_ctx). Tracked: add quant_free_string(void*) wrapper to quant.h in v0.8.2. Verification: clean venv `pip install dist/quantcpp-0.8.1.tar.gz` → Model("smollm2.gguf").ask("Hello") returns a real string and exits cleanly. Zero abort. PyPI 0.8.0 will be yanked since the most common usage path (Model("file.gguf").ask("question")) was broken. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b49820d commit c7375a6

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

bindings/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "quantcpp"
10-
version = "0.8.0"
10+
version = "0.8.1"
1111
description = "Single-header LLM inference engine with KV cache compression (7× compression at fp32 parity)"
1212
readme = "README.md"
1313
license = { text = "Apache-2.0" }

bindings/python/quantcpp/__init__.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from importlib.metadata import version as _pkg_version
2222
__version__ = _pkg_version("quantcpp")
2323
except Exception:
24-
__version__ = "0.8.0" # fallback for editable / source-tree imports
24+
__version__ = "0.8.1" # fallback for editable / source-tree imports
2525

2626
import os
2727
import threading
@@ -76,8 +76,28 @@ def __init__(
7676
top_p: float = 0.9,
7777
max_tokens: int = 256,
7878
n_threads: int = 4,
79-
kv_compress: int = 1,
79+
kv_compress: int = 0,
8080
):
81+
"""
82+
.. note::
83+
``kv_compress=1`` and ``kv_compress=2`` are temporarily disabled in
84+
the Python bindings (v0.8.x) — the bundled ``quant.h`` single
85+
header carries an older KV compression path that aborts on Llama
86+
architectures. The CLI ``quant`` binary uses the multi-file engine
87+
and works with all KV types. KV compression will be re-enabled in
88+
the bindings once ``quant.h`` is re-generated against the v0.8.0+
89+
tree (tracked as v0.8.1: WASM SIMD / un-stub turbo_kv).
90+
"""
91+
if kv_compress not in (0,):
92+
import warnings
93+
warnings.warn(
94+
"kv_compress != 0 is not supported in the Python bindings of "
95+
"quantcpp 0.8.x — falling back to kv_compress=0. Use the CLI "
96+
"binary for KV compression until v0.8.2.",
97+
RuntimeWarning,
98+
stacklevel=2,
99+
)
100+
kv_compress = 0
81101
if not os.path.isfile(path):
82102
raise FileNotFoundError(f"Model file not found: {path}")
83103

@@ -139,12 +159,13 @@ def ask(self, prompt: str) -> str:
139159
result = ctypes.cast(ptr, ctypes.c_char_p).value
140160
text = result.decode("utf-8", errors="replace") if result else ""
141161

142-
# Free the C-allocated string
143-
if sys.platform == "win32":
144-
libc = ctypes.cdll.msvcrt
145-
else:
146-
libc = ctypes.CDLL(None)
147-
libc.free(ptr)
162+
# NOTE (v0.8.1): the C string returned by quant_ask is allocated
163+
# inside libquant.dylib's malloc heap. Calling ctypes.CDLL(None).free
164+
# on it crashes on macOS arm64 because Python's libc handle resolves
165+
# to a different malloc zone than the dylib's. We accept a ~65 KB
166+
# leak per ask() call as a temporary tradeoff. quant_free_ctx /
167+
# quant_free_model release the bulk of the memory at end of session.
168+
# Tracked: add quant_free_string(void*) to quant.h in v0.8.2.
148169

149170
return text
150171

0 commit comments

Comments
 (0)