MiniCPM-2B-dpo-fp16 / README.md
hyx21's picture
Upload 9 files
652927b verified
|
raw
history blame
No virus
3.1 kB

MiniCPM

介绍 Introduction

  • Llama的关系 The Relationship between Llama

    MiniCPMLlama均使用了仅解码器架构。代码实现上,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

我们推荐使用AutoModelForCausalLMAutoTokenizer载入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.

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.float32, 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