MiniCPM-2B-sft-bf16 / README.md
hyx21's picture
Upload 9 files
fab7c2d verified

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.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. 北京:作为中国的首都,北京拥有丰富的历史文化遗产,如故宫、长城、天坛等。此外,北京还有许多现代化的景点,如798艺术区、颐和园等。

2. 上海:作为中国的经济中心,上海拥有许多现代化的高楼大厦和繁华的商业区。同时,上海还有许多历史悠久的景点,如外滩、豫园等。

3. 西安:作为古都,西安拥有丰富的历史文化遗产,如兵马俑、大雁塔等。此外,西安还有许多美食,如肉夹馍、羊肉泡馍等。

4. 成都:作为四川的省会,成都有着丰富的美食文化,如火锅、麻辣烫等。此外,成都还有许多自然风光,如青城山、都江堰等。

5. 杭州:作为美丽的西湖所在地,杭州拥有许多自然风光和历史文化遗产,如西湖、灵隐寺等。此外,杭州还有许多美食,如西湖醋鱼、龙井虾仁等。

6. 广州:作为南方的重要城市,广州拥有丰富的美食文化,如广式早茶、烧腊等。此外,广州还有许多现代化景点,如珠江夜游、白云山等。

7. 南京:作为六朝古都,南京拥有丰富的历史文化遗产,如中山陵、夫子庙等。此外,南京还有许多美食,如鸭血粉丝汤、盐水鸭等。

8. 厦门:作为美丽的海滨城市,厦门拥有许多自然风光和历史文化遗产,如鼓浪屿、南普陀寺等。此外,厦门还有许多美食,如沙茶面、土笋冻等。

9. 昆明:作为云南的省会,昆明拥有许多自然风光和历史文化遗产,如石林、滇池等。此外,昆明还有许多美食,如过桥米线、酸笋鱼等。

10. 哈尔滨:作为北方的城市,哈尔滨拥有许多冰雪景观和自然风光,如冰雪大世界、亚布力滑雪场等。此外,哈尔滨还有许多美食,如东北大拉皮、锅包肉等。

以上仅是一些建议,中国还有许多其他适合旅游的城市,具体取决于您的兴趣和偏好。</s>

引用 Reference