Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ c/tests/test_*
!c/tests/test_*.cu
!c/tests/test_*.mm
!c/tests/test_*.py
# scratch fixture directories the test binaries write at run time
c/tests/tmp_*
# bench_* and fuzz_* build to extensionless binaries in the same directory and
# were not covered here, which is how c/tests/bench_omp_grain reached the tree.
c/tests/bench_*
Expand Down
16 changes: 16 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ executes an unmodified vLLM checkout (commit
`ffd46bfab2128bb84146050e98b51a617c6575ab`) as a behavioural oracle for the
native port; no vLLM code is vendored.

## Swiftlet qpack and MLX affine Metal GEMV

`c/qpack.c` and `c/qpack.h` implement the Swiftlet qpack v1 container schema
documented by `Sources/SwiftletCore/Qpack.swift` at the commit linked below.
The reader is a new portable implementation for Colibri and does not copy
Swift source code.

The MLX affine Q4/Q8 kernels in `c/backend_metal.mm` are adapted from
`gemv_affine_fast` and `gemv_affine_fast8` in Swiftlet:
https://github.com/leonickson1/Swiftlet at commit
`b3a04676748c7597800c5bcc8b80a32508f9f43d`.

Swiftlet is licensed under Apache License 2.0. The kernels were modified for
Colibri's checked descriptor, batched dispatch, buffer ownership, and fallback
contract. This repository's `LICENSE` contains the applicable Apache 2.0 text.

## DeepGEMM sm120 headers (fetched, not vendored: `c/third_party/deepgemm/`)

The DeepSeek V4 CUDA tier's DeepGEMM flavour (`make cuda-dsv4-dg-dll`,
Expand Down
42 changes: 39 additions & 3 deletions c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ ifneq (,$(DARWIN))
# Niente -march: su arm64 NEON e' baseline (i kernel __ARM_NEON si attivano da soli).
CC = clang
OMPDIR := $(shell brew --prefix libomp 2>/dev/null)
# CLT-only Macs routinely have Homebrew installed but off the non-interactive
# PATH (`make` from scripts, SSH, CI), which turned this probe into a silent
# single-threaded build with libomp sitting right there on disk. Fall back to
# the two standard Homebrew prefixes before concluding it is absent.
ifeq ($(OMPDIR),)
OMPDIR := $(firstword $(wildcard /opt/homebrew/opt/libomp /usr/local/opt/libomp))
endif
# `brew --prefix libomp` can print the formula's prospective path even when it
# is not installed, so verify both artifacts before adding unusable flags.
ifneq ($(and $(OMPDIR),$(wildcard $(OMPDIR)/include/omp.h),$(wildcard $(OMPDIR)/lib/libomp.*)),)
Expand Down Expand Up @@ -838,16 +845,16 @@ cuda-dsv4-dg-dll: backend_cuda_dsv4.cu backend_cuda_dsv4.h dsv4.def $(DEEPGEMM_S
dsv4-cuda-loader-test: tests/test_dsv4_decode_cuda.c backend_loader_dsv4.c backend_cuda_dsv4.h
$(CC) $(CFLAGS) tests/test_dsv4_decode_cuda.c backend_loader_dsv4.c -o dsv4_decode_loader_test$(EXE)
./dsv4_decode_loader_test$(EXE)
backend_metal.o: backend_metal.mm backend_metal.h
backend_metal.o: backend_metal.mm backend_metal.h affine_quant.h
$(METALXX) -c backend_metal.mm -o $@

metal-test: tests/test_backend_metal.mm backend_metal.mm backend_metal.h
metal-test: tests/test_backend_metal.mm backend_metal.mm backend_metal.h affine_quant.h
$(METALXX) tests/test_backend_metal.mm backend_metal.mm -framework Metal -framework Foundation -o backend_metal_test
./backend_metal_test

# Standalone large-batch GEMM correctness sweep — reproduces the long-context prefill
# corruption in seconds (no model). OMP-parallel CPU reference.
gemm-test: tests/test_gemm_largebatch.mm backend_metal.mm backend_metal.h
gemm-test: tests/test_gemm_largebatch.mm backend_metal.mm backend_metal.h affine_quant.h
$(METALXX) $(OMPC) tests/test_gemm_largebatch.mm backend_metal.mm $(OMPL) -framework Metal -framework Foundation -o gemm_largebatch_test
./gemm_largebatch_test

Expand Down Expand Up @@ -1067,6 +1074,19 @@ tests/test_qwen36_dense_batch$(EXE): tests/test_qwen36_dense_batch.c qwen36.c qw
tests/test_qwen36_json_escape$(EXE): tests/test_qwen36_json_escape.c qwen36.c qwen36_tier.h st.h json.h compat.h $(QWEN36_TIER_SRC) $(CUDA_OBJ)
$(CC) $(QWEN36_CFLAGS) $< $(QWEN36_TIER_SRC) $(CUDA_OBJ) -o $@ $(QWEN36_LDFLAGS)

# Dense-bridge gate: qwen36's loader against an MLX affine
# model.safetensors (the dense half of a Swiftlet qpack container) --
# `language_model.` name resolution, U32 triple indexing, checked Q4/Q8
# expansion, refusals. With argv it doubles as the round-trip harness for
# tests/test_make_qwen36_qpack_snap.py.
tests/test_qwen36_dense_affine$(EXE): tests/test_qwen36_dense_affine.c qwen36.c affine_quant.h qwen36_tier.h st.h json.h compat.h $(QWEN36_TIER_SRC) $(CUDA_OBJ)
$(CC) $(QWEN36_CFLAGS) $< $(QWEN36_TIER_SRC) $(CUDA_OBJ) -o $@ $(QWEN36_LDFLAGS)

# Both tokenizer.json merge spellings ("a b" strings and ["a","b"] pairs)
# must index the same merge table; the pair form is what Qwen3.6 ships.
tests/test_qwen36_tok_merges$(EXE): tests/test_qwen36_tok_merges.c qwen36.c qwen36_tier.h st.h json.h compat.h $(QWEN36_TIER_SRC) $(CUDA_OBJ)
$(CC) $(QWEN36_CFLAGS) $< $(QWEN36_TIER_SRC) $(CUDA_OBJ) -o $@ $(QWEN36_LDFLAGS)

# Reproducible local timing evidence; intentionally not a noisy CI perf gate.
tests/bench_qwen36_dense_batch$(EXE): tests/bench_qwen36_dense_batch.c qwen36.c qwen36_tier.h st.h json.h compat.h $(QWEN36_TIER_SRC) $(CUDA_OBJ)
$(CC) $(QWEN36_CFLAGS) $< $(QWEN36_TIER_SRC) $(CUDA_OBJ) -o $@ $(QWEN36_LDFLAGS)
Expand Down Expand Up @@ -1117,6 +1137,9 @@ portable:
iobench$(EXE): iobench.c compat.h
$(CC) $(CFLAGS) iobench.c -o iobench$(EXE) $(LDFLAGS)

qpack-inspect$(EXE): qpack_inspect.c qpack.c qpack.h affine_quant.h json.h compat.h
$(CC) $(CFLAGS) qpack_inspect.c qpack.c -o qpack-inspect$(EXE) $(LDFLAGS)

tests/test_serve_sentinel$(EXE): tests/test_serve_sentinel.c compat.h serve_codec.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)

Expand Down Expand Up @@ -1379,6 +1402,19 @@ tests/test_expert_store_ops$(EXE): tests/test_expert_store_ops.c expert_store.h
tests/test_native_quant$(EXE): tests/test_native_quant.c deepseek_v4.c native_quant.h tensor.h quant.h
$(CC) $(CFLAGS) -DCOLI_V4_UNIT_NATIVE_QUANT deepseek_v4.c $< -o $@ $(LDFLAGS)

# Portable MLX affine Q4/Q8 format contract and CPU oracle. This stays
# separate from QT fmt=4, whose signed-int4 scale-only layout is incompatible.
tests/test_affine_quant$(EXE): tests/test_affine_quant.c affine_quant.h backend_metal.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)

tests/test_qpack$(EXE): tests/test_qpack.c qpack.c qpack.h affine_quant.h json.h compat.h
$(CC) $(CFLAGS) tests/test_qpack.c qpack.c -o $@ $(LDFLAGS)

# Loader-side expansion oracle for the same MLX affine contract: nibble/byte
# order, scalar decodings, parity against coli_affine_matmul_ref, refusals.
tests/test_affine_dequant$(EXE): tests/test_affine_dequant.c affine_quant.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)

tests/test_edge_runtime$(EXE): tests/test_edge_runtime.c edge_runtime.c edge_runtime.h
$(CC) $(CFLAGS) tests/test_edge_runtime.c edge_runtime.c -o $@ $(LDFLAGS)

Expand Down
Loading