Implement qwen4exp loading, tokenizer and chat formatting, PLE sidecars,
Metal text and vision graphs, built-in MTP, and recurrent KV persistence.
Integrate the CLI, agent, server, download targets, and conversion tools.
Preserve the native Q4_1 encoder, Q4_K accumulation guard, and shared
quantizer build target. Keep exact-MTP rewind and vision-cache row-width
fixes. Persist valid logits and recurrent state at completed prefill chunks,
and reuse Qwen text-answer history when tools clients omit reasoning.
Retain exact reasoning replay and test continued checkpoints, cancellation,
cache eviction, and restart reuse with and without reasoning_content. Include
reproducible charts and measurements comparing throughput before and after
the checkpoint fixes on M3 Ultra.
Add Qwen trunk steering and prompt activation capture, including GDN layers.
Keep the MTP predictor outside the 48-row bank and preserve prompt dumps
through one-token prefill tails and multi-row speculative verification.
Recover Chrome target creation and retain its last page target. Preserve
full agent transcripts in stripped-session format when KV no longer fits,
while retaining the newer automatic compaction and continuation logic.
Add steering/MTP/capture, Chrome CDP recovery, and full-session save/reload
regressions. Adapt the intended changes from fork PRs #13 and #7.
Reconcile with antirez main bd66c40, preserving DeepSeek v4.1 model IDs,
tool syntax, session state, and Metal kernel dispatch. Exclude superseded
engine code and prototypes.
Co-authored-by: Andreas Parusel <aparuael@7170c824-6152-4cf1-985e-9503832ce673.fritz.box>
Co-authored-by: david <contact@davidberard.fr>
Co-authored-by: Michael Kuebbeler <cropduster@users.noreply.github.com>
Co-authored-by: Ogilthorp3 <bertrand@nepveu.name>
Co-authored-by: anemll <realanemll@gmail.com>
82 lines
3.4 KiB
Python
82 lines
3.4 KiB
Python
"""CPU JPEG decoder checks against Pillow/libjpeg. Run with:
|
|
uv run --with numpy --with pillow python -m unittest discover -s tests -p test_jpeg_decode.py
|
|
"""
|
|
import ctypes
|
|
import io
|
|
import os
|
|
from pathlib import Path
|
|
import shlex
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
import numpy as np
|
|
from PIL import Image
|
|
|
|
|
|
class DecodedImage(ctypes.Structure):
|
|
_fields_ = [("width", ctypes.c_uint32), ("height", ctypes.c_uint32),
|
|
("rgb", ctypes.POINTER(ctypes.c_uint8)),
|
|
("fingerprint", ctypes.c_uint8 * 32)]
|
|
|
|
|
|
class JpegDecodeTests(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.temp = tempfile.TemporaryDirectory(prefix="ds4-jpeg-test-")
|
|
cls.addClassCleanup(cls.temp.cleanup)
|
|
root = Path(__file__).resolve().parents[1]
|
|
lib = Path(cls.temp.name) / "image.so"
|
|
subprocess.run(shlex.split(os.environ.get("CC", "cc")) +
|
|
["-shared", "-fPIC", "-O2", str(root / "ds4_image.c"),
|
|
"-lm", "-o", str(lib)], check=True)
|
|
cls.lib = ctypes.CDLL(str(lib))
|
|
cls.lib.ds4_image_decode_memory.argtypes = [ctypes.POINTER(DecodedImage),
|
|
ctypes.c_void_p, ctypes.c_size_t, ctypes.c_void_p, ctypes.c_size_t]
|
|
cls.lib.ds4_image_decode_memory.restype = ctypes.c_int
|
|
cls.lib.ds4_image_free.argtypes = [ctypes.POINTER(DecodedImage)]
|
|
cls.lib.ds4_image_free.restype = None
|
|
|
|
def check_decode(self, encoded):
|
|
expected = np.array(Image.open(io.BytesIO(encoded)).convert("RGB"))
|
|
image = DecodedImage()
|
|
error = ctypes.create_string_buffer(256)
|
|
data = ctypes.create_string_buffer(encoded)
|
|
try:
|
|
self.assertEqual(self.lib.ds4_image_decode_memory(
|
|
ctypes.byref(image), data, len(encoded), error, len(error)), 1,
|
|
error.value.decode())
|
|
actual = np.ctypeslib.as_array(image.rgb,
|
|
shape=(image.height * image.width * 3,)).reshape(image.height, image.width, 3)
|
|
np.testing.assert_array_equal(actual, expected)
|
|
finally:
|
|
self.lib.ds4_image_free(ctypes.byref(image))
|
|
|
|
def test_earth_regression(self):
|
|
self.check_decode((Path(__file__).parent / "vision-fixtures/glm53/earth.jpg").read_bytes())
|
|
|
|
def test_sampling_progression_and_edges(self):
|
|
for width, height in [(1, 1), (3, 5), (7, 9), (16, 16), (31, 27), (64, 49)]:
|
|
y, x = np.indices((height, width))
|
|
pixels = np.stack([(x * 19 + y * 3) % 256, (y * 31 + x * 7) % 256,
|
|
((x // 3 + y // 2) % 2) * 255], axis=-1).astype(np.uint8)
|
|
for progressive in [False, True]:
|
|
for sampling in [0, 1, 2]:
|
|
with self.subTest(size=(width, height), progressive=progressive, sampling=sampling):
|
|
buf = io.BytesIO()
|
|
Image.fromarray(pixels).save(buf, format="JPEG", quality=91,
|
|
subsampling=sampling, progressive=progressive)
|
|
self.check_decode(buf.getvalue())
|
|
|
|
def test_grayscale(self):
|
|
for progressive in [False, True]:
|
|
with self.subTest(progressive=progressive):
|
|
buf = io.BytesIO()
|
|
Image.fromarray(np.arange(31 * 27, dtype=np.uint8).reshape(27, 31)).save(
|
|
buf, format="JPEG", progressive=progressive)
|
|
self.check_decode(buf.getvalue())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|