---
title: Qwen-2.5-1.5b-instruct-JZFH
canonical_url: "https://www.modelscope.cn/models/FoolBird/Qwen-2.5-1.5b-instruct-JZFH"
md_url: "https://www.modelscope.cn/models/FoolBird/Qwen-2.5-1.5b-instruct-JZFH.md"
repository: FoolBird/Qwen-2.5-1.5b-instruct-JZFH
chinese_name: "千问2.5-1.5B-建筑防火规范"
last_updated: 2024-12-07
license: "Apache License 2.0"
pipeline_tag: text-generation
tasks:
  - text-generation
model_type:
  - qwen2
architectures:
  - Qwen2ForCausalLM
base_model:
  - Qwen/Qwen2.5-1.5B-Instruct
base_model_relation: finetune
parameters: 1.5B
tensor_type:
  - BF16
library_name:
  - pytorch
  - transformer
  - safetensors
frameworks:
  - PyTorch
language:
  - zh
inference_backends:
  - "deploy_task text/emb"
  - "lmdeploy 0.9.1"
  - "lmdeploy_turbomind 0.9.1"
  - "sglang 0.5.2"
  - "vllm 0.9.2"
downloads: 98
stars: 2
---

# Qwen-2.5-1.5b-instruct-JZFH

> Qwen-2.5-1.5b-instruct-JZFH - FoolBird 在 ModelScope 开源的模型。本模型是用数据集FoolBird/GB50016-2014对Qwen2.5-1.5B-Instruct进行预训练，训练轮数250轮 数据集地址https://modelscope.cn/datasets/FoolBird/GB50016-2014 本模型仅供学习使用 您可以通过如下git clone命令，或者ModelScope SDK来下载模型

FoolBird/Qwen-2.5-1.5b-instruct-JZFH 是 ModelScope 魔搭社区上的 1.5B 参数text-generation模型，采用 Apache License 2.0 许可，基于 Qwen/Qwen2.5-1.5B-Instruct 构建，可用 deploy_task text/emb、lmdeploy 0.9.1、lmdeploy_turbomind 0.9.1 部署。

- **Repository**: FoolBird/Qwen-2.5-1.5b-instruct-JZFH
- **License**: Apache License 2.0
- **Tasks**: text-generation
- **Parameters**: 1.5B
- **Base model**: Qwen/Qwen2.5-1.5B-Instruct
- **Inference backends**: deploy_task text/emb, lmdeploy 0.9.1, lmdeploy_turbomind 0.9.1, sglang 0.5.2, vllm 0.9.2
- **Downloads**: 98
- **Stars**: 2
- **Last updated**: 2024-12-07

Source: https://www.modelscope.cn/models/FoolBird/Qwen-2.5-1.5b-instruct-JZFH

---

### 本模型是用数据集FoolBird/GB50016-2014对Qwen2.5-1.5B-Instruct进行预训练，训练轮数250轮
### 数据集地址https://modelscope.cn/datasets/FoolBird/GB50016-2014
### 本模型仅供学习使用
#### 您可以通过如下git clone命令，或者ModelScope SDK来下载模型

SDK下载
```bash
#安装ModelScope
pip install modelscope
```
```python
#SDK模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('FoolBird/Qwen-2.5-1.5b-instruct-JZFH')
```
Git下载
```
#Git模型下载
git clone https://www.modelscope.cn/FoolBird/Qwen-2.5-1.5b-instruct-JZFH.git
```
使用本模型进行推理
```python
# 使用本模型进行推理
from vllm import LLM, SamplingParams
import os
from transformers import AutoModelForCausalLM, AutoTokenizer
from modelscope import snapshot_download
import torch
import time

# 调用 ModelScope 模型
model_id = 'FoolBird/Qwen-2.5-1.5b-instruct-JZFH'  # ModelScope 上的模型 ID

# 初始化全局变量
llm = None
tokenizer = None
sampling_params = None

# 下载 ModelScope 模型
def download_modelscope_model(model_id):
    # 下载模型并返回本地路径
    model_path = snapshot_download(model_id)
    return model_path

# 初始化模型和 tokenizer
def qwen_vllm(model_path):
    # 设置 CUDA 设备为 GPU 2
    os.environ["CUDA_VISIBLE_DEVICES"] = "0"

    global llm, tokenizer
    sum = 1

    # 设置 CUDA 设备为 GPU 2 (在设置的上下文中，它是索引0)
    torch.cuda.set_device(0)

    # 加载模型
    llm = LLM(model=model_path, tensor_parallel_size=sum, dtype=torch.float16, enforce_eager=True, gpu_memory_utilization=0.8, max_model_len=1024)
    tokenizer = AutoTokenizer.from_pretrained(model_path)
    text = "qwen_vllm加载完毕"
    print(text)
    return text

# 使用 VLLM 进行推理
def qwen2_5_inference(info):
    messages = [
        {"role": "system", "content":' You are Qwen, created by Alibaba Cloud. You are a helpful assistant'},
        {"role": "user", "content": info}
    ]

    # 聊天模板的消息
    text = tokenizer.apply_chat_template(
        messages,
        tokenize=False,
        add_generation_prompt=True
    )

    # 清理未使用的显存
    torch.cuda.empty_cache()

    global sampling_params

     
    sampling_params = SamplingParams(temperature=0.7, top_p=0.8, repetition_penalty=1.05, max_tokens=512)
    outputs = llm.generate([text], sampling_params)

    # 流式输出结果
    for output in outputs:
        generated_text = output.outputs[0].text
        for char in generated_text:
            print(char, end='', flush=True)  # 流式输出每个字符
            time.sleep(0.05) 

if __name__ == '__main__':
    model_path = download_modelscope_model(model_id)
    qwen_vllm(model_path)
    while True:
        user_input = input("请输入您的问题: ")
        qwen2_5_inference(user_input)
        print(" ")
        
        
        # 清理未使用的显存
        torch.cuda.empty_cache()
```
