Instructions to use kousw/bitnet_b1_58-3B_quantized with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use kousw/bitnet_b1_58-3B_quantized with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="kousw/bitnet_b1_58-3B_quantized")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("kousw/bitnet_b1_58-3B_quantized") model = AutoModelForCausalLM.from_pretrained("kousw/bitnet_b1_58-3B_quantized", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use kousw/bitnet_b1_58-3B_quantized with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "kousw/bitnet_b1_58-3B_quantized" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kousw/bitnet_b1_58-3B_quantized", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/kousw/bitnet_b1_58-3B_quantized
- SGLang
How to use kousw/bitnet_b1_58-3B_quantized 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 "kousw/bitnet_b1_58-3B_quantized" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kousw/bitnet_b1_58-3B_quantized", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "kousw/bitnet_b1_58-3B_quantized" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kousw/bitnet_b1_58-3B_quantized", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use kousw/bitnet_b1_58-3B_quantized with Docker Model Runner:
docker model run hf.co/kousw/bitnet_b1_58-3B_quantized
| import argparse | |
| import torch | |
| from modeling_bitnet import BitnetForCausalLM | |
| from tokenization_bitnet import BitnetTokenizer | |
| torch.set_grad_enabled(False) | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--hf_path", default="1bitLLM/bitnet_b1_58-3B", type=str) | |
| parser.add_argument("--output_path", default="./bitnet_b1_58-3B_quantized", type=str) | |
| def main(args): | |
| model = BitnetForCausalLM.from_pretrained( | |
| args.hf_path, | |
| device_map="auto", | |
| low_cpu_mem_usage=True, | |
| use_flash_attention_2=True, | |
| torch_dtype=torch.float16, | |
| ).half() | |
| tokenizer = BitnetTokenizer.from_pretrained(args.hf_path, use_fast=False) | |
| model.quantize() | |
| model.save_pretrained(args.output_path, max_shard_size="5GB") | |
| print("Quantized model saved to", args.output_path) | |
| if __name__ == "__main__": | |
| args = parser.parse_args() | |
| main(args) | |