初始化项目,由ModelHub XC社区提供模型
Model: OpenBMB/MiniCPM3-4B 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
|
||||||
|
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bz2 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
|
||||||
|
*.model filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.msgpack 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
|
||||||
|
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
saved_model/**/* 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
|
||||||
|
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.db* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ark* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
**/*ckpt*data* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
**/*ckpt*.meta filter=lfs diff=lfs merge=lfs -text
|
||||||
|
**/*ckpt*.index filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gguf* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ggml filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.llamafile* filter=lfs diff=lfs merge=lfs -text
|
||||||
304
README.md
Normal file
304
README.md
Normal file
@@ -0,0 +1,304 @@
|
|||||||
|
---
|
||||||
|
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">MiniCPM Repo</a> |
|
||||||
|
<a href="https://arxiv.org/abs/2404.06395" target="_blank">MiniCPM Paper</a> |
|
||||||
|
<a href="https://github.com/OpenBMB/MiniCPM-V/" target="_blank">MiniCPM-V Repo</a> |
|
||||||
|
Join 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>
|
||||||
|
|
||||||
|
## Introduction
|
||||||
|
MiniCPM3-4B is the 3rd generation of MiniCPM series. The overall performance of MiniCPM3-4B surpasses Phi-3.5-mini-Instruct and GPT-3.5-Turbo-0125, being comparable with many recent 7B~9B models.
|
||||||
|
|
||||||
|
Compared to MiniCPM1.0/MiniCPM2.0, MiniCPM3-4B has a more powerful and versatile skill set to enable more general usage. MiniCPM3-4B supports function call, along with code interpreter. Please refer to [Advanced Features](https://github.com/OpenBMB/MiniCPM/tree/main?tab=readme-ov-file#%E8%BF%9B%E9%98%B6%E5%8A%9F%E8%83%BD) for usage guidelines.
|
||||||
|
|
||||||
|
MiniCPM3-4B has a 32k context window. Equipped with LLMxMapReduce, MiniCPM3-4B can handle infinite context theoretically, without requiring huge amount of memory.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
### Inference with Transformers
|
||||||
|
```python
|
||||||
|
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||||||
|
import torch
|
||||||
|
|
||||||
|
path = "openbmb/MiniCPM3-4B"
|
||||||
|
device = "cuda"
|
||||||
|
|
||||||
|
tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
|
||||||
|
model = AutoModelForCausalLM.from_pretrained(path, torch_dtype=torch.bfloat16, device_map=device, trust_remote_code=True)
|
||||||
|
|
||||||
|
messages = [
|
||||||
|
{"role": "user", "content": "推荐5个北京的景点。"},
|
||||||
|
]
|
||||||
|
model_inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(device)
|
||||||
|
|
||||||
|
model_outputs = model.generate(
|
||||||
|
model_inputs,
|
||||||
|
max_new_tokens=1024,
|
||||||
|
top_p=0.7,
|
||||||
|
temperature=0.7
|
||||||
|
)
|
||||||
|
|
||||||
|
output_token_ids = [
|
||||||
|
model_outputs[i][len(model_inputs[i]):] for i in range(len(model_inputs))
|
||||||
|
]
|
||||||
|
|
||||||
|
responses = tokenizer.batch_decode(output_token_ids, skip_special_tokens=True)[0]
|
||||||
|
print(responses)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Inference with [vLLM](https://github.com/vllm-project/vllm)
|
||||||
|
|
||||||
|
For now, you need to install our forked version of vLLM.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install git+https://github.com/OpenBMB/vllm.git@minicpm3
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
from transformers import AutoTokenizer
|
||||||
|
from vllm import LLM, SamplingParams
|
||||||
|
|
||||||
|
model_name = "openbmb/MiniCPM3-4B"
|
||||||
|
prompt = [{"role": "user", "content": "推荐5个北京的景点。"}]
|
||||||
|
|
||||||
|
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,
|
||||||
|
tensor_parallel_size=1
|
||||||
|
)
|
||||||
|
sampling_params = SamplingParams(top_p=0.7, temperature=0.7, max_tokens=1024, repetition_penalty=1.02)
|
||||||
|
|
||||||
|
outputs = llm.generate(prompts=input_text, sampling_params=sampling_params)
|
||||||
|
|
||||||
|
print(outputs[0].outputs[0].text)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Evaluation Results
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>Benchmark</td>
|
||||||
|
<td>Qwen2-7B-Instruct</td>
|
||||||
|
<td>GLM-4-9B-Chat</td>
|
||||||
|
<td>Gemma2-9B-it</td>
|
||||||
|
<td>Llama3.1-8B-Instruct</td>
|
||||||
|
<td>GPT-3.5-Turbo-0125</td>
|
||||||
|
<td>Phi-3.5-mini-Instruct(3.8B)</td>
|
||||||
|
<td>MiniCPM3-4B </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="15" align="left"><strong>English</strong></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>MMLU</td>
|
||||||
|
<td>70.5</td>
|
||||||
|
<td>72.4</td>
|
||||||
|
<td>72.6</td>
|
||||||
|
<td>69.4</td>
|
||||||
|
<td>69.2</td>
|
||||||
|
<td>68.4</td>
|
||||||
|
<td>67.2 </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>BBH</td>
|
||||||
|
<td>64.9</td>
|
||||||
|
<td>76.3</td>
|
||||||
|
<td>65.2</td>
|
||||||
|
<td>67.8</td>
|
||||||
|
<td>70.3</td>
|
||||||
|
<td>68.6</td>
|
||||||
|
<td>70.2 </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>MT-Bench</td>
|
||||||
|
<td>8.41</td>
|
||||||
|
<td>8.35</td>
|
||||||
|
<td>7.88</td>
|
||||||
|
<td>8.28</td>
|
||||||
|
<td>8.17</td>
|
||||||
|
<td>8.60</td>
|
||||||
|
<td>8.41 </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>IFEVAL (Prompt Strict-Acc.)</td>
|
||||||
|
<td>51.0</td>
|
||||||
|
<td>64.5</td>
|
||||||
|
<td>71.9</td>
|
||||||
|
<td>71.5</td>
|
||||||
|
<td>58.8</td>
|
||||||
|
<td>49.4</td>
|
||||||
|
<td>68.4 </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="15" align="left"><strong>Chinese</strong></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>CMMLU</td>
|
||||||
|
<td>80.9</td>
|
||||||
|
<td>71.5</td>
|
||||||
|
<td>59.5</td>
|
||||||
|
<td>55.8</td>
|
||||||
|
<td>54.5</td>
|
||||||
|
<td>46.9</td>
|
||||||
|
<td>73.3 </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>CEVAL</td>
|
||||||
|
<td>77.2</td>
|
||||||
|
<td>75.6</td>
|
||||||
|
<td>56.7</td>
|
||||||
|
<td>55.2</td>
|
||||||
|
<td>52.8</td>
|
||||||
|
<td>46.1</td>
|
||||||
|
<td>73.6 </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>AlignBench v1.1</td>
|
||||||
|
<td>7.10</td>
|
||||||
|
<td>6.61</td>
|
||||||
|
<td>7.10</td>
|
||||||
|
<td>5.68</td>
|
||||||
|
<td>5.82</td>
|
||||||
|
<td>5.73</td>
|
||||||
|
<td>6.74 </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>FollowBench-zh (SSR)</td>
|
||||||
|
<td>63.0</td>
|
||||||
|
<td>56.4</td>
|
||||||
|
<td>57.0</td>
|
||||||
|
<td>50.6</td>
|
||||||
|
<td>64.6</td>
|
||||||
|
<td>58.1</td>
|
||||||
|
<td>66.8 </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="15" align="left"><strong>Math</strong></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>MATH</td>
|
||||||
|
<td>49.6</td>
|
||||||
|
<td>50.6</td>
|
||||||
|
<td>46.0</td>
|
||||||
|
<td>51.9</td>
|
||||||
|
<td>41.8</td>
|
||||||
|
<td>46.4</td>
|
||||||
|
<td>46.6 </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>GSM8K</td>
|
||||||
|
<td>82.3</td>
|
||||||
|
<td>79.6</td>
|
||||||
|
<td>79.7</td>
|
||||||
|
<td>84.5</td>
|
||||||
|
<td>76.4</td>
|
||||||
|
<td>82.7</td>
|
||||||
|
<td>81.1 </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>MathBench</td>
|
||||||
|
<td>63.4</td>
|
||||||
|
<td>59.4</td>
|
||||||
|
<td>45.8</td>
|
||||||
|
<td>54.3</td>
|
||||||
|
<td>48.9</td>
|
||||||
|
<td>54.9</td>
|
||||||
|
<td>65.6 </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="15" align="left"><strong>Code</strong></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>HumanEval+</td>
|
||||||
|
<td>70.1</td>
|
||||||
|
<td>67.1</td>
|
||||||
|
<td>61.6</td>
|
||||||
|
<td>62.8</td>
|
||||||
|
<td>66.5</td>
|
||||||
|
<td>68.9</td>
|
||||||
|
<td>68.3 </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>MBPP+</td>
|
||||||
|
<td>57.1</td>
|
||||||
|
<td>62.2</td>
|
||||||
|
<td>64.3</td>
|
||||||
|
<td>55.3</td>
|
||||||
|
<td>71.4</td>
|
||||||
|
<td>55.8</td>
|
||||||
|
<td>63.2 </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>LiveCodeBench v3</td>
|
||||||
|
<td>22.2</td>
|
||||||
|
<td>20.2</td>
|
||||||
|
<td>19.2</td>
|
||||||
|
<td>20.4</td>
|
||||||
|
<td>24.0</td>
|
||||||
|
<td>19.6</td>
|
||||||
|
<td>22.6 </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="15" align="left"><strong>Function Call</strong></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>BFCL v2</td>
|
||||||
|
<td>71.6</td>
|
||||||
|
<td>70.1</td>
|
||||||
|
<td>19.2</td>
|
||||||
|
<td>73.3</td>
|
||||||
|
<td>75.4</td>
|
||||||
|
<td>48.4</td>
|
||||||
|
<td>76.0 </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="15" align="left"><strong>Overall</strong></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Average</td>
|
||||||
|
<td>65.3</td>
|
||||||
|
<td>65.0</td>
|
||||||
|
<td>57.9</td>
|
||||||
|
<td>60.8</td>
|
||||||
|
<td>61.0</td>
|
||||||
|
<td>57.2</td>
|
||||||
|
<td><strong>66.3</strong></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
## Statement
|
||||||
|
* As a language model, MiniCPM3-4B 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 MiniCPM3-4B does not represent the viewpoints or positions of the model developers.
|
||||||
|
* Therefore, when using content generated by MiniCPM3-4B, users should take full responsibility for evaluating and verifying it on their own.
|
||||||
|
|
||||||
|
## LICENSE
|
||||||
|
* This repository is released under the [Apache-2.0](https://github.com/OpenBMB/MiniCPM/blob/main/LICENSE) License.
|
||||||
|
* The usage of MiniCPM3-4B model weights must strictly follow [MiniCPM Model License.md](https://github.com/OpenBMB/MiniCPM/blob/main/MiniCPM%20Model%20License.md).
|
||||||
|
* The models and weights of MiniCPM3-4B are completely free for academic research. after filling out a ["questionnaire"](https://modelbest.feishu.cn/share/base/form/shrcnpV5ZT9EJ6xYjh3Kx0J6v8g) for registration, are also available for free commercial use.
|
||||||
|
|
||||||
|
## Citation
|
||||||
|
|
||||||
|
```
|
||||||
|
@article{hu2024minicpm,
|
||||||
|
title={MiniCPM: Unveiling the Potential of Small Language Models with Scalable Training Strategies},
|
||||||
|
author={Hu, Shengding and Tu, Yuge and Han, Xu and He, Chaoqun and Cui, Ganqu and Long, Xiang and Zheng, Zhi and Fang, Yewei and Huang, Yuxiang and Zhao, Weilin and others},
|
||||||
|
journal={arXiv preprint arXiv:2404.06395},
|
||||||
|
year={2024}
|
||||||
|
}
|
||||||
|
```
|
||||||
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/MiniCPM3-4B",
|
||||||
|
"architectures": [
|
||||||
|
"MiniCPM3ForCausalLM"
|
||||||
|
],
|
||||||
|
"auto_map": {
|
||||||
|
"AutoConfig": "configuration_minicpm.MiniCPM3Config",
|
||||||
|
"AutoModel": "modeling_minicpm.MiniCPM3Model",
|
||||||
|
"AutoModelForCausalLM": "modeling_minicpm.MiniCPM3ForCausalLM",
|
||||||
|
"AutoModelForSeq2SeqLM": "modeling_minicpm.MiniCPM3ForCausalLM",
|
||||||
|
"AutoModelForSequenceClassification": "modeling_minicpm.MiniCPM3ForSequenceClassification"
|
||||||
|
},
|
||||||
|
"bos_token_id": 1,
|
||||||
|
"eos_token_id": [2, 73440],
|
||||||
|
"hidden_act": "silu",
|
||||||
|
"initializer_range": 0.1,
|
||||||
|
"hidden_size": 2560,
|
||||||
|
"num_hidden_layers": 62,
|
||||||
|
"intermediate_size": 6400,
|
||||||
|
"max_position_embeddings": 32768,
|
||||||
|
"model_type": "minicpm3",
|
||||||
|
"num_attention_heads": 40,
|
||||||
|
"num_key_value_heads": 40,
|
||||||
|
"qk_nope_head_dim": 64,
|
||||||
|
"qk_rope_head_dim": 32,
|
||||||
|
"q_lora_rank": 768,
|
||||||
|
"kv_lora_rank": 256,
|
||||||
|
"rms_norm_eps": 1e-05,
|
||||||
|
"rope_scaling": {
|
||||||
|
"type": "longrope",
|
||||||
|
"long_factor": [1.0591234137867171, 1.1241891283591912, 1.2596935748670968, 1.5380380402321725, 2.093982484148734, 3.1446935121267696, 4.937952647693647, 7.524541999994549, 10.475458000005451, 13.062047352306353, 14.85530648787323, 15.906017515851266, 16.461961959767827, 16.740306425132907, 16.87581087164081, 16.940876586213285],
|
||||||
|
"short_factor": [1.0591234137867171, 1.1241891283591912, 1.2596935748670968, 1.5380380402321725, 2.093982484148734, 3.1446935121267696, 4.937952647693647, 7.524541999994549, 10.475458000005451, 13.062047352306353, 14.85530648787323, 15.906017515851266, 16.461961959767827, 16.740306425132907, 16.87581087164081, 16.940876586213285],
|
||||||
|
"original_max_position_embeddings": 32768
|
||||||
|
},
|
||||||
|
"torch_dtype": "bfloat16",
|
||||||
|
"transformers_version": "4.41.0",
|
||||||
|
"use_cache": true,
|
||||||
|
"vocab_size": 73448,
|
||||||
|
"scale_emb": 12,
|
||||||
|
"dim_model_base": 256,
|
||||||
|
"scale_depth": 1.4
|
||||||
|
}
|
||||||
1
configuration.json
Normal file
1
configuration.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"framework":"Pytorch","task":"text-generation"}
|
||||||
195
configuration_minicpm.py
Normal file
195
configuration_minicpm.py
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
# Copyright 2024 The OpenBMB team and the HuggingFace Inc. team. All rights reserved.
|
||||||
|
#
|
||||||
|
# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
|
||||||
|
# and OPT implementations in this library. It has been modified from its
|
||||||
|
# original forms to accommodate minor architectural differences compared
|
||||||
|
# to GPT-NeoX and OPT used by the Meta AI team that trained the model.
|
||||||
|
#
|
||||||
|
# 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 MiniCPM3Config(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 = "minicpm3"
|
||||||
|
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,
|
||||||
|
qk_nope_head_dim=64,
|
||||||
|
qk_rope_head_dim=32,
|
||||||
|
q_lora_rank=768,
|
||||||
|
kv_lora_rank=256,
|
||||||
|
v_head_dim=None,
|
||||||
|
head_dim=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,
|
||||||
|
**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
|
||||||
|
self.qk_nope_head_dim = qk_nope_head_dim
|
||||||
|
self.qk_rope_head_dim = qk_rope_head_dim
|
||||||
|
self.q_lora_rank = q_lora_rank
|
||||||
|
self.kv_lora_rank = kv_lora_rank
|
||||||
|
|
||||||
|
if v_head_dim is None:
|
||||||
|
v_head_dim = qk_nope_head_dim
|
||||||
|
self.v_head_dim = v_head_dim
|
||||||
|
|
||||||
|
# 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.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
|
||||||
|
self.head_dim = self.qk_nope_head_dim + self.qk_rope_head_dim
|
||||||
|
|
||||||
|
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
|
||||||
7
generation_config.json
Normal file
7
generation_config.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"do_sample": true,
|
||||||
|
"top_p": 0.8,
|
||||||
|
"temperature": 0.8,
|
||||||
|
"bos_token_id": 1,
|
||||||
|
"eos_token_id": [2, 73440]
|
||||||
|
}
|
||||||
1572
modeling_minicpm.py
Normal file
1572
modeling_minicpm.py
Normal file
File diff suppressed because it is too large
Load Diff
3
pytorch_model.bin
Normal file
3
pytorch_model.bin
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:f4c69dfe493d3b644071e1b3820d68f49bcd6674cd40e71b9e451b8534586613
|
||||||
|
size 8148010378
|
||||||
81
special_tokens_map.json
Normal file
81
special_tokens_map.json
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
{
|
||||||
|
"additional_special_tokens": [
|
||||||
|
{
|
||||||
|
"content": "<|im_end|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": "<|im_start|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": "<|tool_call|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": "<|execute_start|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": "<|execute_end|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": "<|fim_prefix|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": "<|fim_middle|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": "<|fim_suffix|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"bos_token": {
|
||||||
|
"content": "<s>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
"eos_token": {
|
||||||
|
"content": "</s>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
"unk_token": {
|
||||||
|
"content": "<unk>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
}
|
||||||
|
}
|
||||||
177952
tokenizer.json
Normal file
177952
tokenizer.json
Normal file
File diff suppressed because it is too large
Load Diff
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
|
||||||
116
tokenizer_config.json
Normal file
116
tokenizer_config.json
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user