File size: 3,765 Bytes
c2b5bb7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# MiniCPM
## 介绍 Introduction
- 与`Llama`的关系 The Relationship between `Llama`
`MiniCPM`与`Llama`均使用了仅解码器架构。代码实现上,`MiniCPM`基于`Llama`实现,增加了放缩机制。
`MiniCPM` uses Decoder-only Structure as well as `Llama`. The implementation of `MiniCPM` is based on `Llama` code, with scaling mechenism added.
## 软件依赖 Dependency
- `transformers >= 4.36.0`
- `accelerate`
## 使用 Usage
我们推荐使用`AutoModelForCausalLM`与`AutoTokenizer`载入`MiniCPM`,并使用`torch.bfloat16`作为计算精度。我们推荐在GPU上进行推理。
We recommend using `AutoModelForCausalLM` and `AutoTokenizer` to load `MiniCPM`, and use `torch.bfloat16` as the calculation precision. GPU reference is recommended.
以下是一个使用`MiniCPM`生成的例子。
An example is provided below for using `MiniCPM` to generate tokens.
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
path = '/data/miniCPM_opensource/miniCPM-bf16' # TODO
tokenizer = AutoTokenizer.from_pretrained(path)
model = AutoModelForCausalLM.from_pretrained(path, torch_dtype=torch.bfloat16, device_map='auto', trust_remote_code=True)
dialog = [{'role': 'user', 'content': '请问中国哪几个城市最适合旅游?'}]
input = tokenizer.apply_chat_template(dialog, tokenize=False, add_generation_prompt=False)
enc = tokenizer(input, return_tensors='pt').to('cuda')
output = model.generate(**enc, max_length=1024)
print(tokenizer.decode(output[0]))
```
期望的输出 Expected Output:
```
<s> <用户>请问中国哪几个城市最适合旅游?<AI> 中国是一个拥有丰富旅游资源的国家,有很多城市都适合旅游。以下是一些建议:
1. 北京:作为中国的首都,北京拥有许多著名的景点,如故宫、天安门广场、颐和园、长城等。此外,北京还有许多美食和购物场所。
2. 上海:上海是中国最大的城市之一,拥有许多著名的景点,如外滩、东方明珠、豫园、上海迪士尼乐园等。此外,上海还有许多美食和购物场所。
3. 西安:西安是中国历史悠久的古都,拥有许多著名的景点,如兵马俑、大雁塔、华清池等。此外,西安还有许多美食和购物场所。
4. 成都:成都是中国西南地区的中心城市,拥有许多著名的景点,如大熊猫繁育研究基地、武侯祠、锦里古街等。此外,成都还有许多美食和购物场所。
5. 杭州:杭州是中国东南地区的中心城市,拥有许多著名的景点,如西湖、灵隐寺、千岛湖等。此外,杭州还有许多美食和购物场所。
6. 广州:广州是中国南方地区的中心城市,拥有许多著名的景点,如白云山、珠江夜游、陈家祠等。此外,广州还有许多美食和购物场所。
7. 厦门:厦门是中国东南沿海的城市,拥有许多著名的景点,如鼓浪屿、南普陀寺、厦门大学等。此外,厦门还有许多美食和购物场所。
8. 昆明:昆明是中国西南地区的中心城市,拥有许多著名的景点,如石林、滇池、翠湖等。此外,昆明还有许多美食和购物场所。
9. 桂林:桂林是中国南方地区的中心城市,拥有许多著名的景点,如漓江、阳朔、象山等。此外,桂林还有许多美食和购物场所。
10. 西藏:西藏是中国西南地区的中心城市,拥有许多著名的景点,如布达拉宫、大昭寺、纳木错等。此外,西藏还有许多美食和购物场所。
以上是一些建议,当然还有很多其他城市也适合旅游。在选择旅游目的地时,可以根据自己的兴趣和喜好来决定。</s>
```
## 引用 Reference |