# Kinetic + BitNet (bitnet.cpp) Use Microsoft **[bitnet.cpp](https://github.com/microsoft/BitNet)** as Kinetic’s **Language Reasoner** for 1.58-bit LLM inference on CPU (GPU kernels available upstream). ## Why this fits “light + high performance” | Property | How Kinetic uses it | |----------|---------------------| | 1.58-bit weights | Ternary BitNet; official lossless kernels | | CPU speedups | Upstream reports ~1.4–6×; large energy savings | | Event-only | BitNet runs on **new instruction / replan**, never in the control loop | | Compact context | Prompt = system rules + `WorldState.summary_for_llm()` | | Fallback | Rule reasoner if BitNet is missing | Control / policy / vision stay separate — BitNet only emits **intent JSON**. --- ## Two official scripts (do not confuse `-p`) | Script | Purpose | `-p` means | `-n` means | |--------|---------|------------|------------| | `run_inference.py` | Real text generation / chat | **Text prompt** (string) | Tokens to generate | | `utils/e2e_benchmark.py` | Throughput / latency bench | **Prompt token count** (int, default 512) | Generated tokens (default 128) | Kinetic **reasoning** uses `run_inference.py`. Kinetic **`bitnet-bench`** uses `e2e_benchmark.py`. --- ## Local repo (this project) Kinetic expects BitNet at: ```text F:\Kinetic\BitNet ``` Lightweight defaults: **short JSON prompts**, `n_predict=64`, `ctx_size=1024`, prefer **Falcon-E-1B** (then 0.7B large, then 2B). ### One-shot setup (recommended) ```powershell # Prefer VS2022 Developer PowerShell (clang + MSVC toolset) cd F:\Kinetic powershell -ExecutionPolicy Bypass -File scripts\setup_bitnet_light.ps1 # Optional: -Model BitNetLarge | BitNet2B ``` This runs submodule init, `setup_env.py` for a small HF model, cmake build, and points `configs/bitnet.yaml` at the GGUF. ## Official install (bitnet.cpp) — manual **Requirements:** Python ≥ 3.9, CMake ≥ 3.22, Clang ≥ 18. **Windows:** always use a **VS 2022 Developer** Command Prompt / PowerShell. ```powershell cd F:\Kinetic\BitNet git submodule update --init --recursive pip install huggingface_hub # Lightest instruct option python setup_env.py -hr tiiuae/Falcon-E-1B-Instruct -md models -q i2_s -p ``` ### Inference smoke test (`run_inference.py`) ```powershell python run_inference.py -m models/BitNet-b1.58-2B-4T/ggml-model-i2_s.gguf -p "You are a helpful assistant" -cnv ``` ### Convert from `.safetensors` (bf16 checkpoint) ```powershell huggingface-cli download microsoft/bitnet-b1.58-2B-4T-bf16 --local-dir ./models/bitnet-b1.58-2B-4T-bf16 python ./utils/convert-helper-bitnet.py ./models/bitnet-b1.58-2B-4T-bf16 ``` --- ## Official e2e benchmark (`utils/e2e_benchmark.py`) Setup the environment for running inference benchmarks. ### Arguments | Flag | Meaning | Default | |------|---------|---------| | `-m, --model` | **Required.** Path to model GGUF | — | | `-n, --n-token` | Number of **generated** tokens | 128 | | `-p, --n-prompt` | Number of **prompt** tokens (not text!) | 512 | | `-t, --threads` | Thread count | 2 | | `-h, --help` | Help | — | ### Examples ```powershell # Real model python utils/e2e_benchmark.py -m /path/to/model.gguf -n 200 -p 256 -t 4 # Dummy model (kernel layout not in a public HF model) python utils/generate-dummy-bitnet-model.py models/bitnet_b1_58-large ` --outfile models/dummy-bitnet-125m.tl1.gguf --outtype tl1 --model-size 125M python utils/e2e_benchmark.py -m models/dummy-bitnet-125m.tl1.gguf -p 512 -n 128 ``` ### Via Kinetic CLI (wrapper) ```powershell # After setting KINETIC_BITNET_REPO / model_path python -m kinetic.cli bitnet-bench -m F:\BitNet\models\BitNet-b1.58-2B-4T\ggml-model-i2_s.gguf -n 128 -p 512 -t 4 # Or from config python -m kinetic.cli bitnet-bench --config configs/bitnet.yaml -n 200 -p 256 -t 8 ``` Use benchmark numbers to pick `threads` / model size for **replan latency**, not control-loop Hz. --- ## Wire into Kinetic ### Config (`configs/bitnet.yaml`) ```yaml language: backend: bitnet bitnet: repo_dir: F:/BitNet model_path: F:/BitNet/models/BitNet-b1.58-2B-4T/ggml-model-i2_s.gguf threads: 8 n_predict: 128 temperature: 0.1 strict: false ``` ### Environment ```powershell $env:KINETIC_BITNET_REPO = "F:\BitNet" $env:KINETIC_BITNET_MODEL = "F:\BitNet\models\BitNet-b1.58-2B-4T\ggml-model-i2_s.gguf" ``` ### Run ```powershell cd F:\Kinetic python -m pip install -e ".[dev]" python -m kinetic.cli bitnet-info --config configs/bitnet.yaml python -m kinetic.cli reason -i "Pick up the blue bottle" --config configs/bitnet.yaml --json python -m kinetic.cli bitnet-bench --config configs/bitnet.yaml -n 128 -p 256 -t 4 python -m kinetic.demos.pick_bottle --config configs/bitnet.yaml ``` --- ## Architecture placement ``` User instruction │ ▼ (event only) BitNet b1.58 (run_inference.py) → GoalSpec JSON │ ▼ Task Planner → World Model → Policy → Controller → Robot ``` **Never** call BitNet every control tick. --- ## FAQ (from upstream BitNet + Kinetic notes) ### Q1: Build dies in llama.cpp `log.cpp` / `std::chrono`? Known llama.cpp integration issue. Check BitNet GitHub discussions for the referenced commit fix (upstream BitNet FAQ Q1). ### Q2: Clang / conda on Windows — `'clang' is not recognized`? Your shell is not initialized for VS tools. Verify: ```powershell clang -v ``` **Command Prompt:** ```bat "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=x64 -host_arch=x64 ``` (Use `Community` or `Enterprise` instead of `Professional` if that is your edition.) **PowerShell:** ```powershell Import-Module "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" Enter-VsDevShell -SkipAutomaticLocation -DevCmdArguments "-arch=x64 -host_arch=x64" ``` Then rebuild BitNet from that shell. ### Q3: Kinetic falls back to rules without error? Set `language.bitnet.strict: true`, or run `kinetic reason ...` and inspect `bitnet_error` / `backend`. ### Q4: Benchmark works but reason returns garbage? - Bench only measures kernels (`-p` is token **count**). - Reasoning needs a real instruct GGUF + `run_inference.py` with a **text** `-p`. - Keep temperature low (0.1) and ask for JSON only (Kinetic’s prompt already does). --- ## Performance tuning for Kinetic | Knob | Suggested for replan | Notes | |------|----------------------|--------| | Model | 2B (`BitNet-b1.58-2B-4T`) | 0.7B if RAM-limited | | `threads` | physical cores | Measure with `bitnet-bench -t …` | | `n_predict` / `-n` | 64–128 | Short JSON only | | Replan rate | < 1–2 Hz events | Not 20 Hz control | | Bench `-p` | 256–512 | Approximates world-summary size | --- ## References - [microsoft/BitNet](https://github.com/microsoft/BitNet) — bitnet.cpp - `utils/e2e_benchmark.py`, `utils/generate-dummy-bitnet-model.py`, `utils/convert-helper-bitnet.py` - Technical reports in the BitNet README (1-bit AI Infra, BitNet b1.58, GPU kernels)