Instructions to use WiTi4Bit/bitnet-b1.58-2B-4T-qnm with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use WiTi4Bit/bitnet-b1.58-2B-4T-qnm with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="WiTi4Bit/bitnet-b1.58-2B-4T-qnm", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("WiTi4Bit/bitnet-b1.58-2B-4T-qnm", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("WiTi4Bit/bitnet-b1.58-2B-4T-qnm", trust_remote_code=True, device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use WiTi4Bit/bitnet-b1.58-2B-4T-qnm with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "WiTi4Bit/bitnet-b1.58-2B-4T-qnm" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "WiTi4Bit/bitnet-b1.58-2B-4T-qnm", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/WiTi4Bit/bitnet-b1.58-2B-4T-qnm
- SGLang
How to use WiTi4Bit/bitnet-b1.58-2B-4T-qnm with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "WiTi4Bit/bitnet-b1.58-2B-4T-qnm" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "WiTi4Bit/bitnet-b1.58-2B-4T-qnm", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "WiTi4Bit/bitnet-b1.58-2B-4T-qnm" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "WiTi4Bit/bitnet-b1.58-2B-4T-qnm", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use WiTi4Bit/bitnet-b1.58-2B-4T-qnm with Docker Model Runner:
docker model run hf.co/WiTi4Bit/bitnet-b1.58-2B-4T-qnm
WiTi BitNet QNM β BitNet b1.58 2B4T (q1r)
This repository contains a converted QNM/q1r version of the Microsoft BitNet-b1.58-2B-4T model. It is an alternative format for running the model without the GGUF/GGML ecosystem used by the official bitnet.cpp implementation.
This is a technical conversion and local-runtime experiment. It makes no claim of superiority, higher speed, higher accuracy, or replacement of the official implementation.
- Journal article: https://zenodo.org/records/24452780
- Runtime and source code: https://github.com/WiTi4Bit/WiTiBitNet
Model description
BitNet b1.58 is a QAT (quantization-aware trained) language model with ternary
weights {-1, 0, +1}. The original released weights use the packed I2_S
format: four 2-bit values per uint8 byte, with one BF16 scale per tensor.
This model stores the same weights in QNM q1r format:
one row = [f16 scale][K/4 bytes of 2-bit codes]
codes (LSB-first): 0 = -1, 1 = 0, 2 = +1
The row-wise scale is initialized as mean(|w|) and refined with three
least-squares iterations before being stored as float16.
| Item | Value |
|---|---|
| Parameters | ~2.4 B |
| Layers | 30 |
| Hidden size | 2560 |
| Intermediate size | 6912 |
| Attention | GQA, 20 query / 5 KV heads, head_dim 128 |
| Context length | 4096 |
| RoPE theta | 500000 |
| Activation | ReLUΒ² |
| RMSNorm eps | 1e-5 |
| Vocabulary | 128256 (ByteLevel BPE, LLaMA 3 tokenizer) |
| Weight format | QNM q1r, 2-bit ternary, row-wise F16 scale |
Files
model.safetensorsβ 332 tensors: 210 q1r weights and 122 BF16 tensors (norms and tied embedding).config.json,tokenizer.json,tokenizer_config.json,special_tokens_map.json,generation_config.jsonβ copied from the original model so the folder can be used directly by the runtime.- Safetensors metadata contains
qnm.indexwith shape, scale, block size, and mode for every tensor.
Approximate size: 1.18 GB, comparable to the original I2_S file (1.179 GB) and about 130 MB smaller than a block-wise q1m variant (1.31 GB).
Conversion pipeline
The converter bitnet_to_qnm1bit.py performs:
- Unpack I2_S bytes (
[M/4, K]) using shifts 0, 2, 4, 6. - Map codes to ternary values and multiply by
weight_scale. - Re-quantize each row with a refined F16 scale.
- Write safetensors plus
qnm.indexand copy tokenizer/config files.
Usage
With the native C runtime from the source repository:
# Build (requires AVX2 + FMA)
./build.sh
# Top-5 verification
./qnm_chat_bitnet /path/to/this/model --token 1
# Generation
./qnm_chat_bitnet /path/to/this/model \
--tokens 128000,3923,374,279,6864,315,9822,30 --gen -n 32
# GUI chat
cd gui_native && ./run.sh
The Python reference runtime also supports q1r:
python3 bitnet_runtime.py /path/to/this/model \
--prompt "What is the capital of France?" --max-new-tokens 4
Local measurements
Measured on one machine (Intel Core i5-1235U, 12 threads, Debian GNU/Linux 13,
GCC 14.2.0, -O3 -mavx2 -mfma, single inference thread):
| Metric | Result |
|---|---|
| Decode speed | ~4.4β4.5 tokens/s |
| Prefill (8 tokens) | ~1.85 s |
| Top-5 logits (token 1) | 323, 304, 374, 311, 477 |
quantize_q16 parity |
bitwise identical to scalar reference |
Portable -msse2 build |
~2.0 tokens/s |
These are local measurements, not independent cross-platform benchmarks.
Limitations
- The source model is QAT BitNet; this format is not intended for arbitrary post-training-quantized 1-bit models.
- The model has limited support for non-English languages and may produce inaccurate answers.
- Greedy decoding can drift in topic; the runtime applies repetition penalty and 8-gram no-repeat blocking to reduce exact loops.
- Use for research, education, and local experimentation only.
License
- Original model weights and code: MIT β Copyright (c) Microsoft Corporation.
- QNM/q1r conversion, metadata, and this card: CC BY-NC 4.0.
- WiTi BitNet runtime/software: POKDARTIK-NC (non-commercial).
- Journal article: CC BY 4.0 on Zenodo.
The original MIT notice is retained; this license applies only to the conversion and additions made by this project.
Citation
Sulistiowati, Erni. (2026). WiTi BitNet: An Alternative QNM-Based Conversion Pipeline and Chat Runtime for BitNet AI Models. Zenodo, v1. DOI: 10.5281/zenodo.24452780. https://zenodo.org/records/24452780
- Downloads last month
- 38