当前位置:   article > 正文

大模型部署手记(20)Windows+Qwen-VL-Chat-Int4_qianwen大模型本地部署

qianwen大模型本地部署

参考 https://modelscope.cn/models/qwen/Qwen-VL-Chat-Int4/summary

conda create -n qwenvl python=3.8

conda activate qwenvl

pip install modelscope -U

网络一如既往的不大好。。

pip install modelscope -U -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install transformers accelerate tiktoken -U -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install einops transformers_stream_generator -U -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install "pillow==9.*" -U -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install matplotlib -U -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install optimum -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install auto-gptq -i https://pypi.tuna.tsinghua.edu.cn/simple

#pip install transformers_stream_generator -i https://pypi.tuna.tsinghua.edu.cn/simple

mkdir Qwen-VL-Chat-Int4

cd Qwen-VL-Chat-Int4

下载模型权重文件:

python download.py

from modelscope import ( snapshot_download, AutoModelForCausalLM, AutoTokenizer, GenerationConfig ) from auto_gptq import AutoGPTQForCausalLM model_dir = snapshot_download("qwen/Qwen-VL-Chat-Int4", revision='v1.0.0')

文件会下载到:C:\Users\xishu\.cache\modelscope\hub\qwen\Qwen-VL-Chat-Int4

为了节省C盘空间,可以将这个目录下的文件移到 F:\models\Qwen\Qwen-VL-Chat-Int4目录下。

python model_test.py

  1. from modelscope import (
  2. snapshot_download, AutoModelForCausalLM, AutoTokenizer, GenerationConfig
  3. )
  4. from auto_gptq import AutoGPTQForCausalLM
  5. import torch
  6. torch.manual_seed(1234)
  7. model_dir = "F:\\models\\Qwen\\Qwen-VL-Chat-Int4"
  8. # Note: The default behavior now has injection attack prevention off.
  9. tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
  10. # use cuda device
  11. model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="cuda", trust_remote_code=True,use_safetensors=True).eval()
  12. # 1st dialogue turn
  13. query = tokenizer.from_list_format([
  14. {'image': 'https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg'},
  15. {'text': '这是什么'},
  16. ])
  17. response, history = model.chat(tokenizer, query=query, history=None)
  18. print(response)
  19. # 图中是一名年轻女子在沙滩上和她的狗玩耍,狗的品种可能是拉布拉多。她们坐在沙滩上,狗的前腿抬起来,似乎在和人类击掌。两人之间充满了信任和爱。
  20. # 2nd dialogue turn
  21. response, history = model.chat(tokenizer, '输出"狗"的检测框', history=history)
  22. print(response)
  23. image = tokenizer.draw_bbox_on_latest_picture(response, history)
  24. if image:
  25. image.save('1.jpg')
  26. else:
  27. print("no box")

查看下:

确实不是GPU版本的torch 2.1.0

conda install pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.8 -c pytorch -c nvidia

pip install chardet -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install cchardet -i https://pypi.tuna.tsinghua.edu.cn/simple

python model_test.py

看看原图:

图中是一名年轻女子在沙滩上和她的狗玩耍,太阳升起时分,女子穿着格子衬衫,狗也十分开心。

换一张图试试,另外把最后一段执行不了的语句注释了,并将图片放在当前目录下:

python model_test.py

  1. from modelscope import (
  2. snapshot_download, AutoModelForCausalLM, AutoTokenizer, GenerationConfig
  3. )
  4. from auto_gptq import AutoGPTQForCausalLM
  5. import torch
  6. torch.manual_seed(1234)
  7. model_dir = "F:\\models\\Qwen\\Qwen-VL-Chat-Int4"
  8. # Note: The default behavior now has injection attack prevention off.
  9. tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
  10. # use cuda device
  11. model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="cuda", trust_remote_code=True,use_safetensors=True).eval()
  12. # 1st dialogue turn
  13. query = tokenizer.from_list_format([
  14. # {'image': 'https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg'},
  15. {'image': 'F:\\Qwen-VL-Chat-Int4\\v001.png'},
  16. {'text': '这是什么'},
  17. ])
  18. response, history = model.chat(tokenizer, query=query, history=None)
  19. print(response)
  20. # 图中是一名年轻女子在沙滩上和她的狗玩耍,狗的品种可能是拉布拉多。她们坐在沙滩上,狗的前腿抬起来,似乎在和人类击掌。两人之间充满了信任和爱。
  21. # 2nd dialogue turn
  22. response, history = model.chat(tokenizer, '输出"狗"的检测框', history=history)
  23. print(response)
  24. #image = tokenizer.draw_bbox_on_latest_picture(response, history)
  25. #if image:
  26. # image.save('1.jpg')
  27. #else:
  28. # print("no box")

  1. (qwenvl) PS F:\Qwen-VL-Chat-Int4> python model_test.py
  2. 2023-10-27 16:04:01,190 - modelscope - INFO - PyTorch version 2.0.1 Found.
  3. 2023-10-27 16:04:01,191 - modelscope - INFO - Loading ast index from C:\Users\xishu\.cache\modelscope\ast_indexer
  4. 2023-10-27 16:04:01,372 - modelscope - INFO - Loading done! Current index file version is 1.9.4, with md5 48e2dcc06101841d72dc52fe2751aa5c and a total number of 945 components indexed
  5. Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 5/5 [00:04<00:00, 1.07it/s]
  6. 这张照片是泰坦尼克号电影的剧照,展示的是男主角 Jack 和女主角 Rose 在船的栏杆旁伸出手臂,背靠背站立,身后是夕阳和大海。
  7. <ref></ref><box>(0,288),(759,983)</box>
  8. (qwenvl) PS F:\Qwen-VL-Chat-Int4>

不过,,这图片里面并没有狗。。。难道”舔狗“也算狗?

下面看看怎么做成网页方式。

cd F:\Langchain-Chatchat\

conda deactivate

conda activate chatchat

pythonstartup.py--all-webui

ValueError: Found modules on cpu/disk. Using Exllama backend requires all the modules to be on GPU.You can deactivate exllama backend by setting `disable_exllama=True` in the quantization config object

查看

https://github.com/lm-sys/FastChat/issues/2459​github.com/lm-sys/FastChat/issues/2459

需要修改一下模型下的文件:config.json

在 quantization_config 增加一行: "disable_exllama": true,

重新执行:

网页也加载了。不过还不知道怎么输入图片。

输入对话:

貌似还有点问题:

可能还得想别的办法搞页面了。

下载github代码仓:

F:

cd \

git clone https://github.com/QwenLM/Qwen-VL

cd Qwen-VL

pip install -r requirements_web_demo.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

修改 web_demo_mm.py 中模型文件的路径:

DEFAULT_CKPT_PATH = 'Qwen/Qwen-VL-Chat'

改为:

DEFAULT_CKPT_PATH = '\\models\\Qwen\\Qwen-VL-Chat-Int4'

python web_demo_mm.py

打开网页:http://127.0.0.1:8000/

可以先点击upload上传一个图片,然后再问它这个图片是什么意思。

是的,可以发给它照片提问,但是不能以照片回答。

(全文完,谢谢阅读)

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

闽ICP备14008679号