当前位置:   article > 正文

qwen-vl本地部署记录_qwenvl github

qwenvl github

写在前面:本次部署版本为Qwen-VL-Chat-Int4(卑微),电脑配置:ubuntu22.04;显卡:RTX4090 24G,以下为搬运工记录

三个参考链接:

  1. qwen-vl代码仓库链接:https://github.com/QwenLM/Qwen-VL
  2. Qwen-VL-Chat-Int4模型权重链接:Qwen/Qwen-VL-Chat-Int4 at main
  3. 使用参考文档链接:魔搭社区

部署:只需4步

(前提:已经安装了anaconda)

1、下载代码:

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

2、配置环境python建议使用3.10,本人尝试过3.12会导致failed to build totenizers从而环境安装失败。

  1. conda create -name qwenvl python=3.10
  2. cd Qwen-VL
  3. pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
  4. ###建议添加清华镜像提高包的安装时间

3、配置Qwen-VL-Chat-Int4额外依赖库:

  1. pip install optimum -i https://pypi.tuna.tsinghua.edu.cn/simple
  2. pip install auto-gptq -i https://pypi.tuna.tsinghua.edu.cn/simple
  3. pip install modelscope -U -i https://pypi.tuna.tsinghua.edu.cn/simple

4、测试Demo:代码test.py内容如下:执行python 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. ##Qwen-VL-Chat-Int4模型权重文件夹路径,可通过第三个链接下载
  8. model_dir = "./Qwen-VL-Chat-Int4"
  9. # Note: The default behavior now has injection attack prevention off.
  10. tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
  11. # use cuda device
  12. model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="cuda", trust_remote_code=True,use_safetensors=True).eval()
  13. # 1st dialogue turn
  14. query = tokenizer.from_list_format([
  15. {'image': 'https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg'},
  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")

结果显示:

分割线:


以下内容可忽略,对部署没有贡献但是确实遇到的问题记录



遇到报错:ERROR: Could not build wheels for tokenizers, which is required to install pyproject.toml-based projects

 解决方法:安装rust:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

直接安装太慢,需要配置安装源

  1. curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf > rust.sh && chmod +x rust.sh
  2. ##设置环境变量
  3. ##export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
  4. export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup
  5. export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
  6. ./rust.sh
  7. ##安装成功

安装成功后依旧解决不了问题,最后将python3.12降低到python3.10后得以解决

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

闽ICP备14008679号