当前位置:   article > 正文

通义千问Qwen 1.8B以及7B chat模型本地化部署_qwen-1.8b

qwen-1.8b

本文记录了本地化部署Qwen 1.8B以及7B chat模型的过程。

项目主页:QwenLM/Qwen: The official repo of Qwen (通义千问) chat & pretrained large language model proposed by Alibaba Cloud. (github.com)

1、克隆项目文件

1.1 克隆qwen项目到本地

​git clone https://github.com/QwenLM/Qwen

1.2 创建虚拟环境

  1. conda create -n qwen python=3.11
  2. conda activate qwen

1.3 创建安装依赖环境

pip install -r requirements.txt

1.4 安装GPU版本的pytorh

conda install pytorch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 pytorch-cuda=12.1 -c pytorch -c nvidia

2、下载模型文件

使用魔搭社区进行下载:

通义千问-1_8B-Chat · 模型库 (modelscope.cn)

执行下载命令前,先安装:

 pip install modelscope

建立一个py文件,放入以下代码:

  1. #模型下载
  2. from modelscope import snapshot_download
  3. model_dir = snapshot_download('qwen/Qwen-1_8B-Chat', cache_dir='./model', revision='master')

运行: 这里有个报错:

  1. Traceback (most recent call last):
  2. File "D:\NLP\Qwen\downloads_model.py", line 2, in <module>
  3. from modelscope import snapshot_download
  4. File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\modelscope\__init__.py", line 4, in <module>
  5. from modelscope.utils.import_utils import LazyImportModule
  6. File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\modelscope\utils\__init__.py", line 1, in <module>
  7. from .hub import create_model_if_not_exist, read_config
  8. File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\modelscope\utils\hub.py", line 7, in <module>
  9. from requests import HTTPError
  10. File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\requests\__init__.py", line 45, in <module>
  11. from .exceptions import RequestsDependencyWarning
  12. File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\requests\exceptions.py", line 9, in <module>
  13. from .compat import JSONDecodeError as CompatJSONDecodeError
  14. File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\requests\compat.py", line 13, in <module>
  15. import charset_normalizer as chardet
  16. File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\charset_normalizer\__init__.py", line 23, in <module>
  17. from charset_normalizer.api import from_fp, from_path, from_bytes, normalize
  18. File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\charset_normalizer\api.py", line 10, in <module>
  19. from charset_normalizer.md import mess_ratio
  20. File "charset_normalizer\md.py", line 5, in <module>
  21. ImportError: cannot import name 'COMMON_SAFE_ASCII_CHARACTERS' from 'charset_normalizer.constant' (D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\charset_normalizer\constant.py)

将这个错误复制到文心一言,给出解答:

执行:

pip install --upgrade requests charset_normalizer

又报错了更改命令再执行:

pip install --upgrade requests charset_normalizer --user

安装成功

再次执行,下载脚本:

成功将模型文件下载到本地:

下载7B模型只需要将代码修改为:

model_dir = snapshot_download('qwen/Qwen-7B-Chat', cache_dir='./model', revision='master')

再重新执行即可!

3、配置并启动demo脚本

在终端中运行:

python cli_demo.py

成功开启对话:

能够流畅的进行对话!

输入:h可以看到帮助信息,输入:his可以看到历史对话信息,非常的nice

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/978190
推荐阅读
相关标签
  

闽ICP备14008679号