--- license: apache-2.0 language: - zh - en pipeline_tag: text-generation library_name: transformers ---
GitHub Repo | Technical Report
π Join us on Discord and WeChat
## Introduction 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. > β οΈ **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). ### Key Characteristics - π― **Purpose**: Fine-tuning only. The model weights are un-fused QAT parameters with fake quantizers embedded in the `modeling.py` forward logic. - π¬ **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. - π **Post-Training Conversion**: After fine-tuning, the model can be converted to pseudo-quantized format using the provided `qat-convert.py` script. ## BitCPM4-CANN Model Family | Model | HuggingFace (Inference) | HuggingFace (Fine-tuning) | |-------|-------------------------|---------------------------| | 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) | | 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) | | 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) | | 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) | ## Usage ### Fine-tuning 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. #### Supported Fine-tuning Frameworks - **DeepSpeed** (recommended): See [MiniCPM Fine-tuning Guide](https://github.com/OpenBMB/MiniCPM/tree/main/finetune) - **LLaMA Factory**: Supports custom model loading with `trust_remote_code=True` - **Other Frameworks**: Any framework that supports HuggingFace-compatible model loading with custom modeling code #### Important: Ensure Fake Quantizer is Active When fine-tuning, you **must** ensure: 1. Load the model with `trust_remote_code=True` so that the custom `modeling.py` (containing the ternary quantizer) is used. 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. ```python from transformers import AutoModelForCausalLM, AutoTokenizer path = 'openbmb/BitCPM4-CANN-1B-unquantized' tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained( path, torch_dtype=torch.bfloat16, trust_remote_code=True ) # Proceed with your fine-tuning pipeline (DeepSpeed, LLaMA Factory, etc.) # The ternary fake quantizer in modeling.py will be applied automatically during forward pass. ``` ### Post-Fine-tuning Conversion 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: ```bash python qat-convert.py \ --input_bin