mirror of
https://github.com/QwenLM/Qwen.git
synced 2026-05-20 16:35:47 +08:00
Update README_CN.md
revise modelscope quickstart
This commit is contained in:
31
README_CN.md
31
README_CN.md
@@ -172,28 +172,19 @@ print(tokenizer.decode(pred.cpu()[0], skip_special_tokens=True))
|
|||||||
魔搭(ModelScope)是开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品。使用ModelScope同样非常简单,代码如下所示:
|
魔搭(ModelScope)是开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品。使用ModelScope同样非常简单,代码如下所示:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import os
|
from modelscope import AutoModelForCausalLM, AutoTokenizer
|
||||||
from modelscope.pipelines import pipeline
|
from modelscope import GenerationConfig
|
||||||
from modelscope.utils.constant import Tasks
|
|
||||||
from modelscope import snapshot_download
|
|
||||||
|
|
||||||
model_id = 'QWen/qwen-7b-chat'
|
tokenizer = AutoTokenizer.from_pretrained("qwen/Qwen-7B-Chat", revision = 'v1.0.5',trust_remote_code=True)
|
||||||
revision = 'v1.0.0'
|
model = AutoModelForCausalLM.from_pretrained("qwen/Qwen-7B-Chat", revision = 'v1.0.5',device_map="auto", trust_remote_code=True,fp16 = True).eval()
|
||||||
|
model.generation_config = GenerationConfig.from_pretrained("Qwen/Qwen-7B-Chat",revision = 'v1.0.5', trust_remote_code=True) # 可指定不同的生成长度、top_p等相关超参
|
||||||
|
|
||||||
model_dir = snapshot_download(model_id, revision)
|
response, history = model.chat(tokenizer, "你好", history=None)
|
||||||
|
print(response)
|
||||||
pipe = pipeline(
|
response, history = model.chat(tokenizer, "浙江的省会在哪里?", history=history)
|
||||||
task=Tasks.chat, model=model_dir, device_map='auto')
|
print(response)
|
||||||
history = None
|
response, history = model.chat(tokenizer, "它有什么好玩的景点", history=history)
|
||||||
|
print(response)
|
||||||
text = '浙江的省会在哪里?'
|
|
||||||
results = pipe(text, history=history)
|
|
||||||
response, history = results['response'], results['history']
|
|
||||||
print(f'Response: {response}')
|
|
||||||
text = '它有什么好玩的地方呢?'
|
|
||||||
results = pipe(text, history=history)
|
|
||||||
response, history = results['response'], results['history']
|
|
||||||
print(f'Response: {response}')
|
|
||||||
```
|
```
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user