Instructions to use openbmb/BitCPM-CANN-8B-unquantized with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openbmb/BitCPM-CANN-8B-unquantized with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openbmb/BitCPM-CANN-8B-unquantized", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("openbmb/BitCPM-CANN-8B-unquantized", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use openbmb/BitCPM-CANN-8B-unquantized with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openbmb/BitCPM-CANN-8B-unquantized" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openbmb/BitCPM-CANN-8B-unquantized", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/openbmb/BitCPM-CANN-8B-unquantized
- SGLang
How to use openbmb/BitCPM-CANN-8B-unquantized 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 "openbmb/BitCPM-CANN-8B-unquantized" \ --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": "openbmb/BitCPM-CANN-8B-unquantized", "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 "openbmb/BitCPM-CANN-8B-unquantized" \ --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": "openbmb/BitCPM-CANN-8B-unquantized", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use openbmb/BitCPM-CANN-8B-unquantized with Docker Model Runner:
docker model run hf.co/openbmb/BitCPM-CANN-8B-unquantized
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -18,49 +18,41 @@ library_name: transformers
|
|
| 18 |
π Join us on <a href="https://discord.gg/3cGQn9b3YM" target="_blank">Discord</a> and <a href="https://github.com/OpenBMB/MiniCPM/blob/main/assets/wechat.jpg" target="_blank">WeChat</a>
|
| 19 |
</p>
|
| 20 |
|
| 21 |
-
##
|
| 22 |
|
| 23 |
-
BitCPM4-CANN-
|
| 24 |
|
| 25 |
-
> β οΈ **This model is NOT
|
| 26 |
|
| 27 |
-
##
|
| 28 |
|
| 29 |
-
|
| 30 |
-
- π¬ **Ternary Fake Quantizer**: The forward pass in `modeling.py` contains ternary quantization logic (mapping weights to {-1, 0, 1} with group-wise scaling), which ensures the model continues learning under ternary constraints during fine-tuning.
|
| 31 |
-
- π **Post-Training Conversion**: After fine-tuning, the model can be converted to pseudo-quantized format using the provided `qat-convert.py` script.
|
| 32 |
|
| 33 |
-
##
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|-------|-------------------------|---------------------------|
|
| 37 |
-
| BitCPM4-CANN-0.5B | [openbmb/BitCPM4-CANN-0.5B](https://huggingface.co/openbmb/BitCPM4-CANN-0.5B) | [openbmb/BitCPM4-CANN-0.5B-unquantized](https://huggingface.co/openbmb/BitCPM4-CANN-0.5B-unquantized) |
|
| 38 |
-
| BitCPM4-CANN-1B | [openbmb/BitCPM4-CANN-1B](https://huggingface.co/openbmb/BitCPM4-CANN-1B) | [openbmb/BitCPM4-CANN-1B-unquantized](https://huggingface.co/openbmb/BitCPM4-CANN-1B-unquantized) |
|
| 39 |
-
| BitCPM4-CANN-3B | [openbmb/BitCPM4-CANN-3B](https://huggingface.co/openbmb/BitCPM4-CANN-3B) | [openbmb/BitCPM4-CANN-3B-unquantized](https://huggingface.co/openbmb/BitCPM4-CANN-3B-unquantized) |
|
| 40 |
-
| BitCPM4-CANN-8B | [openbmb/BitCPM4-CANN-8B](https://huggingface.co/openbmb/BitCPM4-CANN-8B) | [openbmb/BitCPM4-CANN-8B-unquantized](https://huggingface.co/openbmb/BitCPM4-CANN-8B-unquantized) |
|
| 41 |
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
|
| 54 |
-
###
|
| 55 |
|
| 56 |
-
|
| 57 |
-
1. Load the model with `trust_remote_code=True` so that the custom `modeling.py` (containing the ternary quantizer) is used.
|
| 58 |
-
2. The forward pass during training goes through the ternary quantizer defined in `modeling.py`βdo NOT replace or bypass the model's forward logic.
|
| 59 |
|
| 60 |
```python
|
| 61 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 62 |
|
| 63 |
-
path = 'openbmb/BitCPM4-CANN-
|
| 64 |
tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
|
| 65 |
model = AutoModelForCausalLM.from_pretrained(
|
| 66 |
path,
|
|
@@ -68,13 +60,13 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 68 |
trust_remote_code=True
|
| 69 |
)
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
# The ternary fake quantizer in modeling.py
|
| 73 |
```
|
| 74 |
|
| 75 |
-
##
|
| 76 |
|
| 77 |
-
After
|
| 78 |
|
| 79 |
```bash
|
| 80 |
python qat-convert.py \
|
|
@@ -84,31 +76,34 @@ python qat-convert.py \
|
|
| 84 |
--group_size -1
|
| 85 |
```
|
| 86 |
|
| 87 |
-
The converted model can
|
| 88 |
|
| 89 |
-
## Workflow
|
| 90 |
|
| 91 |
```
|
| 92 |
βββββββββββββββββββββββββββββββββββ
|
| 93 |
-
β BitCPM4-CANN-
|
| 94 |
βββββββββββββββββ¬ββββββββββββββββββ
|
| 95 |
β
|
| 96 |
-
βΌ
|
| 97 |
βββββββββββββββββββββββββββββββββββ
|
| 98 |
-
β Fine-tuned
|
| 99 |
βββββββββββββββββ¬ββββββββββββββββββ
|
| 100 |
β
|
| 101 |
βΌ python qat-convert.py --quant_type ternary --group_size -1
|
| 102 |
βββββββββββββββββββββββββββββββββββ
|
| 103 |
-
β Pseudo-quantized
|
| 104 |
βββββββββββββββββββββββββββββββββββ
|
| 105 |
```
|
| 106 |
|
| 107 |
-
##
|
| 108 |
-
|
| 109 |
-
BitCPM4-CANN uses a ternary quantizer that maps each weight group to {-1, 0, 1} scaled by a group-wise factor, trained with Straight-Through Estimator (STE) for gradient flow. The unquantized checkpoint preserves the full-precision latent weights alongside the quantizer parameters, allowing the model to continue learning under quantization constraints during fine-tuning.
|
| 110 |
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
## Statement
|
| 114 |
- As a language model, BitCPM4-CANN generates content by learning from a vast amount of text.
|
|
|
|
| 18 |
π Join us on <a href="https://discord.gg/3cGQn9b3YM" target="_blank">Discord</a> and <a href="https://github.com/OpenBMB/MiniCPM/blob/main/assets/wechat.jpg" target="_blank">WeChat</a>
|
| 19 |
</p>
|
| 20 |
|
| 21 |
+
## Overview
|
| 22 |
|
| 23 |
+
BitCPM4-CANN-1B-unquantized is the **unquantized QAT (Quantization-Aware Training) checkpoint** of BitCPM4-CANN-1B, designed for **continued pre-training and fine-tuning**. It preserves full-precision latent weights with ternary fake quantizers (weights β {-1, 0, 1} with group-wise scaling, trained via STE) defined in `modeling.py`, enabling the model to keep learning under quantization constraints. For technical details, see our [Technical Report](https://github.com/OpenBMB/MiniCPM/blob/main/docs/BitCPM_CANN.pdf).
|
| 24 |
|
| 25 |
+
> β οΈ **This model is NOT for direct inference.** For inference, use the pseudo-quantized version: [openbmb/BitCPM4-CANN-1B](https://huggingface.co/openbmb/BitCPM4-CANN-1B).
|
| 26 |
|
| 27 |
+
## Continued Pre-training & Fine-tuning
|
| 28 |
|
| 29 |
+
The **only requirement** is that the forward pass must go through the bundled `modeling.py` (which contains the ternary fake quantizer). Load with `trust_remote_code=True` and do NOT replace or bypass the model's forward logic.
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
### Option 1: DeepSpeed (Recommended)
|
| 32 |
|
| 33 |
+
We provide ready-to-use training scripts in the [example](https://huggingface.co/openbmb/BitCPM4-CANN-1B-unquantized/tree/main/example) directory (using the 1B model as an example):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
- **Continued pre-training**: `example/run.sh` + `example/train.py`
|
| 36 |
+
- **SFT (Supervised Fine-tuning)**: `example/run_sft.sh` + `example/train_sft.py`
|
| 37 |
|
| 38 |
+
Quick start:
|
| 39 |
|
| 40 |
+
```bash
|
| 41 |
+
# Continued pre-training
|
| 42 |
+
cd example && bash run.sh
|
| 43 |
|
| 44 |
+
# Supervised fine-tuning
|
| 45 |
+
cd example && bash run_sft.sh
|
| 46 |
+
```
|
| 47 |
|
| 48 |
+
### Option 2: HuggingFace-compatible Frameworks
|
| 49 |
|
| 50 |
+
Any framework that supports HuggingFace model loading with custom code can be used, such as **LLaMA Factory**, **HuggingFace Trainer**, etc. The key is to ensure `trust_remote_code=True`:
|
|
|
|
|
|
|
| 51 |
|
| 52 |
```python
|
| 53 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 54 |
|
| 55 |
+
path = 'openbmb/BitCPM4-CANN-1B-unquantized'
|
| 56 |
tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
|
| 57 |
model = AutoModelForCausalLM.from_pretrained(
|
| 58 |
path,
|
|
|
|
| 60 |
trust_remote_code=True
|
| 61 |
)
|
| 62 |
|
| 63 |
+
# Use with your preferred framework (LLaMA Factory, HF Trainer, etc.)
|
| 64 |
+
# The ternary fake quantizer in modeling.py is applied automatically during forward pass.
|
| 65 |
```
|
| 66 |
|
| 67 |
+
## Post-Training Conversion
|
| 68 |
|
| 69 |
+
After training, use `qat-convert.py` to fuse the fake quantizer and produce inference-ready pseudo-quantized weights:
|
| 70 |
|
| 71 |
```bash
|
| 72 |
python qat-convert.py \
|
|
|
|
| 76 |
--group_size -1
|
| 77 |
```
|
| 78 |
|
| 79 |
+
The converted model can be loaded for inference in the same way as [openbmb/BitCPM4-CANN-1B](https://huggingface.co/openbmb/BitCPM4-CANN-1B)βno special quantization libraries required.
|
| 80 |
|
| 81 |
+
## Workflow
|
| 82 |
|
| 83 |
```
|
| 84 |
βββββββββββββββββββββββββββββββββββ
|
| 85 |
+
β BitCPM4-CANN-1B-unquantized β β This model (QAT checkpoint + fake quantizer in modeling.py)
|
| 86 |
βββββββββββββββββ¬ββββββββββββββββββ
|
| 87 |
β
|
| 88 |
+
βΌ Train (DeepSpeed / LLaMA Factory / HF Trainer / ...)
|
| 89 |
βββββββββββββββββββββββββββββββββββ
|
| 90 |
+
β Fine-tuned checkpoint β β Still contains un-fused QAT parameters
|
| 91 |
βββββββββββββββββ¬ββββββββββββββββββ
|
| 92 |
β
|
| 93 |
βΌ python qat-convert.py --quant_type ternary --group_size -1
|
| 94 |
βββββββββββββββββββββββββββββββββββ
|
| 95 |
+
β Pseudo-quantized model β β Ready for inference (same format as BitCPM4-CANN-1B)
|
| 96 |
βββββββββββββββββββββββββββββββββββ
|
| 97 |
```
|
| 98 |
|
| 99 |
+
## BitCPM4-CANN Model Family
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
| Model | HuggingFace (Inference) | HuggingFace (Fine-tuning) |
|
| 102 |
+
|-------|-------------------------|---------------------------|
|
| 103 |
+
| BitCPM4-CANN-0.5B | [openbmb/BitCPM4-CANN-0.5B](https://huggingface.co/openbmb/BitCPM4-CANN-0.5B) | [openbmb/BitCPM4-CANN-0.5B-unquantized](https://huggingface.co/openbmb/BitCPM4-CANN-0.5B-unquantized) |
|
| 104 |
+
| BitCPM4-CANN-1B | [openbmb/BitCPM4-CANN-1B](https://huggingface.co/openbmb/BitCPM4-CANN-1B) | [openbmb/BitCPM4-CANN-1B-unquantized](https://huggingface.co/openbmb/BitCPM4-CANN-1B-unquantized) |
|
| 105 |
+
| BitCPM4-CANN-3B | [openbmb/BitCPM4-CANN-3B](https://huggingface.co/openbmb/BitCPM4-CANN-3B) | [openbmb/BitCPM4-CANN-3B-unquantized](https://huggingface.co/openbmb/BitCPM4-CANN-3B-unquantized) |
|
| 106 |
+
| BitCPM4-CANN-8B | [openbmb/BitCPM4-CANN-8B](https://huggingface.co/openbmb/BitCPM4-CANN-8B) | [openbmb/BitCPM4-CANN-8B-unquantized](https://huggingface.co/openbmb/BitCPM4-CANN-8B-unquantized) |
|
| 107 |
|
| 108 |
## Statement
|
| 109 |
- As a language model, BitCPM4-CANN generates content by learning from a vast amount of text.
|