microsoft-bitnet-b1-58-2b-4t
Version: 6
BitNet b1.58 2B4T - Scaling Native 1-bit LLM
This repository contains the weights for BitNet b1.58 2B4T, the first open-source, native 1-bit Large Language Model (LLM) at the 2-billion parameter scale, developed by Microsoft Research. Trained on a corpus of 4 trillion tokens, this model demonstrates that native 1-bit LLMs can achieve performance comparable to leading open-weight, full-precision models of similar size, while offering substantial advantages in computational efficiency (memory, energy, latency). ➡️ Technical Report: BitNet b1.58 2B4T Technical Report ➡️ Official Inference Code: microsoft/BitNet (bitnet.cpp)Model Variants
Several versions of the model weights are available on Hugging Face:-
microsoft/bitnet-b1.58-2B-4T(This repository): Contains the packed 1.58-bit weights optimized for efficient inference. Use this for deployment. -
microsoft/bitnet-b1.58-2B-4T-bf16: Contains the master weights in BF16 format. Use this only for training or fine-tuning purposes. -
microsoft/bitnet-b1.58-2B-4T-gguf: Contains the model weights in GGUF format, compatible with thebitnet.cpplibrary for CPU inference.
Model Details
- Architecture: Transformer-based, modified with
BitLinearlayers (BitNet framework).- Uses Rotary Position Embeddings (RoPE).
- Uses squared ReLU (ReLU²) activation in FFN layers.
- Employs
sublnnormalization. - No bias terms in linear or normalization layers.
- Quantization: Native 1.58-bit weights and 8-bit activations (W1.58A8).
- Weights are quantized to ternary values {-1, 0, +1} using absmean quantization during the forward pass.
- Activations are quantized to 8-bit integers using absmax quantization (per-token).
- Crucially, the model was trained from scratch with this quantization scheme, not post-training quantized.
- Parameters: ~2 Billion
- Training Tokens: 4 Trillion
- Context Length: Maximum sequence length of 4096 tokens.
- Recommendation: For optimal performance on tasks requiring very long contexts (beyond the pre-training length or for specialized long-reasoning tasks), we recommend performing intermediate long-sequence adaptation/training before the final fine-tuning stage.
- Training Stages:
- Pre-training: Large-scale training on public text/code and synthetic math data using a two-stage learning rate and weight decay schedule.
- Supervised Fine-tuning (SFT): Fine-tuned on instruction-following and conversational datasets using sum loss aggregation and specific hyperparameter tuning.
- Direct Preference Optimization (DPO): Aligned with human preferences using preference pairs.
- Tokenizer: LLaMA 3 Tokenizer (vocab size: 128,256).
How to Use (with transformers)
VERY IMPORTANT NOTE ON EFFICIENCY
Please do NOT expect performance efficiency gains (in terms of speed, latency, or energy consumption) when using this model with the standard transformers library, even with the required fork. The current execution paths within transformers do not contain the specialized, highly optimized computational kernels required to leverage the advantages of the BitNet architecture. Running the model via transformers will likely result in inference speeds and energy usage comparable to, or potentially worse than, standard full-precision models within this framework on both CPU and GPU. While you might observe reduced memory usage due to the quantized weights, the primary computational efficiency benefits are not accessible through this standard transformers usage path. For achieving the efficiency benefits demonstrated in the technical paper, you MUST use the dedicated C++ implementation: bitnet.cpp .
Requirements
pip install git+https://github.com/huggingface/transformers.git@096f25ae1f501a084d8ff2dcaf25fbc2bd60eba4
Example
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "microsoft/bitnet-b1.58-2B-4T"
# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16
)
# Apply the chat template
messages = [
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": "How are you?"},
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
chat_input = tokenizer(prompt, return_tensors="pt").to(model.device)
# Generate response
chat_outputs = model.generate(**chat_input, max_new_tokens=50)
response = tokenizer.decode(chat_outputs[0][chat_input['input_ids'].shape[-1]:], skip_special_tokens=True) # Decode only the response part
print("\nAssistant Response:", response)
How to Use (with bitnet.cpp)
Please refer to the bitnet.cpp GitHub repository for detailed compilation steps, usage examples, and command-line options.
Evaluation
BitNet b1.58 2B4T was evaluated against leading open-weight full-precision LLMs of similar size. Below are the key results (all models are instruction-tuned versions):| Benchmark | LLaMA 3.2 1B | Gemma-3 1B | Qwen2.5 1.5B | SmolLM2 1.7B | MiniCPM 2B | BitNet b1.58 2B |
|---|---|---|---|---|---|---|
| Memory (Non-emb) | 2GB | 1.4GB | 2.6GB | 3.2GB | 4.8GB | 0.4GB |
| Latency (CPU Decoding) | 48ms | 41ms | 65ms | 67ms | 124ms | 29ms |
| Energy (Estimated) | 0.258J | 0.186J | 0.347J | 0.425J | 0.649J | 0.028J |
| Training Tokens (Pre-train) | 9T* | 2T** | 18T | 11T | 1.1T | 4T |
| ARC-Challenge | 37.80 | 38.40 | 46.67 | 43.52 | 44.80 | 49.91 |
| ARC-Easy | 63.17 | 63.13 | 76.01 | 62.92 | 72.14 | 74.79 |
| OpenbookQA | 34.80 | 38.80 | 40.80 | 46.00 | 40.20 | 41.60 |
| BoolQ | 64.65 | 74.22 | 78.04 | 75.78 | 80.67 | 80.18 |
| HellaSwag | 60.80 | 57.69 | 68.28 | 71.71 | 70.81 | 68.44 |
| PIQA | 74.21 | 71.93 | 76.12 | 76.12 | 76.66 | 77.09 |
| WinoGrande | 59.51 | 58.48 | 62.83 | 68.98 | 61.80 | 71.90 |
| CommonsenseQA | 58.48 | 42.10 | 76.41 | 63.55 | 71.74 | 71.58 |
| TruthfulQA | 43.80 | 38.66 | 46.67 | 39.90 | 41.41 | 45.31 |
| TriviaQA | 37.60 | 23.49 | 38.37 | 45.97 | 34.13 | 33.57 |
| MMLU | 45.58 | 39.91 | 60.25 | 49.24 | 51.82 | 53.17 |
| HumanEval+ | 31.10 | 37.20 | 50.60 | 28.00 | 43.90 | 38.40 |
| GSM8K | 38.21 | 31.16 | 56.79 | 45.11 | 4.40 | 58.38 |
| MATH-500 | 23.00 | 42.00 | 53.00 | 17.60 | 14.80 | 43.40 |
| IFEval | 62.71 | 66.67 | 50.12 | 57.91 | 36.81 | 53.48 |
| MT-bench | 5.43 | 6.40 | 6.12 | 5.50 | 6.57 | 5.85 |
| Average | 44.90 | 43.74 | 55.23 | 48.70 | 42.05 | 54.19 |
License
The model weights and code are released under the MIT License .Bias, Risks, and Limitations
Predictions may perpetuate biases present in the training data. There is limited support for non-English languages and underrepresented domains. There is a risk of generating inaccurate or harmful content. The Bitnet model has an elevated defect rate when responding to election-critical queries, which may result in incorrect or unauthoritative election critical information being presented. We are working to improve the model's performance in this area. Users should verify information related to elections with the election authority in their region.Disclaimer
We do not recommend using BitNet b1.58 in commercial or real-world applications without further testing and development. This model is intended for research and development purposes. While efforts have been made to align it using SFT and DPO, it may still produce outputs that are unexpected, biased, or inaccurate. Please use responsibly.microsoft/bitnet-b1.58-2B-4T powered by Hugging Face Inference Toolkit
Send Request
You can use cURL or any REST Client to send a request to the AzureML endpoint with your AzureML token.curl <AZUREML_ENDPOINT_URL> \
-X POST \
-d '{"inputs":"System: You are a helpful assistant that responds like a pirate<|eot_id|>User: What is Deep Learning?<|eot_id|>Assistant: ","parameters":{"max_new_tokens":10,"seed":42}}' \
-H "Authorization: Bearer <AZUREML_TOKEN>" \
-H "Content-Type: application/json"
Supported Parameters
Find below the parameters that control the length of the output:- max_length: The maximum length the generated tokens can have. Corresponds to the length of the input prompt + max_new_tokens. Its effect is overridden by max_new_tokens, if also set. Defaults to 20.
- max_new_tokens: The maximum numbers of tokens to generate, ignoring the number of tokens in the prompt.
- min_length: The minimum length of the sequence to be generated. Corresponds to the length of the input prompt + min_new_tokens. Its effect is overridden by min_new_tokens, if also set. Defaults to 0.
- min_new_tokens: The minimum numbers of tokens to generate, ignoring the number of tokens in the prompt.
- early_stopping: Controls the stopping condition for beam-based methods, like beam-search. It accepts the following values: True, where the generation stops as soon as there are num_beams complete candidates; False, where an heuristic is applied and the generation stops when is it very unlikely to find better candidates; "never", where the beam search procedure only stops when there cannot be better candidates (canonical beam search algorithm). Defaults to False.
- max_time: The maximum amount of time you allow the computation to run for in seconds. generation will still finish the current pass after allocated time has been passed.
- stop_strings: A string or a list of strings that should terminate generation if the model outputs them.
- do_sample: Whether or not to use sampling; use greedy decoding otherwise. Defaults to False.
- num_beams: Number of beams for beam search, 1 means no beam search. Defaults to 1.
- num_beam_groups: Number of groups to divide num_beams into in order to ensure diversity among different groups of beams. Defaults to 1.
- penalty_alpha: The values balance the model confidence and the degeneration penalty in contrastive search decoding.
- temperature: The value used to modulate the next token probabilities. Defaults to 1.0.
- top_k: The number of highest probability vocabulary tokens to keep for top-k-filtering. Defaults to 50.
- top_p: If set to a float < 1, only the smallest set of most probable tokens with probabilities that add up to top_p or higher are kept for generation. Defaults to 1.0.
- min_p: Minimum token probability, scaled by the probability of the most likely token. Typical values are between 0.01 and 0.2.
- typical_p: Controls local typicality, keeping the smallest set of the most locally typical tokens whose probabilities add up to typical_p or higher. Defaults to 1.0.
- epsilon_cutoff: If set to a float strictly between 0 and 1, only tokens with a conditional probability greater than epsilon_cutoff will be sampled. Defaults to 0.0.
- eta_cutoff: Hybrid of locally typical sampling and epsilon sampling. If set to a float strictly between 0 and 1, a token is only considered if it meets the eta_cutoff threshold. Defaults to 0.0.
- diversity_penalty: Subtracted from a beam’s score if it generates a token already generated by another group at a particular time. Only effective if group beam search is enabled. Defaults to 0.0.
- repetition_penalty: The parameter for repetition penalty. 1.0 means no penalty. Defaults to 1.0.
- encoder_repetition_penalty: Exponential penalty on sequences not in the original input. 1.0 means no penalty. Defaults to 1.0.
- length_penalty: Exponential penalty to the sequence length used with beam-based generation. >0.0 promotes longer sequences, <0.0 encourages shorter sequences. Defaults to 1.0.
- no_repeat_ngram_size: If set to an integer > 0, all ngrams of that size can only occur once. Defaults to 0.
- bad_words_ids: List of lists of token ids that are not allowed to be generated.
- force_words_ids: List of token ids that must be generated. Can be a simple list or a disjunctive constraint for multiple forms.
- renormalize_logits: Whether to renormalize the logits after applying all logits processors. Defaults to False.
- constraints: Custom constraints to ensure the output contains certain tokens as defined by Constraint objects.
- forced_bos_token_id: The id of the token to force as the first generated token after the decoder start token. Useful for multilingual models.
- forced_eos_token_id: The id of the token to force as the last generated token when max_length is reached. Can be a list for multiple end-of-sequence tokens.
- remove_invalid_values: Whether to remove possible NaN and inf outputs to prevent the generation method from crashing. May slow down generation.
- exponential_decay_length_penalty: Tuple (start_index, decay_factor) adding an exponentially increasing length penalty after a certain number of tokens.
- suppress_tokens: List of tokens that will be suppressed during generation.
- begin_suppress_tokens: List of tokens that will be suppressed at the beginning of generation.
- forced_decoder_ids: List of pairs indicating a mapping from generation indices to token indices that will be forced before sampling.
- sequence_bias: Dictionary mapping a sequence of tokens to its bias term. Positive biases increase, negative biases decrease the odds of selection.
- token_healing: Heal tail tokens of prompts by replacing them with their appropriate extensions. Defaults to False.
- guidance_scale: The guidance scale for classifier-free guidance (CFG). CFG is enabled by setting guidance_scale > 1.
- low_memory: Switch to sequential beam search and sequential top-k for contrastive search to reduce peak memory.
- watermarking_config: Arguments used to watermark the model outputs by adding a small bias to a randomly selected set of tokens. If passed as a dict, it will be converted internally.
Example payload
{
"inputs": "System: You are a helpful assistant that responds like a pirate<|eot_id|>User: What is Deep Learning?<|eot_id|>Assistant: ",
"parameters": {
"max_new_tokens": 10,
"do_sample": true,
"temperature": 0.8
}
}
Model Specifications
LicenseMit
Last UpdatedJuly 2025
ProviderHuggingFace