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.


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.index with 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:

  1. Unpack I2_S bytes ([M/4, K]) using shifts 0, 2, 4, 6.
  2. Map codes to ternary values and multiply by weight_scale.
  3. Re-quantize each row with a refined F16 scale.
  4. Write safetensors plus qnm.index and 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
Safetensors
Model size
0.9B params
Tensor type
BF16
Β·
U8
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support