赞
踩
本文记录了本地化部署Qwen 1.8B以及7B chat模型的过程。
git clone https://github.com/QwenLM/Qwen
- conda create -n qwen python=3.11
- conda activate qwen
pip install -r requirements.txt
conda install pytorch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 pytorch-cuda=12.1 -c pytorch -c nvidia
使用魔搭社区进行下载:
通义千问-1_8B-Chat · 模型库 (modelscope.cn)
执行下载命令前,先安装:
pip install modelscope
建立一个py文件,放入以下代码:
- #模型下载
- from modelscope import snapshot_download
- model_dir = snapshot_download('qwen/Qwen-1_8B-Chat', cache_dir='./model', revision='master')
运行: 这里有个报错:
- Traceback (most recent call last):
- File "D:\NLP\Qwen\downloads_model.py", line 2, in <module>
- from modelscope import snapshot_download
- File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\modelscope\__init__.py", line 4, in <module>
- from modelscope.utils.import_utils import LazyImportModule
- File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\modelscope\utils\__init__.py", line 1, in <module>
- from .hub import create_model_if_not_exist, read_config
- File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\modelscope\utils\hub.py", line 7, in <module>
- from requests import HTTPError
- File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\requests\__init__.py", line 45, in <module>
- from .exceptions import RequestsDependencyWarning
- File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\requests\exceptions.py", line 9, in <module>
- from .compat import JSONDecodeError as CompatJSONDecodeError
- File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\requests\compat.py", line 13, in <module>
- import charset_normalizer as chardet
- File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\charset_normalizer\__init__.py", line 23, in <module>
- from charset_normalizer.api import from_fp, from_path, from_bytes, normalize
- File "D:\ProgramData\anaconda3\envs\qwen\Lib\site-packages\charset_normalizer\api.py", line 10, in <module>
- from charset_normalizer.md import mess_ratio
- File "charset_normalizer\md.py", line 5, in <module>
- 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')
再重新执行即可!
在终端中运行:
python cli_demo.py
成功开启对话:
能够流畅的进行对话!
输入:h可以看到帮助信息,输入:his可以看到历史对话信息,非常的nice
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。