初始化项目,由ModelHub XC社区提供模型
Model: OpenBMB/MiniCPM4.1-8B Source: Original Platform
This commit is contained in:
37
.gitattributes
vendored
Normal file
37
.gitattributes
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||
*.model filter=lfs diff=lfs merge=lfs -text
|
||||
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||
|
||||
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
||||
558
README.md
Normal file
558
README.md
Normal file
@@ -0,0 +1,558 @@
|
||||
---
|
||||
license: apache-2.0
|
||||
language:
|
||||
- zh
|
||||
- en
|
||||
pipeline_tag: text-generation
|
||||
library_name: transformers
|
||||
---
|
||||
<div align="center">
|
||||
<img src="https://github.com/OpenBMB/MiniCPM/blob/main/assets/minicpm_logo.png?raw=true" width="500em" ></img>
|
||||
</div>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/OpenBMB/MiniCPM/" target="_blank">GitHub Repo</a> |
|
||||
<a href="https://arxiv.org/abs/2506.07900" target="_blank">Technical Report</a> |
|
||||
<a href="https://mp.weixin.qq.com/s/KIhH2nCURBXuFXAtYRpuXg?poc_token=HBIsUWijxino8oJ5s6HcjcfXFRi0Xj2LJlxPYD9c">Join Us</a>
|
||||
</p>
|
||||
<p align="center">
|
||||
👋 Contact us in <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>
|
||||
</p>
|
||||
|
||||
## What's New
|
||||
- [2025.09.29] **[InfLLM-V2 paper](https://arxiv.org/abs/2509.24663) is released!** We can train a sparse attention model with only 5B long-text tokens. 🔥🔥🔥
|
||||
- [2025.09.05] **MiniCPM4.1** series are released! This series is a hybrid reasoning model with trainable sparse attention, which can be used in both deep reasoning mode and non-reasoning mode. 🔥🔥🔥
|
||||
- [2025.06.06] **MiniCPM4** series are released! This model achieves ultimate efficiency improvements while maintaining optimal performance at the same scale! It can achieve over 5x generation acceleration on typical end-side chips! You can find technical report [here](https://arxiv.org/abs/2506.07900).🔥🔥🔥
|
||||
|
||||
## Highlights
|
||||
MiniCPM4.1 is highlighted with following features:
|
||||
|
||||
✅ Strong Reasoning Capability: Surpasses similar-sized models on 15 tasks!
|
||||
|
||||
✅ Fast Generation: 3x decoding speedup for reasoning!
|
||||
|
||||
✅ Efficient Architecture: Trainable sparse attention, frequency-ranked speculative decoding!
|
||||
|
||||
- [MiniCPM4.1-8B](https://huggingface.co/openbmb/MiniCPM4.1-8B): The latest version of MiniCPM4, with 8B parameters, support fusion thinking. (**<-- you are here**)
|
||||
- [MiniCPM4.1-8B-GPTQ](https://huggingface.co/openbmb/MiniCPM4.1-8B-GPTQ): MiniCPM4.1-8B in GPTQ format.
|
||||
- [MiniCPM4.1-8B-AutoAWQ](https://huggingface.co/openbmb/MiniCPM4.1-8B-AutoAWQ): MiniCPM4.1-8B in AutoAWQ format.
|
||||
- [MiniCPM-4.1-8B-Marlin](https://huggingface.co/openbmb/MiniCPM-4.1-8B-Marlin): MiniCPM4.1-8B in Marlin format.
|
||||
- [MiniCPM4.1-8B-GGUF](https://huggingface.co/openbmb/MiniCPM4.1-8B-GGUF): MiniCPM4.1-8B in GGUF format.
|
||||
- [MiniCPM4.1-8B-MLX](https://huggingface.co/openbmb/MiniCPM4.1-8B-MLX): MiniCPM4.1-8B in MLX format.
|
||||
- [MiniCPM4.1-8B-Eagle3](https://huggingface.co/openbmb/MiniCPM4.1-8B-Eagle3): Eagle3 model for MiniCPM4.1-8B.
|
||||
- **MiniCPM4 Series**
|
||||
<details>
|
||||
<summary>Click to expand all MiniCPM4 series models</summary>
|
||||
|
||||
- [**MiniCPM4-8B**](https://huggingface.co/openbmb/MiniCPM4-8B): The flagship model with 8B parameters, trained on 8T tokens
|
||||
- [**MiniCPM4-0.5B**](https://huggingface.co/openbmb/MiniCPM4-0.5B): Lightweight version with 0.5B parameters, trained on 1T tokens
|
||||
- [**MiniCPM4-8B-Eagle-FRSpec**](https://huggingface.co/openbmb/MiniCPM4-8B-Eagle-FRSpec): Eagle head for FRSpec, accelerating speculative inference
|
||||
- [**MiniCPM4-8B-Eagle-FRSpec-QAT-cpmcu**](https://huggingface.co/openbmb/MiniCPM4-8B-Eagle-FRSpec-QAT-cpmcu): Eagle head with QAT for FRSpec, integrating speculation and quantization for ultra acceleration
|
||||
- [**MiniCPM4-8B-Eagle-vLLM**](https://huggingface.co/openbmb/MiniCPM4-8B-Eagle-vLLM): Eagle head in vLLM format for speculative inference
|
||||
- [**MiniCPM4-8B-marlin-Eagle-vLLM**](https://huggingface.co/openbmb/MiniCPM4-8B-marlin-Eagle-vLLM): Quantized Eagle head for vLLM format
|
||||
- [**BitCPM4-0.5B**](https://huggingface.co/openbmb/BitCPM4-0.5B): Extreme ternary quantization of MiniCPM4-0.5B, achieving 90% bit width reduction
|
||||
- [**BitCPM4-1B**](https://huggingface.co/openbmb/BitCPM4-1B): Extreme ternary quantization of MiniCPM3-1B, achieving 90% bit width reduction
|
||||
- [**MiniCPM4-Survey**](https://huggingface.co/openbmb/MiniCPM4-Survey): Generates trustworthy, long-form survey papers from user queries
|
||||
- [**MiniCPM4-MCP**](https://huggingface.co/openbmb/MiniCPM4-MCP): Integrates MCP tools to autonomously satisfy user requirements
|
||||
</details>
|
||||
|
||||
|
||||
## Evaluation Results
|
||||
|
||||
### Performance Evaluation
|
||||
MiniCPM4.1 launches end-side versions with 8B parameter scale, both achieving best-in-class performance in their respective categories.
|
||||
|
||||

|
||||
|
||||
### Best Practices
|
||||
1. It is advisable to use temperature=0.9, topp=0.95. And we suggest setting max_output_token to 65,536 tokens.
|
||||
2. For math problems, we recommend using "Please reason step by step, and put your final answer within \boxed{}."
|
||||
3. And for English multiple-choice questions, we recommend starting with "Answer the following multiple choice question. The last line of your response should be of the following format: 'ANSWER: $LETTER' (without quotes) where LETTER is one of ABCD. Think step by step before answering." And "你回答的最后一行必须是以下格式 '答案:$选项' (不带引号), 其中选项是ABCD之一。请在回答之前一步步思考" for Chinese MCQ.
|
||||
|
||||
### Efficiency Evaluation
|
||||
MiniCPM4.1 adopts sparse attention and speculative decoding to improve the inference efficiency. On RTX 4090, MiniCPM4.1 achieves 3x decoding speed improvement in reasoning.
|
||||
|
||||

|
||||
|
||||
#### Examples
|
||||
<div align="center">
|
||||
<a href="https://www.youtube.com/watch?v=VouXjLHKDUY"><img src="https://img.youtube.com/vi/VouXjLHKDUY/0.jpg", width=70%></a>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
## Usage
|
||||
MiniCPM 4.1 can be used with following frameworks: Huggingface Transformers, SGLang, vLLM, and CPM.cu. For the ultimate inference speed, we highly recommend CPM.cu.
|
||||
|
||||
MiniCPM4/MiniCPM4.1 supports both dense attention inference and sparse attention inference modes, where vLLM and SGLang currently only support dense inference mode. If you want to use sparse inference mode, please use Huggingface Transformers and CPM.cu.
|
||||
|
||||
- Dense attention inference: vLLM, SGLang, Huggingface Transformers
|
||||
- Sparse attention inference: Huggingface Transformers, CPM.cu
|
||||
|
||||
**To facilitate researches in sparse attention, we provide [InfLLM-V2 Training Kernels](https://github.com/OpenBMB/infllmv2_cuda_impl) and [InfLLM-V2 Inference Kernels](https://github.com/openbmb/cpm.cu).**
|
||||
|
||||
### Inference with Transformers
|
||||
MiniCPM4.1-8B requires `transformers>=4.56`.
|
||||
|
||||
- **Inference with Dense Attention**
|
||||
```python
|
||||
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||||
import torch
|
||||
torch.manual_seed(0)
|
||||
|
||||
path = 'openbmb/MiniCPM4.1-8B'
|
||||
device = "cuda"
|
||||
tokenizer = AutoTokenizer.from_pretrained(path)
|
||||
model = AutoModelForCausalLM.from_pretrained(path, torch_dtype=torch.bfloat16, device_map=device, trust_remote_code=True)
|
||||
|
||||
# User can directly use the chat interface
|
||||
# responds, history = model.chat(tokenizer, "Write an article about Artificial Intelligence.", temperature=0.7, top_p=0.7)
|
||||
# print(responds)
|
||||
|
||||
# User can also use the generate interface
|
||||
messages = [
|
||||
{"role": "user", "content": "Write an article about Artificial Intelligence."},
|
||||
]
|
||||
prompt_text = tokenizer.apply_chat_template(
|
||||
messages,
|
||||
tokenize=False,
|
||||
add_generation_prompt=True,
|
||||
)
|
||||
model_inputs = tokenizer([prompt_text], return_tensors="pt").to(device)
|
||||
|
||||
model_outputs = model.generate(
|
||||
**model_inputs,
|
||||
max_new_tokens=32768,
|
||||
top_p=0.95,
|
||||
temperature=0.6
|
||||
)
|
||||
output_token_ids = [
|
||||
model_outputs[i][len(model_inputs[i]):] for i in range(len(model_inputs['input_ids']))
|
||||
]
|
||||
|
||||
responses = tokenizer.batch_decode(output_token_ids, skip_special_tokens=True)[0]
|
||||
print(responses)
|
||||
```
|
||||
|
||||
- **Inference with Sparse Attention**
|
||||
MiniCPM4.1-8B supports `InfLLM v2`, a sparse attention mechanism designed for efficient long-sequence inference. It requires the [infllmv2_cuda_impl](https://github.com/OpenBMB/infllmv2_cuda_impl) library.
|
||||
|
||||
You can install it by running the following command:
|
||||
```bash
|
||||
git clone -b feature_infer https://github.com/OpenBMB/infllmv2_cuda_impl.git
|
||||
cd infllmv2_cuda_impl
|
||||
git submodule update --init --recursive
|
||||
pip install -e . # or python setup.py install
|
||||
```
|
||||
|
||||
To enable InfLLM v2, you need to add the `sparse_config` field in `config.json`:
|
||||
```json
|
||||
{
|
||||
...,
|
||||
"sparse_config": {
|
||||
"kernel_size": 32,
|
||||
"kernel_stride": 16,
|
||||
"init_blocks": 1,
|
||||
"block_size": 64,
|
||||
"window_size": 2048,
|
||||
"topk": 64,
|
||||
"use_nope": false,
|
||||
"dense_len": 8192
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
These parameters control the behavior of InfLLM v2:
|
||||
* `kernel_size` (default: 32): The size of semantic kernels.
|
||||
* `kernel_stride` (default: 16): The stride between adjacent kernels.
|
||||
* `init_blocks` (default: 1): The number of initial blocks that every query token attends to. This ensures attention to the beginning of the sequence.
|
||||
* `block_size` (default: 64): The block size for key-value blocks.
|
||||
* `window_size` (default: 2048): The size of the local sliding window.
|
||||
* `topk` (default: 64): The specifies that each token computes attention with only the top-k most relevant key-value blocks.
|
||||
* `use_nope` (default: false): Whether to use the NOPE technique in block selection for improved performance.
|
||||
* `dense_len` (default: 8192): Since Sparse Attention offers limited benefits for short sequences, the model can use standard (dense) attention for shorter texts. The model will use dense attention for sequences with a token length below `dense_len` and switch to sparse attention for sequences exceeding this length. Set this to `-1` to always use sparse attention regardless of sequence length.
|
||||
|
||||
- **Long Context Extension**
|
||||
MiniCPM4.1 natively supports context lengths of up to 65,536(64k) tokens. For conversations where the total length (including both input and output) significantly exceeds this limit, we recommend using RoPE scaling techniques for effective handling of long texts. We have validated the model's performance on context lengths of up to 131,072 tokens by modifying the LongRoPE factor.
|
||||
|
||||
You can apply the LongRoPE factor modification by modifying the model files. Specifically, in the `config.json` file, adjust the `rope_scaling` fields.
|
||||
```json
|
||||
{
|
||||
...,
|
||||
"rope_scaling": {
|
||||
"rope_type": "longrope",
|
||||
"long_factor": [0.9982316082870437, 1.033048153422584, 1.0749920956484724, 1.1255096879436193, 1.1863348602111476, 1.259543828902579, 1.3476188888731149, 1.4535223827776373, 1.5807816745852985, 1.7335856049489526, 1.9168922912975785, 2.1365471404135326, 2.3994084200118646, 2.713475511863602, 3.0880118452194134, 3.533650295140154, 4.062463396503134, 4.687974098908333, 5.425075306704039, 6.289818967956352, 7.29902962722721, 8.6357018163639, 10.210822723989212, 12.053807765671676, 14.193944598909404, 16.65780676784363, 19.463620727694074, 22.628311203524586, 26.150106147261315, 30.02526691405111, 34.23183327975347, 38.73811934094828, 43.502489489729555, 48.47627117965394, 53.61139491762471, 58.857366522037935, 64.16798299215064, 69.51359464319125, 74.86555458220285, 80.21497790341579, 85.55322183307433, 90.89611806932027, 96.26245306514224, 101.68269304046481, 107.18619510219668, 112.82253283014026, 118.63764063163615, 119.88866203644656, 120.9462882391725, 121.837565139014, 122.58663780572562, 123.2147719894291, 123.74049454862576, 124.17980424685767, 124.54641761955492, 124.85202548028222, 125.10654406389756, 125.31835105170659, 125.49450117164764, 125.64091910903052, 125.76256945356558, 125.86360463815589, 125.94749252260765, 126.01712561287873],
|
||||
"short_factor": [0.9982316082870437, 1.033048153422584, 1.0749920956484724, 1.1255096879436193, 1.1863348602111476, 1.259543828902579, 1.3476188888731149, 1.4535223827776373, 1.5807816745852985, 1.7335856049489526, 1.9168922912975785, 2.1365471404135326, 2.3994084200118646, 2.713475511863602, 3.0880118452194134, 3.533650295140154, 4.062463396503134, 4.687974098908333, 5.425075306704039, 6.289818967956352, 7.29902962722721, 8.6357018163639, 10.210822723989212, 12.053807765671676, 14.193944598909404, 16.65780676784363, 19.463620727694074, 22.628311203524586, 26.150106147261315, 30.02526691405111, 34.23183327975347, 38.73811934094828, 43.502489489729555, 48.47627117965394, 53.61139491762471, 58.857366522037935, 64.16798299215064, 69.51359464319125, 74.86555458220285, 80.21497790341579, 85.55322183307433, 90.89611806932027, 96.26245306514224, 101.68269304046481, 107.18619510219668, 112.82253283014026, 118.63764063163615, 119.88866203644656, 120.9462882391725, 121.837565139014, 122.58663780572562, 123.2147719894291, 123.74049454862576, 124.17980424685767, 124.54641761955492, 124.85202548028222, 125.10654406389756, 125.31835105170659, 125.49450117164764, 125.64091910903052, 125.76256945356558, 125.86360463815589, 125.94749252260765, 126.01712561287873],
|
||||
"original_max_position_embeddings": 65536
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Inference with [SGLang](https://github.com/sgl-project/sglang)
|
||||
|
||||
You can inference with SGLang using the standard mode and speculative decoding mode.
|
||||
|
||||
#### Speculative Decoding
|
||||
|
||||
For accelerated inference with speculative decoding, follow these steps:
|
||||
|
||||
##### 1. Download MiniCPM4.1 Draft Model
|
||||
|
||||
First, download the MiniCPM4.1 draft model:
|
||||
|
||||
```bash
|
||||
cd /your_path
|
||||
git clone https://huggingface.co/openbmb/MiniCPM4.1-8B-Eagle3
|
||||
```
|
||||
|
||||
##### 2. Install EAGLE3-Compatible SGLang
|
||||
|
||||
The EAGLE3 adaptation PR has been submitted. For now, use our repository for installation:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/LDLINGLINGLING/sglang.git
|
||||
cd sglang
|
||||
pip install -e "python[all]"
|
||||
```
|
||||
|
||||
##### 3. Launch SGLang Server with Speculative Decoding
|
||||
|
||||
Start the SGLang server with speculative decoding enabled:
|
||||
|
||||
```bash
|
||||
python -m sglang.launch_server \
|
||||
--model-path "openbmb/MiniCPM4.1-8B" \
|
||||
--host "127.0.0.1" \
|
||||
--port 30002 \
|
||||
--mem-fraction-static 0.9 \
|
||||
--speculative-algorithm EAGLE3 \
|
||||
--speculative-draft-model-path "your/path/MiniCPM4_1-8B-Eagle3-bf16" \
|
||||
--speculative-num-steps 3 \
|
||||
--speculative-eagle-topk 1 \
|
||||
--speculative-num-draft-tokens 32 \
|
||||
--temperature 0.7
|
||||
```
|
||||
|
||||
##### 4. Client Usage
|
||||
|
||||
The client usage remains the same for both standard and speculative decoding:
|
||||
|
||||
```python
|
||||
import openai
|
||||
|
||||
client = openai.Client(base_url=f"http://localhost:30002/v1", api_key="None")
|
||||
|
||||
response = client.chat.completions.create(
|
||||
model="openbmb/MiniCPM4.1-8B",
|
||||
messages=[
|
||||
{"role": "user", "content": "Write an article about Artificial Intelligence."},
|
||||
],
|
||||
temperature=0.6,
|
||||
max_tokens=32768,
|
||||
)
|
||||
|
||||
print(response.choices[0].message.content)
|
||||
```
|
||||
|
||||
Note: Make sure to update the port number in the client code to match the server port (30002 in the speculative decoding example).
|
||||
|
||||
##### Configuration Parameters
|
||||
|
||||
- `--speculative-algorithm EAGLE3`: Enables EAGLE3 speculative decoding
|
||||
- `--speculative-draft-model-path`: Path to the draft model for speculation
|
||||
- `--speculative-num-steps`: Number of speculative steps (default: 3)
|
||||
- `--speculative-eagle-topk`: Top-k parameter for EAGLE (default: 1)
|
||||
- `--speculative-num-draft-tokens`: Number of draft tokens (default: 32)
|
||||
- `--mem-fraction-static`: Memory fraction for static allocation (default: 0.9)
|
||||
|
||||
#### Standard Inference (Without Speculative Decoding)
|
||||
|
||||
For now, you need to install our forked version of SGLang.
|
||||
|
||||
```bash
|
||||
git clone -b openbmb https://github.com/OpenBMB/sglang.git
|
||||
cd sglang
|
||||
|
||||
pip install --upgrade pip
|
||||
pip install -e "python[all]"
|
||||
```
|
||||
|
||||
You can start the inference server by running the following command:
|
||||
|
||||
```bash
|
||||
python -m sglang.launch_server --model openbmb/MiniCPM4.1-8B --trust-remote-code --port 30000 --chat-template chatml
|
||||
```
|
||||
|
||||
Then you can use the chat interface by running the following command:
|
||||
|
||||
```python
|
||||
import openai
|
||||
|
||||
client = openai.Client(base_url=f"http://localhost:30000/v1", api_key="None")
|
||||
|
||||
response = client.chat.completions.create(
|
||||
model="openbmb/MiniCPM4.1-8B",
|
||||
messages=[
|
||||
{"role": "user", "content": "Write an article about Artificial Intelligence."},
|
||||
],
|
||||
temperature=0.6,
|
||||
max_tokens=32768,
|
||||
)
|
||||
|
||||
print(response.choices[0].message.content)
|
||||
```
|
||||
|
||||
### Inference with [vLLM](https://github.com/vllm-project/vllm)
|
||||
You can inference with vLLM using the standard mode and speculative decoding mode.
|
||||
|
||||
#### Speculative Decoding
|
||||
|
||||
For accelerated inference with speculative decoding using vLLM, follow these steps:
|
||||
|
||||
##### 1. Download MiniCPM4.1 Draft Model
|
||||
|
||||
First, download the MiniCPM4.1 draft model and change the `architectures` in config.json as `LlamaForCausalLM`.
|
||||
|
||||
```bash
|
||||
cd /your_path
|
||||
git clone https://huggingface.co/openbmb/MiniCPM4.1-8B-Eagle3
|
||||
```
|
||||
|
||||
##### 2. Install EAGLE3-Compatible vLLM
|
||||
|
||||
The EAGLE3 vLLM PR has been submitted. For now, use our repository for installation:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/LDLINGLINGLING/vllm.git
|
||||
cd vllm
|
||||
pip install -e .
|
||||
```
|
||||
|
||||
##### 3. Launch vLLM Server with Speculative Decoding
|
||||
|
||||
Start the vLLM inference server with speculative decoding enabled. Make sure to update the model path in the speculative-config to point to your downloaded MiniCPM4_1-8B-Eagle3-bf16 folder:
|
||||
|
||||
```bash
|
||||
VLLM_USE_V1=1 \
|
||||
vllm serve openbmb/MiniCPM4.1-8B \
|
||||
--seed 42 \
|
||||
--trust-remote-code \
|
||||
--speculative-config '{
|
||||
"model": "your/path/MiniCPM4_1-8B-Eagle3-bf16",
|
||||
"num_speculative_tokens": 3,
|
||||
"method": "eagle3",
|
||||
"draft_tensor_parallel_size": 1
|
||||
}'
|
||||
```
|
||||
|
||||
##### 4. Client Usage Example
|
||||
|
||||
The client usage remains the same for both standard and speculative decoding:
|
||||
|
||||
```python
|
||||
import openai
|
||||
|
||||
client = openai.Client(base_url="http://localhost:8000/v1", api_key="EMPTY")
|
||||
|
||||
response = client.chat.completions.create(
|
||||
model="openbmb/MiniCPM4.1-8B",
|
||||
messages=[
|
||||
{"role": "user", "content": "Write an article about Artificial Intelligence."},
|
||||
],
|
||||
temperature=0.6,
|
||||
max_tokens=32768,
|
||||
extra_body=dict(add_special_tokens=True), # Ensures special tokens are added for chat template
|
||||
)
|
||||
|
||||
print(response.choices[0].message.content)
|
||||
```
|
||||
|
||||
##### vLLM Configuration Parameters
|
||||
|
||||
- `VLLM_USE_V1=1`: Enables vLLM v1 API
|
||||
- `--speculative-config`: JSON configuration for speculative decoding
|
||||
- `model`: Path to the draft model for speculation
|
||||
- `num_speculative_tokens`: Number of speculative tokens (default: 3)
|
||||
- `method`: Speculative decoding method (eagle3)
|
||||
- `draft_tensor_parallel_size`: Tensor parallel size for draft model (default: 1)
|
||||
- `--seed`: Random seed for reproducibility
|
||||
- `--trust-remote-code`: Allow execution of remote code for custom models
|
||||
|
||||
#### Standard Inference (Without Speculative Decoding)
|
||||
|
||||
For now, you need to install the latest version of vLLM.
|
||||
|
||||
```bash
|
||||
pip install -U vllm \
|
||||
--pre \
|
||||
--extra-index-url https://wheels.vllm.ai/nightly
|
||||
```
|
||||
|
||||
Then you can inference MiniCPM4.1-8B with vLLM:
|
||||
```python
|
||||
from transformers import AutoTokenizer
|
||||
from vllm import LLM, SamplingParams
|
||||
|
||||
model_name = "openbmb/MiniCPM4.1-8B"
|
||||
prompt = [{"role": "user", "content": "Write an article about Artificial Intelligence."}]
|
||||
|
||||
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
||||
input_text = tokenizer.apply_chat_template(prompt, tokenize=False, add_generation_prompt=True)
|
||||
|
||||
llm = LLM(
|
||||
model=model_name,
|
||||
trust_remote_code=True,
|
||||
max_num_batched_tokens=65536,
|
||||
dtype="bfloat16",
|
||||
gpu_memory_utilization=0.8,
|
||||
)
|
||||
sampling_params = SamplingParams(top_p=0.95, temperature=0.6, max_tokens=32768)
|
||||
|
||||
outputs = llm.generate(prompts=input_text, sampling_params=sampling_params)
|
||||
|
||||
print(outputs[0].outputs[0].text)
|
||||
```
|
||||
|
||||
Also, you can start the inference server by running the following command:
|
||||
> **Note**: In vLLM's chat API, `add_special_tokens` is `False` by default. This means important special tokens—such as the beginning-of-sequence (BOS) token—will not be added automatically. To ensure the input prompt is correctly formatted for the model, you should explicitly set `extra_body={"add_special_tokens": True}`.
|
||||
|
||||
```bash
|
||||
vllm serve openbmb/MiniCPM4.1-8B --trust-remote-code
|
||||
```
|
||||
|
||||
Then you can use the chat interface by running the following code:
|
||||
|
||||
```python
|
||||
import openai
|
||||
|
||||
client = openai.Client(base_url="http://localhost:8000/v1", api_key="EMPTY")
|
||||
|
||||
response = client.chat.completions.create(
|
||||
model="openbmb/MiniCPM4.1-8B",
|
||||
messages=[
|
||||
{"role": "user", "content": "Write an article about Artificial Intelligence."},
|
||||
],
|
||||
temperature=0.6,
|
||||
max_tokens=32768,
|
||||
extra_body=dict(add_special_tokens=True), # Ensures special tokens are added for chat template
|
||||
|
||||
)
|
||||
|
||||
print(response.choices[0].message.content)
|
||||
```
|
||||
|
||||
|
||||
### Inference with [CPM.cu](https://github.com/OpenBMB/cpm.cu)
|
||||
|
||||
We recommend using [CPM.cu](https://github.com/OpenBMB/cpm.cu) for the inference of MiniCPM4 and MiniCPM4.1. CPM.cu is a CUDA inference framework developed by OpenBMB, which integrates efficient sparse, speculative sampling, and quantization techniques, fully leveraging the efficiency advantages of MiniCPM4 and MiniCPM4.1.
|
||||
|
||||
You can install CPM.cu by running the following command:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/OpenBMB/cpm.cu.git --recursive
|
||||
cd cpm.cu
|
||||
python3 setup.py install
|
||||
```
|
||||
|
||||
MiniCPM4.1 natively supports context lengths of up to 65,536(64k) tokens. To reproduce the long-text acceleration effect in the paper, we recommend using the LongRoPE factors that have been validated. Change the `rope_scaling` field in the `config.json` file as the following to enable LongRoPE.
|
||||
```json
|
||||
{
|
||||
...,
|
||||
"rope_scaling": {
|
||||
"rope_type": "longrope",
|
||||
"long_factor": [0.9982316082870437, 1.033048153422584, 1.0749920956484724, 1.1255096879436193, 1.1863348602111476, 1.259543828902579, 1.3476188888731149, 1.4535223827776373, 1.5807816745852985, 1.7335856049489526, 1.9168922912975785, 2.1365471404135326, 2.3994084200118646, 2.713475511863602, 3.0880118452194134, 3.533650295140154, 4.062463396503134, 4.687974098908333, 5.425075306704039, 6.289818967956352, 7.29902962722721, 8.6357018163639, 10.210822723989212, 12.053807765671676, 14.193944598909404, 16.65780676784363, 19.463620727694074, 22.628311203524586, 26.150106147261315, 30.02526691405111, 34.23183327975347, 38.73811934094828, 43.502489489729555, 48.47627117965394, 53.61139491762471, 58.857366522037935, 64.16798299215064, 69.51359464319125, 74.86555458220285, 80.21497790341579, 85.55322183307433, 90.89611806932027, 96.26245306514224, 101.68269304046481, 107.18619510219668, 112.82253283014026, 118.63764063163615, 119.88866203644656, 120.9462882391725, 121.837565139014, 122.58663780572562, 123.2147719894291, 123.74049454862576, 124.17980424685767, 124.54641761955492, 124.85202548028222, 125.10654406389756, 125.31835105170659, 125.49450117164764, 125.64091910903052, 125.76256945356558, 125.86360463815589, 125.94749252260765, 126.01712561287873],
|
||||
"short_factor": [0.9982316082870437, 1.033048153422584, 1.0749920956484724, 1.1255096879436193, 1.1863348602111476, 1.259543828902579, 1.3476188888731149, 1.4535223827776373, 1.5807816745852985, 1.7335856049489526, 1.9168922912975785, 2.1365471404135326, 2.3994084200118646, 2.713475511863602, 3.0880118452194134, 3.533650295140154, 4.062463396503134, 4.687974098908333, 5.425075306704039, 6.289818967956352, 7.29902962722721, 8.6357018163639, 10.210822723989212, 12.053807765671676, 14.193944598909404, 16.65780676784363, 19.463620727694074, 22.628311203524586, 26.150106147261315, 30.02526691405111, 34.23183327975347, 38.73811934094828, 43.502489489729555, 48.47627117965394, 53.61139491762471, 58.857366522037935, 64.16798299215064, 69.51359464319125, 74.86555458220285, 80.21497790341579, 85.55322183307433, 90.89611806932027, 96.26245306514224, 101.68269304046481, 107.18619510219668, 112.82253283014026, 118.63764063163615, 119.88866203644656, 120.9462882391725, 121.837565139014, 122.58663780572562, 123.2147719894291, 123.74049454862576, 124.17980424685767, 124.54641761955492, 124.85202548028222, 125.10654406389756, 125.31835105170659, 125.49450117164764, 125.64091910903052, 125.76256945356558, 125.86360463815589, 125.94749252260765, 126.01712561287873],
|
||||
"original_max_position_embeddings": 65536
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
After modification, you can run the following command to reproduce the long-context acceleration effect (the script will automatically download the model weights from HuggingFace)
|
||||
```bash
|
||||
python3 tests/test_generate.py
|
||||
```
|
||||
|
||||
You can run the following command to infer with EAGLE3 speculative decoding algorithm.
|
||||
|
||||
```bash
|
||||
python3 -m cpmcu.cli \
|
||||
--model-path $BASE_MODEL_PATH \
|
||||
--draft-model-path $EAGLE3_DRAFT_MODEL_PATH \
|
||||
--prompt-text "Write an article about Artificial Intelligence." \
|
||||
--use-eagle3 true
|
||||
```
|
||||
|
||||
For more details about CPM.cu, please refer to [the repo CPM.cu](https://github.com/OpenBMB/cpm.cu).
|
||||
|
||||
### Inference with llama.cpp and Ollama
|
||||
|
||||
We also support inference with [llama.cpp](https://github.com/ggml-org/llama.cpp) and [Ollama](https://ollama.com/).
|
||||
|
||||
##### llama.cpp
|
||||
|
||||
You can download the GGUF format of MiniCPM4.1-8B model from [huggingface](https://huggingface.co/openbmb/MiniCPM4.1-8B-GGUF) and run it with llama.cpp for efficient CPU or GPU inference.
|
||||
```
|
||||
# case 1: main-cli
|
||||
./build/bin/llama-cli -m MiniCPM4.1-8B-Q4_K_M.gguf -p "Write an article about Artificial Intelligence." -n 1500
|
||||
|
||||
# case 2: server
|
||||
## launch server
|
||||
./build/bin/llama-server -m MiniCPM4.1-8B-Q4_K_M.gguf --host 127.0.0.1 --port 8080 -c 4096 -fa on &
|
||||
|
||||
## send request
|
||||
curl -X POST http://127.0.0.1:8080/v1/chat/completions \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"model": "gpt-3.5-turbo",
|
||||
"messages": [{"role": "user", "content": "Write an article about Artificial Intelligence."}],
|
||||
"max_tokens": 1500
|
||||
}'
|
||||
```
|
||||
|
||||
##### Ollama
|
||||
Please refer to [model hub](https://ollama.com/openbmb/minicpm4.1) for model download. After installing ollama package, you can use MiniCPM4.1 with following commands:
|
||||
```
|
||||
ollama run openbmb/minicpm4.1
|
||||
```
|
||||
|
||||
### Hybird Reasoning Mode
|
||||
|
||||
MiniCPM4.1 supports hybrid reasoning mode, which can be used in both deep reasoning mode and non-reasoning mode. To enable hybrid reasoning mode. User can set `enable_thinking=True` in `tokenizer.apply_chat_template` to enable hybrid reasoning mode, and set `enable_thinking=False` to enable non-reasoning mode. Similarly, user can directly add `/no_think` at the end of the query to enable non-reasoning mode. If not add any special token or add `/think` at the end of the query, the model will enable reasoning mode.
|
||||
|
||||
```python
|
||||
# Enable reasoning mode
|
||||
prompt_text = tokenizer.apply_chat_template(
|
||||
messages,
|
||||
tokenize=False,
|
||||
add_generation_prompt=True,
|
||||
enable_thinking=True
|
||||
)
|
||||
# Enable non-reasoning mode
|
||||
prompt_text = tokenizer.apply_chat_template(
|
||||
messages,
|
||||
tokenize=False,
|
||||
add_generation_prompt=True,
|
||||
enable_thinking=False
|
||||
)
|
||||
```
|
||||
|
||||
## Statement
|
||||
- As a language model, MiniCPM generates content by learning from a vast amount of text.
|
||||
- However, it does not possess the ability to comprehend or express personal opinions or value judgments.
|
||||
- Any content generated by MiniCPM does not represent the viewpoints or positions of the model developers.
|
||||
- Therefore, when using content generated by MiniCPM, users should take full responsibility for evaluating and verifying it on their own.
|
||||
|
||||
## LICENSE
|
||||
- This repository and MiniCPM models are released under the [Apache-2.0](https://github.com/OpenBMB/MiniCPM/blob/main/LICENSE) License.
|
||||
|
||||
## Citation
|
||||
- Please cite our [paper](https://arxiv.org/abs/2506.07900) if you find our work valuable.
|
||||
|
||||
```bibtex
|
||||
@article{minicpm4,
|
||||
title={Minicpm4: Ultra-efficient llms on end devices},
|
||||
author={MiniCPM, Team},
|
||||
journal={arXiv preprint arXiv:2506.07900},
|
||||
year={2025}
|
||||
}
|
||||
```
|
||||
10
added_tokens.json
Normal file
10
added_tokens.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"<|execute_end|>": 73444,
|
||||
"<|execute_start|>": 73443,
|
||||
"<|fim_middle|>": 73446,
|
||||
"<|fim_prefix|>": 73445,
|
||||
"<|fim_suffix|>": 73447,
|
||||
"<|im_end|>": 73440,
|
||||
"<|im_start|>": 73441,
|
||||
"<|tool_call|>": 73442
|
||||
}
|
||||
42
config.json
Normal file
42
config.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"_name_or_path": "openbmb/MiniCPM4.1-8B",
|
||||
"architectures": [
|
||||
"MiniCPMForCausalLM"
|
||||
],
|
||||
"auto_map": {
|
||||
"AutoConfig": "configuration_minicpm.MiniCPMConfig",
|
||||
"AutoModel": "modeling_minicpm.MiniCPMModel",
|
||||
"AutoModelForCausalLM": "modeling_minicpm.MiniCPMForCausalLM",
|
||||
"AutoModelForSeq2SeqLM": "modeling_minicpm.MiniCPMForCausalLM",
|
||||
"AutoModelForSequenceClassification": "modeling_minicpm.MiniCPMForSequenceClassification"
|
||||
},
|
||||
"bos_token_id": 1,
|
||||
"eos_token_id": [2, 73440],
|
||||
"pad_token_id": 2,
|
||||
"hidden_act": "silu",
|
||||
"hidden_size": 4096,
|
||||
"initializer_range": 0.1,
|
||||
"intermediate_size": 16384,
|
||||
"max_position_embeddings": 65536,
|
||||
"model_type": "minicpm",
|
||||
"num_attention_heads": 32,
|
||||
"num_hidden_layers": 32,
|
||||
"num_key_value_heads": 2,
|
||||
"rms_norm_eps": 1e-06,
|
||||
"rope_scaling": {
|
||||
"rope_type": "longrope",
|
||||
"long_factor": [0.9982316082870437, 1.033048153422584, 1.0749920956484724, 1.1255096879436193, 1.1863348602111476, 1.259543828902579, 1.3476188888731149, 1.4535223827776373, 1.5807816745852985, 1.7335856049489526, 1.9168922912975785, 2.1365471404135326, 2.3994084200118646, 2.713475511863602, 3.0880118452194134, 3.533650295140154, 4.062463396503134, 4.687974098908333, 5.425075306704039, 6.289818967956352, 7.29902962722721, 8.469695779093664, 9.81809877306655, 11.358657902065282, 13.102505860712087, 15.055862949967128, 17.218348131364184, 19.581439255386453, 22.127353314656723, 24.828633849376587, 27.6486820771775, 30.54334096108829, 33.46345345363812, 36.358112337548896, 39.17816056534983, 41.879441100069684, 44.425355159339965, 46.78844628336223, 48.95093146475928, 50.90428855401433, 52.648136512661125, 54.18869564165987, 55.537098635632745, 56.7077647874992, 57.71697544677006, 58.58171910802236, 59.31882031581807, 59.94433101822328, 60.47314411958625, 60.918782569507, 61.29331890286281, 61.60738599471455, 61.87024727431288, 62.089902123428836, 62.27320880977746, 62.42601274014111, 62.55327203194878, 62.65917552585329, 62.74725058582382, 62.82045955451526, 62.88128472678279, 62.931802319077946, 62.97374626130382, 63.008562806439365],
|
||||
"short_factor": [0.9982316082870437, 1.033048153422584, 1.0749920956484724, 1.1255096879436193, 1.1863348602111476, 1.259543828902579, 1.3476188888731149, 1.4535223827776373, 1.5807816745852985, 1.7335856049489526, 1.9168922912975785, 2.1365471404135326, 2.3994084200118646, 2.713475511863602, 3.0880118452194134, 3.533650295140154, 4.062463396503134, 4.687974098908333, 5.425075306704039, 6.289818967956352, 7.29902962722721, 8.469695779093664, 9.81809877306655, 11.358657902065282, 13.102505860712087, 15.055862949967128, 17.218348131364184, 19.581439255386453, 22.127353314656723, 24.828633849376587, 27.6486820771775, 30.54334096108829, 33.46345345363812, 36.358112337548896, 39.17816056534983, 41.879441100069684, 44.425355159339965, 46.78844628336223, 48.95093146475928, 50.90428855401433, 52.648136512661125, 54.18869564165987, 55.537098635632745, 56.7077647874992, 57.71697544677006, 58.58171910802236, 59.31882031581807, 59.94433101822328, 60.47314411958625, 60.918782569507, 61.29331890286281, 61.60738599471455, 61.87024727431288, 62.089902123428836, 62.27320880977746, 62.42601274014111, 62.55327203194878, 62.65917552585329, 62.74725058582382, 62.82045955451526, 62.88128472678279, 62.931802319077946, 62.97374626130382, 63.008562806439365],
|
||||
"original_max_position_embeddings": 65536
|
||||
},
|
||||
"torch_dtype": "bfloat16",
|
||||
"transformers_version": "4.56.1",
|
||||
"use_cache": true,
|
||||
"vocab_size": 73448,
|
||||
"rope_theta": 10000.0,
|
||||
"scale_emb": 12,
|
||||
"scale_depth": 1.4,
|
||||
"mup_denominator": 32,
|
||||
"dim_model_base": 256,
|
||||
"tie_word_embeddings": false
|
||||
}
|
||||
1
configuration.json
Normal file
1
configuration.json
Normal file
@@ -0,0 +1 @@
|
||||
{"framework":"Pytorch","task":"text-generation"}
|
||||
203
configuration_minicpm.py
Normal file
203
configuration_minicpm.py
Normal file
@@ -0,0 +1,203 @@
|
||||
# coding=utf-8
|
||||
# Copyright 2025 The OpenBMB Team. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
""" MiniCPM model configuration"""
|
||||
|
||||
from transformers.configuration_utils import PretrainedConfig
|
||||
from transformers.utils import logging
|
||||
|
||||
logger = logging.get_logger(__name__)
|
||||
|
||||
MINICPM_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
|
||||
|
||||
|
||||
class MiniCPMConfig(PretrainedConfig):
|
||||
r"""
|
||||
This is the configuration class to store the configuration of a [`MiniCPMModel`]. It is used to instantiate an MiniCPM
|
||||
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
|
||||
defaults will yield a similar configuration to that of the MiniCPM-7B.
|
||||
|
||||
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
||||
documentation from [`PretrainedConfig`] for more information.
|
||||
|
||||
|
||||
Args:
|
||||
vocab_size (`int`, *optional*, defaults to 32000):
|
||||
Vocabulary size of the MiniCPM model. Defines the number of different tokens that can be represented by the
|
||||
`inputs_ids` passed when calling [`MiniCPMModel`]
|
||||
hidden_size (`int`, *optional*, defaults to 4096):
|
||||
Dimension of the hidden representations.
|
||||
intermediate_size (`int`, *optional*, defaults to 11008):
|
||||
Dimension of the MLP representations.
|
||||
num_hidden_layers (`int`, *optional*, defaults to 32):
|
||||
Number of hidden layers in the Transformer decoder.
|
||||
num_attention_heads (`int`, *optional*, defaults to 32):
|
||||
Number of attention heads for each attention layer in the Transformer decoder.
|
||||
num_key_value_heads (`int`, *optional*):
|
||||
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
||||
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
||||
`num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
||||
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
||||
by meanpooling all the original heads within that group. For more details checkout [this
|
||||
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
|
||||
`num_attention_heads`.
|
||||
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
||||
The non-linear activation function (function or string) in the decoder.
|
||||
max_position_embeddings (`int`, *optional*, defaults to 2048):
|
||||
The maximum sequence length that this model might ever be used with. MiniCPM 1 supports up to 2048 tokens,
|
||||
MiniCPM 2 up to 4096, CodeMiniCPM up to 16384.
|
||||
initializer_range (`float`, *optional*, defaults to 0.02):
|
||||
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
||||
rms_norm_eps (`float`, *optional*, defaults to 1e-06):
|
||||
The epsilon used by the rms normalization layers.
|
||||
use_cache (`bool`, *optional*, defaults to `True`):
|
||||
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
||||
relevant if `config.is_decoder=True`.
|
||||
pad_token_id (`int`, *optional*):
|
||||
Padding token id.
|
||||
bos_token_id (`int`, *optional*, defaults to 1):
|
||||
Beginning of stream token id.
|
||||
eos_token_id (`int`, *optional*, defaults to 2):
|
||||
End of stream token id.
|
||||
pretraining_tp (`int`, *optional*, defaults to 1):
|
||||
Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
|
||||
document](https://huggingface.co/docs/transformers/parallelism) to understand more about it. This value is
|
||||
necessary to ensure exact reproducibility of the pretraining results. Please refer to [this
|
||||
issue](https://github.com/pytorch/pytorch/issues/76232).
|
||||
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
||||
Whether to tie weight embeddings
|
||||
rope_theta (`float`, *optional*, defaults to 10000.0):
|
||||
The base period of the RoPE embeddings.
|
||||
rope_scaling (`Dict`, *optional*):
|
||||
Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
|
||||
strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
|
||||
`{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
|
||||
`max_position_embeddings` to the expected new maximum. See the following thread for more information on how
|
||||
these scaling strategies behave:
|
||||
https://www.reddit.com/r/LocalMiniCPM/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
|
||||
experimental feature, subject to breaking API changes in future versions.
|
||||
attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
|
||||
Whether to use a bias in the query, key, value and output projection layers during self-attention.
|
||||
attention_dropout (`float`, *optional*, defaults to 0.0):
|
||||
The dropout ratio for the attention probabilities.
|
||||
|
||||
```python
|
||||
>>> from transformers import MiniCPMModel, MiniCPMConfig
|
||||
|
||||
>>> # Initializing a MiniCPM minicpm-7b style configuration
|
||||
>>> configuration = MiniCPMConfig()
|
||||
|
||||
>>> # Initializing a model from the minicpm-7b style configuration
|
||||
>>> model = MiniCPMModel(configuration)
|
||||
|
||||
>>> # Accessing the model configuration
|
||||
>>> configuration = model.config
|
||||
```"""
|
||||
|
||||
model_type = 'minicpm'
|
||||
keys_to_ignore_at_inference = ['past_key_values']
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
vocab_size=32000,
|
||||
hidden_size=4096,
|
||||
intermediate_size=11008,
|
||||
num_hidden_layers=32,
|
||||
num_attention_heads=32,
|
||||
num_key_value_heads=None,
|
||||
hidden_act='silu',
|
||||
max_position_embeddings=2048,
|
||||
initializer_range=0.02,
|
||||
rms_norm_eps=1e-6,
|
||||
use_cache=True,
|
||||
pad_token_id=None,
|
||||
bos_token_id=1,
|
||||
eos_token_id=2,
|
||||
pretraining_tp=1,
|
||||
tie_word_embeddings=True,
|
||||
rope_theta=10000.0,
|
||||
rope_scaling=None,
|
||||
attention_bias=False,
|
||||
attention_dropout=0.0,
|
||||
scale_emb=1,
|
||||
dim_model_base=1,
|
||||
scale_depth=1,
|
||||
mup_denominator=32,
|
||||
sparse_config=None,
|
||||
**kwargs):
|
||||
|
||||
self.vocab_size = vocab_size
|
||||
self.max_position_embeddings = max_position_embeddings
|
||||
self.hidden_size = hidden_size
|
||||
self.intermediate_size = intermediate_size
|
||||
self.num_hidden_layers = num_hidden_layers
|
||||
self.num_attention_heads = num_attention_heads
|
||||
|
||||
# for backward compatibility
|
||||
if num_key_value_heads is None:
|
||||
num_key_value_heads = num_attention_heads
|
||||
|
||||
self.num_key_value_heads = num_key_value_heads
|
||||
self.hidden_act = hidden_act
|
||||
self.initializer_range = initializer_range
|
||||
self.rms_norm_eps = rms_norm_eps
|
||||
self.pretraining_tp = pretraining_tp
|
||||
self.use_cache = use_cache
|
||||
self.rope_theta = rope_theta
|
||||
self.rope_scaling = rope_scaling
|
||||
# self._rope_scaling_validation()
|
||||
self.attention_bias = attention_bias
|
||||
self.attention_dropout = attention_dropout
|
||||
self.scale_emb = scale_emb
|
||||
self.dim_model_base = dim_model_base
|
||||
self.scale_depth = scale_depth
|
||||
# only used for Eagle Head
|
||||
self.mup_denominator = mup_denominator
|
||||
|
||||
# sparse config
|
||||
self.sparse_config = sparse_config
|
||||
|
||||
super().__init__(
|
||||
pad_token_id=pad_token_id,
|
||||
bos_token_id=bos_token_id,
|
||||
eos_token_id=eos_token_id,
|
||||
tie_word_embeddings=tie_word_embeddings,
|
||||
**kwargs,
|
||||
)
|
||||
try:
|
||||
import flash_attn
|
||||
self._attn_implementation = 'flash_attention_2'
|
||||
except:
|
||||
pass
|
||||
|
||||
def _rope_scaling_validation(self):
|
||||
"""
|
||||
Validate the `rope_scaling` configuration.
|
||||
"""
|
||||
if self.rope_scaling is None:
|
||||
return
|
||||
|
||||
if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
|
||||
raise ValueError(
|
||||
'`rope_scaling` must be a dictionary with with two fields, `type` and `factor`, '
|
||||
f'got {self.rope_scaling}'
|
||||
)
|
||||
rope_scaling_type = self.rope_scaling.get('type', None)
|
||||
rope_scaling_factor = self.rope_scaling.get('factor', None)
|
||||
if rope_scaling_type is None or rope_scaling_type not in ['linear', 'dynamic']:
|
||||
raise ValueError(
|
||||
f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
|
||||
)
|
||||
if rope_scaling_factor is None or not isinstance(rope_scaling_factor, float) or rope_scaling_factor <= 1.0:
|
||||
raise ValueError(f"`rope_scaling`'s factor field must be a float > 1, got {rope_scaling_factor}")
|
||||
12
generation_config.json
Normal file
12
generation_config.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"bos_token_id": 1,
|
||||
"do_sample": true,
|
||||
"eos_token_id": [
|
||||
2,
|
||||
73440
|
||||
],
|
||||
"pad_token_id": 2,
|
||||
"temperature": 0.8,
|
||||
"top_p": 0.8,
|
||||
"transformers_version": "4.46.1"
|
||||
}
|
||||
3
model-00001-of-00004.safetensors
Normal file
3
model-00001-of-00004.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:d893df3a00be018df333f102251db12de40d614a39438ee9721398b272b0b9c0
|
||||
size 4968335472
|
||||
3
model-00002-of-00004.safetensors
Normal file
3
model-00002-of-00004.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:064bcba714ff425b660057fd2a09f9e55bbb0db75e52fc5d082ddf3fcf5af11e
|
||||
size 4542417008
|
||||
3
model-00003-of-00004.safetensors
Normal file
3
model-00003-of-00004.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:a23c3ad2c4c1ca4eae8cbd0fd14cbc0391096cd167bb4969dc49b52abfac7a67
|
||||
size 4936647824
|
||||
3
model-00004-of-00004.safetensors
Normal file
3
model-00004-of-00004.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:e3809c32918b84150715c343736a27fb4cf082473fb82505f87566d7179588ea
|
||||
size 1923141264
|
||||
299
model.safetensors.index.json
Normal file
299
model.safetensors.index.json
Normal file
@@ -0,0 +1,299 @@
|
||||
{
|
||||
"metadata": {
|
||||
"total_parameters": 8185253888,
|
||||
"total_size": 16370507776
|
||||
},
|
||||
"weight_map": {
|
||||
"lm_head.weight": "model-00003-of-00004.safetensors",
|
||||
"model.embed_tokens.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.0.input_layernorm.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.0.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.0.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.0.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.0.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.0.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.0.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.0.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.0.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.1.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.1.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.1.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.1.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.1.post_attention_layernorm.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.1.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.1.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.1.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.1.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.10.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.10.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.10.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.10.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.10.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.10.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.10.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.10.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.10.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.11.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.11.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.11.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.11.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.11.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.11.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.11.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.11.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.11.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.12.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.12.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.12.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.12.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.12.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.12.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.12.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.12.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.12.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.13.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.13.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.13.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.13.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.13.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.13.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.13.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.13.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.13.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.14.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.14.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.14.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.14.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.14.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.14.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.14.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.14.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.14.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.15.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.15.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.15.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.15.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.15.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.15.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.15.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.15.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.15.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.16.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.16.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.16.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.16.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.16.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.16.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.16.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.16.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.16.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.17.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.17.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.17.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.17.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.17.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.17.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.17.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.17.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.17.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.18.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.18.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.18.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.18.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.18.post_attention_layernorm.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.18.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.18.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.18.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.18.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.19.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.19.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.19.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.19.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.19.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.19.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.19.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.19.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.19.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.2.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.2.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.2.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.2.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.2.post_attention_layernorm.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.2.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.2.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.2.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.2.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.20.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.20.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.20.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.20.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.20.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.20.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.20.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.20.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.20.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.21.input_layernorm.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.21.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.21.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.21.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.21.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.21.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.21.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.21.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.21.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.22.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.22.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.22.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.22.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.22.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.22.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.22.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.22.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.22.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.23.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.23.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.23.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.23.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.23.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.23.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.23.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.23.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.23.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.24.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.24.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.24.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.24.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.24.post_attention_layernorm.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.24.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.24.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.24.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.24.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.25.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.25.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.25.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.25.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.25.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.25.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.25.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.25.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.25.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.26.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.26.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.26.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.26.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.26.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.26.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.26.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.26.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.26.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.27.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.27.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.27.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.27.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.27.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.27.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.27.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.27.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.27.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.28.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.28.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.28.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.28.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.28.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.28.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.28.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.28.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.28.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.29.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.29.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.29.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.29.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.29.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.29.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.29.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.29.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.29.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.3.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.3.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.3.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.3.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.3.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.3.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.3.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.3.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.3.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.30.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.30.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.30.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.30.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.30.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.30.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.30.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.30.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.30.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.31.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.31.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.31.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.31.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.31.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.31.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.31.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.31.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.31.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.4.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.4.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.4.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.4.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.4.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.4.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.4.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.4.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.4.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.5.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.5.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.5.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.5.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.5.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.5.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.5.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.5.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.5.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.6.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.6.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.6.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.6.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.6.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.6.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.6.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.6.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.6.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.7.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.7.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.7.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.7.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.7.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.7.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.7.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.7.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.7.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.layers.8.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.8.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.8.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.8.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.8.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.8.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.8.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.8.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.8.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.9.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.9.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.9.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
||||
"model.layers.9.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.9.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.9.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.9.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
||||
"model.layers.9.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
||||
"model.layers.9.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
|
||||
"model.norm.weight": "model-00003-of-00004.safetensors"
|
||||
}
|
||||
}
|
||||
2283
modeling_minicpm.py
Normal file
2283
modeling_minicpm.py
Normal file
File diff suppressed because it is too large
Load Diff
33
special_tokens_map.json
Normal file
33
special_tokens_map.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"additional_special_tokens": [
|
||||
"<|im_end|>",
|
||||
"<|im_start|>",
|
||||
"<|tool_call|>",
|
||||
"<|execute_start|>",
|
||||
"<|execute_end|>",
|
||||
"<|fim_prefix|>",
|
||||
"<|fim_middle|>",
|
||||
"<|fim_suffix|>"
|
||||
],
|
||||
"bos_token": {
|
||||
"content": "<s>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false
|
||||
},
|
||||
"eos_token": {
|
||||
"content": "<|im_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false
|
||||
},
|
||||
"unk_token": {
|
||||
"content": "<unk>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false
|
||||
}
|
||||
}
|
||||
3
tokenizer.json
Normal file
3
tokenizer.json
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:adf7208af154a5ca065d2eda4e5419e02aac58c2c00627874748b75ec6769094
|
||||
size 6701371
|
||||
3
tokenizer.model
Normal file
3
tokenizer.model
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:bb74d51116831c3bf65db812c553f94ab0c88dcf97a5bbb37e3504f6d359c530
|
||||
size 1181204
|
||||
117
tokenizer_config.json
Normal file
117
tokenizer_config.json
Normal file
@@ -0,0 +1,117 @@
|
||||
{
|
||||
"add_bos_token": true,
|
||||
"add_eos_token": false,
|
||||
"add_prefix_space": null,
|
||||
"added_tokens_decoder": {
|
||||
"0": {
|
||||
"content": "<unk>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"1": {
|
||||
"content": "<s>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"2": {
|
||||
"content": "</s>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"73440": {
|
||||
"content": "<|im_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"73441": {
|
||||
"content": "<|im_start|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"73442": {
|
||||
"content": "<|tool_call|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"73443": {
|
||||
"content": "<|execute_start|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"73444": {
|
||||
"content": "<|execute_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"73445": {
|
||||
"content": "<|fim_prefix|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"73446": {
|
||||
"content": "<|fim_middle|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"73447": {
|
||||
"content": "<|fim_suffix|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
}
|
||||
},
|
||||
"additional_special_tokens": [
|
||||
"<|im_end|>",
|
||||
"<|im_start|>",
|
||||
"<|tool_call|>",
|
||||
"<|execute_start|>",
|
||||
"<|execute_end|>",
|
||||
"<|fim_prefix|>",
|
||||
"<|fim_middle|>",
|
||||
"<|fim_suffix|>"
|
||||
],
|
||||
"bos_token": "<s>",
|
||||
"chat_template": "{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% if enable_thinking is defined and enable_thinking is false %}{{ '<think>\n\n</think>\n' }}{% endif %}{% endif %}",
|
||||
"clean_up_tokenization_spaces": false,
|
||||
"eos_token": "<|im_end|>",
|
||||
"legacy": true,
|
||||
"model_max_length": 1000000000000000019884624838656,
|
||||
"pad_token": null,
|
||||
"sp_model_kwargs": {},
|
||||
"spaces_between_special_tokens": false,
|
||||
"tokenizer_class": "LlamaTokenizer",
|
||||
"unk_token": "<unk>",
|
||||
"use_default_system_prompt": false
|
||||
}
|
||||
Reference in New Issue
Block a user