Text Generation
Transformers
Safetensors
English
bitnet
chat
large-language-model
conversational
custom_code
8-bit precision
Run this model with HF Jobs
Run microsoft/bitnet-b1.58-2B-4T on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/microsoft/bitnet-b1.58-2B-4T. Ask me which dataset to train on, then push the LoRA adapter to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs and Transformers to run batch inference with https://huggingface.co/microsoft/bitnet-b1.58-2B-4T on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the predictions back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs and Lighteval to evaluate https://huggingface.co/microsoft/bitnet-b1.58-2B-4T. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/microsoft/bitnet-b1.58-2B-4T with Transformers and bitsandbytes. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use microsoft/bitnet-b1.58-2B-4T with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/bitnet-b1.58-2B-4T with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="microsoft/bitnet-b1.58-2B-4T", 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("microsoft/bitnet-b1.58-2B-4T", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("microsoft/bitnet-b1.58-2B-4T", 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 microsoft/bitnet-b1.58-2B-4T with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/bitnet-b1.58-2B-4T" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/bitnet-b1.58-2B-4T", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/microsoft/bitnet-b1.58-2B-4T
- SGLang
How to use microsoft/bitnet-b1.58-2B-4T 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 "microsoft/bitnet-b1.58-2B-4T" \ --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": "microsoft/bitnet-b1.58-2B-4T", "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 "microsoft/bitnet-b1.58-2B-4T" \ --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": "microsoft/bitnet-b1.58-2B-4T", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use microsoft/bitnet-b1.58-2B-4T with Docker Model Runner:
docker model run hf.co/microsoft/bitnet-b1.58-2B-4T
Add Hugging Face paper link and clarify repos
#13
by nielsr HF Staff - opened
1234567891011121314152 unmodified lines1819202122232473 unmodified lines989910010110210310436 unmodified lines141142143144---license: mitlicense_link: https://huggingface.co/microsoft/bitnet-b1.58-2B-4T/blob/main/LICENSElanguage:- enpipeline_tag: text-generationtags:- chat- bitnet- text-generation- large-language-modellibrary_name: transformers---# BitNet b1.58 2B4T - Scaling Native 1-bit LLM2 unmodified linesTrained 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](https://arxiv.org/abs/2504.12285)➡️ **Official Inference Code:** [microsoft/BitNet (bitnet.cpp)](https://github.com/microsoft/BitNet)73 unmodified lines# Generate responsechat_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 partprint("\nAssistant Response:", response)```## How to Use (with `bitnet.cpp`)36 unmodified linesThe model weights and code are released under the [MIT License](https://huggingface.co/microsoft/bitnet-b1.58-2B-4T/blob/main/LICENSE).## DisclaimerThis 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.1234567891011121314152 unmodified lines1819202122232473 unmodified lines989910010110210310410536 unmodified lines142143144145---language:- enlibrary_name: transformerslicense: mitlicense_link: https://huggingface.co/microsoft/bitnet-b1.58-2B-4T/blob/main/LICENSEpipeline_tag: text-generationtags:- chat- bitnet- text-generation- large-language-model---# BitNet b1.58 2B4T - Scaling Native 1-bit LLM2 unmodified linesTrained 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](https://arxiv.org/abs/2504.12285) ➡️ **Hugging Face Paper:** [Hugging Face Paper](https://huggingface.co/papers/2504.12285)➡️ **Official Inference Code:** [microsoft/BitNet (bitnet.cpp)](https://github.com/microsoft/BitNet)73 unmodified lines# Generate responsechat_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 partprint("Assistant Response:", response)```## How to Use (with `bitnet.cpp`)36 unmodified linesThe model weights and code are released under the [MIT License](https://huggingface.co/microsoft/bitnet-b1.58-2B-4T/blob/main/LICENSE).## DisclaimerThis 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.
README.md+7-6