c225a91206f718dc4f3c45e12d8db7b28be18f91
Model: testUser/Qwen3-1.7b-Medical-R1-sft Source: Original Platform
frameworks, license, tasks
| frameworks | license | tasks | ||
|---|---|---|---|---|
|
Apache License 2.0 |
|
- 基础模型:Qwen3-1.7B
- 微调后模型:Qwen3-1.7b-Medical-R1-sft
- 数据集:delicate_medical_r1_data
- SwanLab:qwen3-sft-medical
- 微调方式:全参数微调、LoRA微调
- 推理风格:R1推理风格
- 算力要求:
- 全参数微调:32GB显存
- LoRA微调:28GB显存
- 图文教程:Qwen3大模型微调入门实战(完整代码)
模型下载
#安装ModelScope
pip install modelscope
#SDK模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('testUser/Qwen3-1.7b-Medical-R1-sft')
Git下载
#Git模型下载
git clone https://www.modelscope.cn/testUser/Qwen3-1.7b-Medical-R1-sft.git
如果您是本模型的贡献者,我们邀请您根据模型贡献文档,及时完善模型卡片内容。
模型推理
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
def predict(messages, model, tokenizer):
if torch.backends.mps.is_available():
device = "mps"
elif torch.cuda.is_available():
device = "cuda"
else:
device = "cpu"
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
model_inputs = tokenizer([text], return_tensors="pt").to(device)
generated_ids = model.generate(model_inputs.input_ids, max_new_tokens=2048)
generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
return response
# 加载原下载路径的tokenizer和model
tokenizer = AutoTokenizer.from_pretrained("./Qwen3-1.7b-Medical-R1-sft", use_fast=False, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("./Qwen3-1.7b-Medical-R1-sft", device_map="auto", torch_dtype=torch.bfloat16)
test_texts = {
'instruction': "你是一个医学专家,你需要根据用户的问题,给出带有思考的回答。",
'input': "医生,我最近被诊断为糖尿病,听说碳水化合物的选择很重要,我应该选择什么样的碳水化合物呢?"
}
instruction = test_texts['instruction']
input_value = test_texts['input']
messages = [
{"role": "system", "content": f"{instruction}"},
{"role": "user", "content": f"{input_value}"}
]
response = predict(messages, model, tokenizer)
print(response)
Description