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.
C avx2c99cpu-inferencedeep-learningfrom-scratchinference-enginekimi-k3linear-attentionllmllm-inferencemachine-learningmemory-efficientmixture-of-expertsmoemxfp4quantizationsimdsystems-programmingtransformerzero-dependencies
docs: add runnable examples
FareedKhan-dev8f185442d954
diff --git a/examples/01-hello.sh b/examples/01-hello.shnew file mode 100644index 0000000..aad6e56--- /dev/null+++ b/examples/01-hello.sh@@ -0,0 +1,16 @@+#!/usr/bin/env bash+# The smallest useful run: text in, text out.+#+# examples/01-hello.sh ~/k3model ~/k3trunk+#+# Note the model has no chat template, so it CONTINUES the prompt rather than replying+# to it. "Hello! My name is" gets completed, not answered. That is expected.+set -euo pipefail+MODEL="${1:?usage: 01-hello.sh <model_dir> <trunk_dir>}"+TRUNK="${2:?}"++./bin/k3 "$MODEL" \+ --trunk "$TRUNK" --preset server \+ --tok "$MODEL" \+ --prompt "Hello! My name is" \+ --gen 24 --incrementaldiff --git a/examples/02-memory-budgets.sh b/examples/02-memory-budgets.shnew file mode 100644index 0000000..2fe6175--- /dev/null+++ b/examples/02-memory-budgets.sh@@ -0,0 +1,30 @@+#!/usr/bin/env bash+# Run the same prompt at three very different memory budgets and diff the output.+#+# examples/02-memory-budgets.sh ~/k3model ~/k3trunk+#+# The point of this example is that the token ids come out IDENTICAL. Memory buys speed,+# not capability.+set -euo pipefail+MODEL="${1:?usage: 02-memory-budgets.sh <model_dir> <trunk_dir>}"+TRUNK="${2:?}"+IDS=1008,10484,318,15383,387 # "The capital of France is"+OUT=$(mktemp -d)++for preset in laptop desktop server; do+ echo "=== $preset ==="+ ./bin/k3 "$MODEL" --trunk "$TRUNK" --preset "$preset" \+ --ids "$IDS" --gen 8 --incremental --out "$OUT/$preset.json" \+ | grep -E 's/token average|PEAK RSS'+done++echo+echo "=== token ids at each budget ==="+for preset in laptop desktop server; do+ printf '%-12s ' "$preset"+ python3 -c "import json,sys; print(json.load(open(sys.argv[1]))['generated_ids'])" \+ "$OUT/$preset.json"+done+echo+echo "If those three lines are not identical, that is a bug worth reporting."+rm -rf "$OUT"diff --git a/examples/03-long-prompt.sh b/examples/03-long-prompt.shnew file mode 100644index 0000000..07f6f28--- /dev/null+++ b/examples/03-long-prompt.sh@@ -0,0 +1,18 @@+#!/usr/bin/env bash+# Feed a file as the prompt instead of a command-line string.+#+# examples/03-long-prompt.sh ~/k3model ~/k3trunk somefile.txt+#+# Use --prompt-file rather than --prompt for anything non-ASCII: argv is re-encoded by+# the shell, so a UTF-8 string can reach the engine as different bytes than you typed.+#+# Be aware that prefill is not chunked and MLA attention is quadratic in sequence length,+# so a long file is slow. See docs/ROADMAP.md.+set -euo pipefail+MODEL="${1:?usage: 03-long-prompt.sh <model_dir> <trunk_dir> <file>}"+TRUNK="${2:?}"+FILE="${3:?}"++wc -c "$FILE"+./bin/k3 "$MODEL" --trunk "$TRUNK" --preset server \+ --tok "$MODEL" --prompt-file "$FILE" --gen 16 --incremental