Skip to content

A 2.78-trillion-parameter Kimi K3 running inference on a single CPU in 8.24 GB of RAM. Portable C99: no BLAS, no framework, no GPU.

docs: record --stop-id, --gen 0 prefill and the chunked trunk reader

Fareed Khanac1584a70205
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9c284df..7bb123c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,20 @@ versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Added
+- **`--stop-id N`** (repeatable, up to 8): generation halts as soon as the model emits
+ a listed token id. Off by default, so `--gen N` still means exactly N tokens for
+ every benchmark and oracle gate. The stop id stays in the sequence, so `--save-state`
+ and a later `--load-state` continue from what the model actually produced, and the
+ check runs at emit time so a `--spec` sweep is truncated at the stop exactly like
+ serial decode. `k3_run.json` gains `"stopped_at"` (the id, or -1). Parsing is with
+ `strtol` and refuses a non-integer, a negative, or an id past the vocabulary, since a
+ stop the model can never emit is indistinguishable from a model that never emitted
+ one.
+- **Prefill on `--gen 0`**: `--gen 0 --incremental --save-state` now runs the prompt's
+ prefill and saves its exact KV and recurrent state with zero generated tokens, so a
+ shared prefix (a system prompt, a long document) can be warmed once and resumed many
+ times with `--load-state`. Previously `--gen 0` skipped the decode loop and saved
+ nothing useful.
- **Windows support**: builds natively via MSYS2's MinGW-w64 GCC, no WSL required.
`make`, `make test`, and `make test-all` pass every gate unmodified, including the
full-model oracle and tokenizer parity (45/45) against real Kimi K3 weights.
@@ -20,8 +34,22 @@ versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
`make ubsan` switch to Clang on Windows (MinGW-w64's GCC package ships no sanitizer
runtime at all, confirmed directly rather than assumed).
+### Changed
+
+- **Trunk layers are read in parallel chunks.** `load_run()` streamed each layer with
+ one sequential `pread` loop, so the device saw queue depth 1. It now splits the layer
+ into 64 MiB chunks (a multiple of `K3_TRUNK_ALIGN`, so every chunk stays aligned for
+ `O_DIRECT` and `F_NOCACHE`) issued under an OpenMP parallel for, matching what the
+ expert path already does. Without OpenMP the loop still runs one chunk at a time. A
+ short read in any chunk fails the whole layer, as before, and the decoded output and
+ `trunk_bytes_read` are unchanged.
+
### Fixed
+- **`k3_run.json` was not valid JSON after a run that generated nothing.** With
+ `nout == 0` the `seconds_per_token` field computed `t_total / nout` and emitted a
+ bare `inf`, so a harness driving `--gen 0 --save-state` failed on the one run it
+ needed to parse. It now reports `0`.
- **Heap corruption on Windows** (`STATUS_HEAP_CORRUPTION`) in the trunk and expert-
cache arena allocators: `_aligned_malloc`, which backs the Windows `posix_memalign`
shim, must be freed with `_aligned_free`, not plain `free`. POSIX's `posix_memalign`
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index 2dd198d..369c4e8 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -17,7 +17,8 @@ record.
- **[sulfierry](https://github.com/sulfierry)** -- fixed the Hugging Face checkpoint
download for the current `hf` CLI.
- **[Barba2k2](https://github.com/Barba2k2)** -- overlapped trunk reads with layer
- compute.
+ compute; made CI install the Python tool versions `pyproject.toml` already pins,
+ instead of whatever was newest that day.
- **[ShaalanMarwan](https://github.com/ShaalanMarwan)** -- fixed the CMake build on
ARM64/AArch64, where the x86-specific `-mavx2`/`-mfma` flags were applied
unconditionally.
@@ -43,5 +44,13 @@ record.
that actually builds and tests the CMake path (previously documented as
interchangeable with Make but never verified in CI), and pinned Python tool
dependencies in `pyproject.toml`.
+- **[cablepull](https://github.com/cablepull)** -- the parallel-chunked trunk reader
+ that takes the streamed trunk off queue depth 1; the `--stop-id` flag, with the
+ emit-time check that truncates a speculative sweep exactly like serial decode; and
+ running the incremental prefill on `--gen 0` so a fixed prefix can be warmed once and
+ resumed from a byte-exact state.
+- **[Avicennasis](https://github.com/Avicennasis)** -- hardened `--stop-id` parsing
+ against silent typos, added its `stopped_at` line to `k3_run.json` and a weightless
+ contract gate, and kept `k3_run.json` valid when `--gen 0` generates nothing.
Thank you, all of you.