In this article, you will learn what 1.58-bit BitNet models are, how to run BitNet b1.58 2B4T on a laptop CPU with bitnet.cpp, and how to benchmark it against a 4-bit Qwen2.5-1.5B on speed, memory, and agent-style tasks. Topics we will cover include: What ternary, 1.58-bit weights are, and how Microsoft’s published numbers compare BitNet with 4-bit quantized models. How to build bitnet.cpp, serve BitNet and a Q4_K_M Qwen2.5-1.5B side by side, and compare them with one Python script. Where a tiny CPU model is good enough for agent work, such as classification and tool-call extraction, and where it falls short. In late September, two small projects reached Hacker News in the same week. One spreads a ternary language model across seven ESP32-S3 microcontrollers. The other, MicroLLM Lab, lets you run seven tiny LLMs in a browser tab, and both appeared in a Hacker News digest for September 29. Neither needs a GPU and both point at the same question: how small can a useful local model get? The most mature answer so far is BitNet, Microsoft’s family of 1-bit LLMs. KDnuggets already has a good beginner guide to running BitNet locally that covers building bitnet.cpp on Linux, chatting with the 2B model, and connecting it to the OpenAI Python SDK. This guide starts where that one stops. Once the model runs, the real questions are how it compares with an ordinary 4-bit quantized model, and which jobs it can handle. You will learn what “1.58-bit” means, how to run BitNet b1.58 2B4T on a laptop CPU with bitnet.cpp, and how to run a 4-bit Qwen2.5-1.5B next to it. Then you will measure both on speed, memory, classification and tool-call extraction with one Python script, using Microsoft’s published numbers as the reference. Finally you will see where a tiny CPU model is good enough for an agent, and where it isn’t. What “1.58-Bit” Means A normal LLM stores each weight as a 16-bit number. A 4-bit quantized model takes that trained model and rounds the weights to 16 possible values after training. BitNet restricts every weight to three values, -1, 0 and +1, and trains that way from the start. Three states carry about 1.58 bits of information (log2 of 3), which is where the name comes from. The difference between rounding afterward and training that way matters. The technical report describes BitNet b1.58 2B4T as trained from scratch on 4 trillion tokens, with ternary weights (absmean quantization) and 8-bit activations (absmax, per token), a scheme Microsoft abbreviates W1.58A8. Because the model learned to work within three values, it avoids much of the damage that post-training quantization causes. The model card warns that you should not expect speed or energy gains from the standard Transformers library, because it lacks the specialized kernels. You get the efficiency only through bitnet.cpp, Microsoft’s inference framework built on llama.cpp, whose kernels use lookup-table methods from T-MAC. Microsoft reports speedups of 2.37x to 6.17x on x86 CPUs and 1.37x to 5.07x on ARM, with larger models gaining more. Three rows of boxes showing the same row of weights stored as 16-bit floats, 4-bit integers, and ternary (click to enlarge) Image by Author What the Published Numbers Say Before running anything, it helps to know what Microsoft measured. The report’s comparison with 4-bit models uses Qwen2.5-1.5B, which is the pairing we use in this guide. The 4-bit versions were made with the two standard post-training methods, GPTQ and AWQ. Metric Qwen2.5-1.5B bf16 Qwen2.5-1.5B GPTQ-int4 Qwen2.5-1.5B AWQ-int4 BitNet b1.58 2B Memory (non-embedding) 2.6 GB 0.7 GB 0.7 GB 0.4 GB MMLU 60.25 58.06 57.43 53.17 GSM8K 56.79 50.57 50.64 58.38 IFEval 50.12 47.84 45.44 53.48 Average of the three 55.72 52.15 51.17 55.01 BitNet loses clearly on MMLU, a knowledge test, and wins on GSM8K math and IFEval instruction following. The 4-bit models lose a few points against their bf16 original. Against the 4-bit versions, BitNet comes out ahead on average and uses less memory. Speed is the other half. In the report’s main table, BitNet decodes at 29 ms per token against 65 ms for full-precision Qwen2.5-1.5B, roughly 34 versus 15 tokens per second. That was measured on a Core i7-13800H laptop with 8 threads, generating 128 tokens, with BitNet on bitnet.cpp and the others on llama.cpp. The same table lists an estimated 0.028 J per token against 0.347 J, but the appendix says that figure comes from an arithmetic energy model, not a power meter. The report does not give a speed for the INT4 models, so the head-to-head you care about is unpublished. The memory figures exclude the embedding table, and the files you download are closer in size: about 1.19 GB for the BitNet GGUF against about 0.99 GB for Qwen2.5-1.5B Q4_K_M. And these are Microsoft’s own runs. The script in Step 3 exists to fill the gap on your hardware. Prerequisites The bitnet.cpp README requires Python 3.10 or newer, CMake 3.22 or newer, and Clang 18 or newer, and recommends conda. On Windows, you need Visual Studio 2022 with the C++ and Clang options enabled, and every command must run in a Developer Command Prompt. Allow about 3 GB of disk space for both models. Install the two libraries the comparison script uses: pip install requests psutil requests sends chat requests to the two local servers, and psutil reads how much memory each server process is using. Step 1: Run BitNet With bitnet.cpp These commands follow the official README. Clone the repository with its submodules, create an environment, and install the dependencies: git clone --recursive https://github.com/microsoft/BitNet.gitcd BitNetconda create -n bitnet-cpp python=3.10conda activate bitnet-cpppip install -r requirements.txt Next, download the GGUF weights and build the kernels: huggingface-cli download microsoft/BitNet-b1.58-2B-4T-gguf --local-dir models/BitNet-b1.58-2B-4Tpython setup_env.py -md models/BitNet-b1.58-2B-4T -q i2_s –recursive also pulls the submodules, including the llama.cpp code bitnet.cpp builds on. The download command fetches the model in GGUF format, which is the file type bitnet.cpp reads. setup_env.py compiles the project for your CPU, and -q i2_s selects the I2_S kernel, which the README lists as supported for this model on both x86 and ARM. If the build fails with an int8_t * y_col error, KDnuggets documents a one-line sed fix, and the README FAQ covers other build errors. Test it in chat mode, then start the server the comparison script will talk to: python run_inference.py -m models/BitNet-b1.58-2B-4T/ggml-model-i2_s.gguf -p "You are a helpful assistant" -cnvpython run_inference_server.py -m models/BitNet-b1.58-2B-4T/ggml-model-i2_s.gguf --host 127.0.0.1 --port 8080 -t 8 -c 2048 In the first command, -m points to the model, -p sets the system prompt, and -cnv turns on conversation mode, as the README describes. The second command starts an OpenAI-compatible server. -t 8 sets 8 CPU threads, -c 2048 sets the context size, and 127.0.0.1 keeps the server reachable only from your own machine. Leave it running in its own terminal. Step 2: Run the 4-Bit Model With llama.cpp Install llama.cpp and download the 4-bit Qwen2.5-1.5B-Instruct file from bartowski’s GGUF repository: brew install llama.cpphuggingface-cli download bartowski/Qwen2.5-1.5B-Instruct-GGUF --include "Qwen2.5-1.5B-Instruct-Q4_K_M.gguf" --local-dir modelsllama-server -m models/Qwen2.5-1.5B-Instruct-Q4_K_M.gguf --port 8081 -t 8 -c 2048 Homebrew installs llama.cpp on macOS and Linux; on other systems, build it from its repository. The download command fetches one quantization of the model, Q4_K_M, a common 4-bit format. llama-server serves it on port 8081 with the same 8 threads and 2048-token context as BitNet, so the comparison is fair. Leave this running in a second terminal. Step 3: Measure Speed, Memory and Task Accuracy The script below sends the same requests to both servers. It measures tokens per second, reads each server’s memory use, and scores two small tasks that mirror real agent work: classifying support messages and turning a request into a JSON tool call. 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 # compare.py"""Compare two local llama.cpp-style servers on speed, memory and two small agent-style tasks."""import argparseimport jsonimport reimport statisticsimport timeimport psutilimport requestsCLASSIFY = [ ("I was charged twice for my last order.", "billing"), ("Please send me a copy of my invoice.", "billing"), ("My card was declined but the money left my account.", "billing"), ("Can I get a refund for the annual plan?", "billing"), ("Where is my package? It was due on Monday.", "shipping"), ("The tracking page has not updated in three days.", "shipping"), ("Can you change the delivery address on my order?", "shipping"), ("My order was delivered to the wrong building.", "shipping"), ("The app crashes every time I open settings.", "technical"), ("I cannot log in even after resetting my password.", "technical"), ("The export button does nothing when I click it.", "technical"), ("Your API returns a 500 error on every request.", "technical"),]CLASSIFY_SYSTEM = ("Classify the customer message as exactly one of: billing, shipping, technical. " "Reply with the single label and nothing else.")TOOL_CASES = [ ("Check the status of order A1002.", "lookup_order", {"order_id": "A1002"}), ("What is the status of order B2044?", "lookup_order", {"order_id": "B2044"}), ("Find the account for maya@example.com.", "lookup_account", {"email": "maya@example.com"}), ("Pull up the account of dan@example.com.", "lookup_account", {"email": "dan@example.com"}), ("Refund order A1005 for 20 dollars.", "issue_refund", {"order_id": "A1005", "amount": 20}), ("Please refund $35.50 on order C3001.", "issue_refund", {"order_id": "C3001", "amount": 35.5}),]TOOL_SYSTEM = """You convert a request into one tool call. Tools:lookup_order(order_id), lookup_account(email), issue_refund(order_id, amount)Reply with JSON only, like {"tool": "lookup_order", "args": {"order_id": "A1001"}}"""SPEED_PROMPT = "Explain in four sentences why the sky is blue."def chat(base, system, user, max_tokens): """One chat request. Returns the reply text, the generated token count and the seconds taken.""" body = {"model": "local", "temperature": 0, "max_tokens": max_tokens, "messages": [{"role": "system", "content": system}, {"role": "user", "content": user}]} start = time.perf_counter() reply = requests.post(f"{base}/v1/chat/completions", json=body, timeout=300) reply.raise_for_status() seconds = time.perf_counter() - start data = reply.json() text = data["choices"][0]["message"]["content"] tokens = data.get("usage", {}).get("completion_tokens") or len(text.split()) return text, tokens, secondsdef tokens_per_second(base): chat(base, "You are helpful.", SPEED_PROMPT, 16) # warm-up, not timed rates = [] for _ in range(3): _, tokens, seconds = chat(base, "You are helpful.", SPEED_PROMPT, 128) rates.append(tokens / seconds) return statistics.median(rates)def memory_gb(hint): """Resident memory of every process whose command line mentions the model file.""" total = 0 for proc in psutil.process_iter(["cmdline", "memory_info"]): if hint in " ".join(proc.info["cmdline"] or []): total += proc.info["memory_info"].rss return total / 1e9def classification_accuracy(base): hits = 0 for text, label in CLASSIFY: reply, _, _ = chat(base, CLASSIFY_SYSTEM, text, 8) first = re.findall(r"billing|shipping|technical", reply.lower()) hits += bool(first) and first[0] == label return hits / len(CLASSIFY)def norm(value): try: return float(str(value).lstrip("$")) except ValueError: return str(value).strip().lower()def tool_call_accuracy(base): hits = 0 for text, tool, args in TOOL_CASES: reply, _, _ = chat(base, TOOL_SYSTEM, text, 80) match = re.search(r"\{.*\}", reply, re.S) try: call = json.loads(match.group(0)) if match else {} got = {k: norm(v) for k, v in call.get("args", {}).items()} hits += call.get("tool") == tool and got == {k: norm(v) for k, v in args.items()} except (json.JSONDecodeError, AttributeError): pass return hits / len(TOOL_CASES)if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--bitnet", default="http://127.0.0.1:8080") parser.add_argument("--q4", default="http://127.0.0.1:8081") parser.add_argument("--bitnet-hint", default="ggml-model-i2_s") parser.add_argument("--q4-hint", default="Q4_K_M") args = parser.parse_args() rows = [("BitNet b1.58 2B4T", args.bitnet, args.bitnet_hint), ("Qwen2.5-1.5B Q4_K_M", args.q4, args.q4_hint)] print(f"{'model':22}{'tok/s':>8}{'RAM GB':>9}{'classify':>10}{'tool call':>11}") for name, base, hint in rows: speed = tokens_per_second(base) print(f"{name:22}{speed:>8.1f}{memory_gb(hint):>9.2f}" f"{classification_accuracy(base):>10.0%}{tool_call_accuracy(base):>11.0%}") CLASSIFY holds 12 labeled messages, and TOOL_CASES holds 6 requests with the exact tool and arguments each should produce. The chat function sends one request at temperature 0 to the OpenAI-compatible endpoint and returns the text, the generated token count, and the elapsed time. tokens_per_second makes one untimed warm-up call, then three timed 128-token generations, and reports the median. The figure includes prompt processing, so it runs slightly lower than a pure decoding rate, but the same applies to both models. memory_gb adds up the resident memory of every process whose command line contains the model file name, which is how it finds each server. classification_accuracy asks for a single label and takes the first valid label in the reply. tool_call_accuracy pulls the first JSON object out of the reply, since small models often wrap JSON in extra text, and checks the tool name and arguments. The norm helper treats 20, “20” and “$20.00” as equal. Run it with both servers up: The defaults match the ports and file names used above. If your model files have different names, pass –bitnet-hint and –q4-hint with a string from each command line. The output is one table with a row per model: tokens per second, memory in GB, classification accuracy and tool-call accuracy. Where Tiny Models Are Good Enough Microsoft’s own benchmarks suggest where the line sits. BitNet scores 80.18 on BoolQ, a yes-or-no reading test, above Qwen2.5-1.5B’s 78.04 and just under MiniCPM-2B’s 80.67, and its 53.48 on IFEval beats Qwen’s bf16 and INT4 versions, as the table above shows. Those are the skills that classification, routing and tool-call formatting lean on: pick a label, follow a format, stay on instructions. It falls short where knowledge and long reasoning matter. In the report’s main table, BitNet scores 33.57 on TriviaQA against 38.37 for Qwen2.5-1.5B, 38.40 on HumanEval+ against 50.60, and 43.40 on MATH-500 against 53.00. The context limit is 4,096 tokens, the model is English-focused, and the card notes an elevated defect rate on election-related questions. Microsoft also says it does not recommend BitNet b1.58 for commercial or real-world applications without further testing. That points to a practical agent design. NVIDIA researchers argue that small models are sufficiently powerful for many agent invocations, and that agents calling several different models are the natural fit when general conversation is needed. In practice, let the tiny model handle intent classification, field extraction and tool-call drafting, validate every output with plain code, and escalate failures to a larger model. Tiny does not mean automatically useful, though. The ESP32 cluster from the intro shows how far the memory budget bends, but its own write-up says the training script is unfinished and the model emits random tokens. Microsoft’s July release of BitNet embedding models at 0.6B and 270M parameters shows where the ecosystem is heading next. Troubleshooting If speed looks no better than a normal model, check that you ran the GGUF through bitnet.cpp, not Transformers. If the build fails, check the Clang and CMake versions against the prerequisites and read the README FAQ. If your numbers swing between runs, close other heavy programs and keep the thread count the same on both servers. Conclusion BitNet’s pitch holds up on paper: against 4-bit versions of a comparable model, Microsoft reports lower memory and a better average, plus faster decoding than full-precision peers. What the paper cannot tell you is how it behaves against a 4-bit model on your laptop, on your task. The script above answers that in a few minutes. Start with classification and tool-call extraction, add validation, and keep a larger model behind it for the cases a 2B model gets wrong. No comments yet.
Running 1-Bit LLMs Locally: A Practical Guide to BitNet Inference
Full Article
Original Source
Read the full article at Machinelearningmastery →KhanList aggregates and links to publicly available news content. We do not host full articles from third-party sources. Always verify important information with original sources.