BitCPM4-CANN-1B-unquantized 是 BitCPM4-CANN-1B 模型的未量化 QAT 训练检查点。该模型存储的是伪量化器融合之前的原始量化感知训练(QAT)参数——三元伪量化器在 modeling.py 中定义,并在正向传播过程中应用。
⚠️ 本模型不适合直接用于推理。它设计为 BitCPM4-CANN 微调的起点。如果您需要用于推理的模型,请使用伪量化版本:openbmb/BitCPM4-CANN-0.5B。
modeling.py 的正向逻辑中嵌入了伪量化器。modeling.py 中的正向传播包含三元量化逻辑(将权重映射到 {-1, 0, 1} 并进行分组缩放),确保模型在微调过程中继续在三元约束下学习。qat-convert.py 脚本将模型转换为伪量化格式。| 模型 | HuggingFace(推理) | HuggingFace(微调) |
|---|---|---|
| BitCPM4-CANN-0.5B | openbmb/BitCPM4-CANN-0.5B | openbmb/BitCPM4-CANN-0.5B-unquantized |
| BitCPM4-CANN-1B | openbmb/BitCPM4-CANN-1B | openbmb/BitCPM4-CANN-1B-unquantized |
| BitCPM4-CANN-3B | openbmb/BitCPM4-CANN-3B | openbmb/BitCPM4-CANN-3B-unquantized |
| BitCPM4-CANN-8B | openbmb/BitCPM4-CANN-8B | openbmb/BitCPM4-CANN-8B-unquantized |
该模型适用于支持自定义建模代码的框架进行微调。关键要求是前向传播必须通过与模型捆绑的modeling.py文件,该文件包含三元伪量化器逻辑。这可确保模型参数在整个微调过程中始终符合三元量化约束。
trust_remote_code=True加载自定义模型微调时,您必须确保:
trust_remote_code=True加载模型,以便使用包含三元量化器的自定义modeling.py。modeling.py中定义的三元量化器进行——不要替换或绕过模型的前向逻辑。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.微调完成后,使用qat-convert.py脚本融合伪量化器,并生成可用于推理的伪量化模型权重:
python qat-convert.py \
--input_bin <path-to-finetuned-pytorch.bin> \
--output <path-to-output-pseudo-quantized-pytorch.bin> \
--quant_type ternary \
--group_size -1转换后的模型可按照与 openbmb/BitCPM4-CANN-1B 相同的方式加载以进行推理,无需特殊的量化库。
┌─────────────────────────────────┐
│ BitCPM4-CANN-1B-unquantized │ ← This model (QAT parameters + fake quantizer in modeling.py)
└───────────────┬─────────────────┘
│
▼ Fine-tune (DeepSpeed / LLaMA Factory / ...)
┌─────────────────────────────────┐
│ Fine-tuned pytorch.bin │ ← Still contains un-fused QAT parameters
└───────────────┬─────────────────┘
│
▼ python qat-convert.py --quant_type ternary --group_size -1
┌─────────────────────────────────┐
│ Pseudo-quantized pytorch.bin │ ← Ready for inference (same format as BitCPM4-CANN-0.5B)
└─────────────────────────────────┘BitCPM4-CANN 采用三元量化器,通过逐组缩放因子将每个权重组映射到 {-1, 0, 1},并使用直通估计器(STE)进行梯度流训练。未量化的检查点保留了全精度潜在权重以及量化器参数,使模型能够在微调期间继续在量化约束下学习。
有关完整技术细节,请参阅我们的技术报告。
@article{bitcpm4cann,
title={{BitCPM-CANN}: Native 1.58-Bit Large Language Model Training on Ascend NPU},
author={BitCPM Team},
year={2026}
}