guanwenyu1995 commited on
Commit
e99b139
Β·
verified Β·
1 Parent(s): 689ba6e

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +131 -0
README.md ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - zh
5
+ - en
6
+ pipeline_tag: text-generation
7
+ library_name: transformers
8
+ ---
9
+ <div align="center">
10
+ <img src="https://github.com/OpenBMB/MiniCPM/blob/main/assets/minicpm_logo.png?raw=true" width="500em" ></img>
11
+ </div>
12
+
13
+ <p align="center">
14
+ <a href="https://github.com/OpenBMB/MiniCPM/" target="_blank">GitHub Repo</a> |
15
+ <a href="TODO_TECHNICAL_REPORT_LINK" target="_blank">Technical Report</a>
16
+ </p>
17
+ <p align="center">
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
+ ## Introduction
22
+
23
+ BitCPM4-CANN-1B-unquantized is the **unquantized QAT training checkpoint** of the BitCPM4-CANN-1B model. This model stores the raw quantization-aware training (QAT) parameters **before** fake-quantizer fusionβ€”the ternary fake quantizers are defined in `modeling.py` and applied during forward propagation.
24
+
25
+ > ⚠️ **This model is NOT intended for direct inference.** It is designed as the starting point for fine-tuning BitCPM4-CANN. If you need a model for inference, please use the pseudo-quantized version: [openbmb/BitCPM4-CANN-0.5B](https://huggingface.co/openbmb/BitCPM4-CANN-0.5B).
26
+
27
+ ### Key Characteristics
28
+
29
+ - 🎯 **Purpose**: Fine-tuning only. The model weights are un-fused QAT parameters with fake quantizers embedded in the `modeling.py` forward logic.
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
+ ## BitCPM4-CANN Model Family
34
+
35
+ | Model | HuggingFace (Inference) | HuggingFace (Fine-tuning) |
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
+ ## Usage
43
+
44
+ ### Fine-tuning
45
+
46
+ This model is designed for fine-tuning with frameworks that support custom modeling code. The critical requirement is that **the forward pass must go through the `modeling.py` file bundled with this model**, which contains the ternary fake quantizer logic. This ensures the model parameters remain compatible with ternary quantization constraints throughout fine-tuning.
47
+
48
+ #### Supported Fine-tuning Frameworks
49
+
50
+ - **DeepSpeed** (recommended): See [MiniCPM Fine-tuning Guide](https://github.com/OpenBMB/MiniCPM/tree/main/finetune)
51
+ - **LLaMA Factory**: Supports custom model loading with `trust_remote_code=True`
52
+ - **Other Frameworks**: Any framework that supports HuggingFace-compatible model loading with custom modeling code
53
+
54
+ #### Important: Ensure Fake Quantizer is Active
55
+
56
+ When fine-tuning, you **must** ensure:
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-0.5B-unquantized'
64
+ tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
65
+ model = AutoModelForCausalLM.from_pretrained(
66
+ path,
67
+ torch_dtype=torch.bfloat16,
68
+ trust_remote_code=True
69
+ )
70
+
71
+ # Proceed with your fine-tuning pipeline (DeepSpeed, LLaMA Factory, etc.)
72
+ # The ternary fake quantizer in modeling.py will be applied automatically during forward pass.
73
+ ```
74
+
75
+ ### Post-Fine-tuning Conversion
76
+
77
+ After fine-tuning is complete, use the `qat-convert.py` script to fuse the fake quantizer and produce the pseudo-quantized model weights that can be used for inference:
78
+
79
+ ```bash
80
+ python qat-convert.py \
81
+ --input_bin <path-to-finetuned-pytorch.bin> \
82
+ --output <path-to-output-pseudo-quantized-pytorch.bin> \
83
+ --quant_type ternary \
84
+ --group_size -1
85
+ ```
86
+
87
+ The converted model can then be loaded for inference in the same way as [openbmb/BitCPM4-CANN-0.5B](https://huggingface.co/openbmb/BitCPM4-CANN-0.5B)β€”no special quantization libraries required.
88
+
89
+ ## Workflow Summary
90
+
91
+ ```
92
+ β”Œβ”€οΏ½οΏ½οΏ½β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
93
+ β”‚ BitCPM4-CANN-1B-unquantized β”‚ ← This model (QAT parameters + fake quantizer in modeling.py)
94
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
95
+ β”‚
96
+ β–Ό Fine-tune (DeepSpeed / LLaMA Factory / ...)
97
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
98
+ β”‚ Fine-tuned pytorch.bin β”‚ ← Still contains un-fused QAT parameters
99
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
100
+ β”‚
101
+ β–Ό python qat-convert.py --quant_type ternary --group_size -1
102
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
103
+ β”‚ Pseudo-quantized pytorch.bin β”‚ ← Ready for inference (same format as BitCPM4-CANN-0.5B)
104
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
105
+ ```
106
+
107
+ ## Technical Background
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
+ For full technical details, please refer to our [Technical Report](TODO_TECHNICAL_REPORT_LINK).
112
+
113
+ ## Statement
114
+ - As a language model, BitCPM4-CANN generates content by learning from a vast amount of text.
115
+ - However, it does not possess the ability to comprehend or express personal opinions or value judgments.
116
+ - Any content generated by BitCPM4-CANN does not represent the viewpoints or positions of the model developers.
117
+ - Therefore, when using content generated by BitCPM4-CANN, users should take full responsibility for evaluating and verifying it on their own.
118
+
119
+ ## LICENSE
120
+ - This repository and BitCPM4-CANN models are released under the [Apache-2.0](https://github.com/OpenBMB/MiniCPM/blob/main/LICENSE) License.
121
+
122
+ ## Citation
123
+ - Please cite our technical report if you find our work valuable.
124
+
125
+ ```bibtex
126
+ @article{bitcpm4cann,
127
+ title={{BitCPM-CANN}: Native 1.58-Bit Large Language Model Training on Ascend NPU},
128
+ author={BitCPM Team},
129
+ year={2026}
130
+ }
131
+ ```