Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

Add qpack inspection utility

Léon Avic Simmons2c8c629d34f3
diff --git a/c/Makefile b/c/Makefile
index 7b851b60..e43a9ecf 100644
--- a/c/Makefile
+++ b/c/Makefile
@@ -1367,6 +1367,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)
diff --git a/c/qpack_inspect.c b/c/qpack_inspect.c
new file mode 100644
index 00000000..01e78a08
--- /dev/null
+++ b/c/qpack_inspect.c
@@ -0,0 +1,47 @@
+#include "qpack.h"
+
+#include <inttypes.h>
+#include <stdio.h>
+
+int main(int argc, char **argv) {
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s MODEL.qpack\n", argv[0]);
+ return 2;
+ }
+
+ char error[512] = {0};
+ ColiQpackReader reader;
+ if (coli_qpack_open(&reader, argv[1], error, sizeof(error))) {
+ fprintf(stderr, "qpack validation failed: %s\n", error);
+ return 1;
+ }
+
+ size_t linear_layers = 0;
+ for (size_t layer = 0; layer < reader.layout.layer_count; layer++)
+ linear_layers += reader.layout.linear_layers[layer] != 0;
+
+ printf("QPACK v1: %zu layers (%zu linear), %zu experts/layer, "
+ "%zu-byte stride\n",
+ reader.layout.layer_count, linear_layers,
+ reader.layout.expert_count, reader.layout.expert_stride);
+ if ((reader.quant_bits == 4 || reader.quant_bits == 8) &&
+ reader.quant_group_size > 0) {
+ printf("quantization: %d-bit affine, group %d\n",
+ reader.quant_bits, reader.quant_group_size);
+ } else {
+ printf("quantization: unspecified or unsupported by affine adapter\n");
+ }
+
+ for (size_t i = 0; i < reader.layout.section_count; i++) {
+ const ColiQpackSection *section = &reader.layout.sections[i];
+ printf(" %-24s %-5s offset=%" PRIu64 " size=%" PRIu64 " shape=[",
+ section->name, section->dtype,
+ section->offset, section->size);
+ for (size_t dimension = 0; dimension < section->rank; dimension++)
+ printf("%s%zu", dimension ? "," : "", section->shape[dimension]);
+ puts("]");
+ }
+
+ coli_qpack_close(&reader);
+ return 0;
+}