Files

110 lines
2.7 KiB
Markdown
Raw Permalink Normal View History

---
frameworks:
- Pytorch
license: Apache License 2.0
tasks:
- text-generation
#model-type:
##如 gpt、phi、llama、chatglm、baichuan 等
#- gpt
#domain:
##如 nlp、cv、audio、multi-modal
#- nlp
#language:
##语言代码列表 https://help.aliyun.com/document_detail/215387.html?spm=a2c4g.11186623.0.0.9f8d7467kni6Aa
#- cn
#metrics:
##如 CIDEr、Blue、ROUGE 等
#- CIDEr
#tags:
##各种自定义,包括 pretrained、fine-tuned、instruction-tuned、RL-tuned 等训练方法和其他
#- pretrained
#tools:
##如 vllm、fastchat、llamacpp、AdaSeq 等
#- vllm
---
### 当前模型的贡献者未提供更加详细的模型介绍。模型文件和权重,可浏览“模型文件”页面获取。
#### 您可以通过如下git clone命令或者ModelScope SDK来下载模型
SDK下载
```bash
#安装ModelScope
pip install modelscope
```
```python
#SDK模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('bruce870101/qwen2.5_7B_traditional_chinese_medicine')
```
Git下载
```
#Git模型下载
git clone https://www.modelscope.cn/bruce870101/qwen2.5_7B_traditional_chinese_medicine.git
```
本地加载模型的试用案例
```
from transformers import AutoTokenizer
from transformers.models.qwen2 import Qwen2ForCausalLM
import torch
model_path = 大模型的本地绝对路径
# 加载分词器和模型
tokenizer = AutoTokenizer.from_pretrained(
model_path,
trust_remote_code=True,
local_files_only=True
)
model = Qwen2ForCausalLM.from_pretrained(
model_path,
trust_remote_code=True,
torch_dtype=torch.float16,
device_map="auto",
local_files_only=True
).eval()
# 使用 Qwen2.5 的正确生成方式
prompt = "你好,请解析一下中医所说的气,是指什么?"
# 使用聊天模板构建输入
messages = [
{"role": "system", "content": "你是一个知识渊博的中医医疗助手"},
{"role": "user", "content": prompt}
]
# 应用聊天模板
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
# 编码输入
inputs = tokenizer([text], return_tensors="pt").to(model.device)
# 生成回复
outputs = model.generate(
**inputs,
max_new_tokens=512,
pad_token_id=tokenizer.eos_token_id,
eos_token_id=tokenizer.eos_token_id,
do_sample=True,
temperature=0.7,
top_p=0.9
)
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
print(response)
```
<p style="color: lightgrey;">如果您是本模型的贡献者,我们邀请您根据<a href="https://modelscope.cn/docs/ModelScope%E6%A8%A1%E5%9E%8B%E6%8E%A5%E5%85%A5%E6%B5%81%E7%A8%8B%E6%A6%82%E8%A7%88" style="color: lightgrey; text-decoration: underline;">模型贡献文档</a>,及时完善模型卡片内容。</p>