---
title: Qwen3-1.7b-Medical-R1-sft
canonical_url: "https://www.modelscope.cn/models/testUser/Qwen3-1.7b-Medical-R1-sft"
md_url: "https://www.modelscope.cn/models/testUser/Qwen3-1.7b-Medical-R1-sft.md"
repository: testUser/Qwen3-1.7b-Medical-R1-sft
chinese_name: "Qwen3-1.7b-医疗微调微调"
last_updated: 2025-05-18
license: "Apache License 2.0"
pipeline_tag: text-generation
tasks:
  - text-generation
model_type:
  - qwen3
architectures:
  - Qwen3ForCausalLM
parameters: 1.7B
tensor_type:
  - BF16
library_name:
  - pytorch
  - transformer
  - safetensors
frameworks:
  - Pytorch
inference_backends:
  - "deploy_task text/emb"
  - "lmdeploy_turbomind 0.9.1"
  - "sglang 0.5.2"
  - "vllm 0.9.2"
downloads: 606
stars: 4
---

# Qwen3-1.7b-Medical-R1-sft

> Qwen3-1.7b-Medical-R1-sft - testUser 在 ModelScope 开源的模型。基础模型：Qwen3-1.7B 微调后模型：Qwen3-1.7b-Medical-R1-sft 数据集：delicatemedicalr1data SwanLab：qwen3-sft-medical 微调方式：全参数微调、LoRA微调 推理风格：R1推理风格 算力要求： 全参数微调：32GB显存 LoRA微调：28GB显存 图文教程：Qwen3大模型微调入门实战（完整代码）

testUser/Qwen3-1.7b-Medical-R1-sft 是 ModelScope 魔搭社区上的 1.7B 参数text-generation模型，采用 Apache License 2.0 许可，可用 deploy_task text/emb、lmdeploy_turbomind 0.9.1、sglang 0.5.2 部署。

- **Repository**: testUser/Qwen3-1.7b-Medical-R1-sft
- **License**: Apache License 2.0
- **Tasks**: text-generation
- **Parameters**: 1.7B
- **Inference backends**: deploy_task text/emb, lmdeploy_turbomind 0.9.1, sglang 0.5.2, vllm 0.9.2
- **Downloads**: 606
- **Stars**: 4
- **Last updated**: 2025-05-18

Source: https://www.modelscope.cn/models/testUser/Qwen3-1.7b-Medical-R1-sft

---

[Github](https://github.com/Zeyi-Lin/Qwen3-Medical-SFT)

- **基础模型**：[Qwen3-1.7B](https://modelscope.cn/models/Qwen/Qwen3-1.7B/summary)
- **微调后模型**：[Qwen3-1.7b-Medical-R1-sft](https://modelscope.cn/models/testUser/Qwen3-1.7b-Medical-R1-sft/summary)
- **数据集**：[delicate_medical_r1_data](https://modelscope.cn/datasets/krisfu/delicate_medical_r1_data)
- **SwanLab**：[qwen3-sft-medical](https://swanlab.cn/@ZeyiLin/qwen3-sft-medical/runs/agps0dkifth5l1xytcdyk/chart)
- **微调方式**：全参数微调、LoRA微调
- **推理风格**：R1推理风格
- **算力要求**：
  - **全参数微调**：32GB显存
  - **LoRA微调**：28GB显存
- **图文教程**：[Qwen3大模型微调入门实战（完整代码）](https://zhuanlan.zhihu.com/p/1903848838214705484)

## 模型下载

```bash
#安装ModelScope
pip install modelscope
```
```python
#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
```

<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>

## 模型推理

```bash
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)
```
