QwenLM / Qwen2-VL

Qwen2-VL is the multimodal large language model series developed by Qwen team, Alibaba Cloud.
Apache License 2.0
2.99k stars 175 forks source link

大佬,我模型下载到本地了,想在本地加载应该怎么写 #106

Open StartHua opened 2 months ago

StartHua commented 2 months ago

model = Qwen2VLForConditionalGeneration.from_pretrained( MODEL_PATH, torch_dtype="auto", device_map="auto",local_files_only=True # 确保只从本地加载
)

Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 2/2 [00:03<00:00, 1.52s/it] !!! Exception during processing !!! Incorrect path_or_model_id: 'Qwen2VLForConditionalGeneration( (visual): Qwen2VisionTransformerPretrainedModel( (patch_embed): PatchEmbed( (proj): Conv3d(3, 1280, kernel_size=(2, 14, 14), stride=(2, 14, 14), bias=False) ) (rotary_pos_emb): VisionRotaryEmbedding() (blocks): ModuleList( (0-31): 32 x Qwen2VLVisionBlock( (norm1): LayerNorm((1280,), eps=1e-06, elementwise_affine=True) (norm2): LayerNorm((1280,), eps=1e-06, elementwise_affine=True) (attn): VisionSdpaAttention( (qkv): Linear(in_features=1280, out_features=3840, bias

YoungofNUAA commented 2 months ago

model = Qwen2VLForConditionalGeneration.from_pretrained( MODEL_PATH, torch_dtype="auto", device_map="auto",local_files_only=True # 确保只从本地加载 )

Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 2/2 [00:03<00:00, 1.52s/it] !!! Exception during processing !!! Incorrect path_or_model_id: 'Qwen2VLForConditionalGeneration( (visual): Qwen2VisionTransformerPretrainedModel( (patch_embed): PatchEmbed( (proj): Conv3d(3, 1280, kernel_size=(2, 14, 14), stride=(2, 14, 14), bias=False) ) (rotary_pos_emb): VisionRotaryEmbedding() (blocks): ModuleList( (0-31): 32 x Qwen2VLVisionBlock( (norm1): LayerNorm((1280,), eps=1e-06, elementwise_affine=True) (norm2): LayerNorm((1280,), eps=1e-06, elementwise_affine=True) (attn): VisionSdpaAttention( (qkv): Linear(in_features=1280, out_features=3840, bias

cannot import name 'Qwen2VLForConditionalGeneration' from 'transformers' 我这边报错,请问你transformers用的什么版本

StartHua commented 2 months ago

main 版本

YoungofNUAA commented 2 months ago

main 版本

transformers 4.44.2 我装了最新的提示cannot import name 'Qwen2VLForConditionalGeneration' from 'transformers' 很奇怪

StartHua commented 2 months ago

我看了源码4.44.2里面没有,你要用main版本 最笨的方法下载git main版本直接到python环境里面替换掉

xml4cn commented 2 months ago

readme里有安装依赖的各种注意事项,还有demo代码。 主要是transformers的最新版本还没有集成Qwen2-VL的代码,需要拉main分支。 torch和torchversion根据你的cuda版本在PyTorch官网生成指令。 我的cuda是11.8版本,安装命令如下: pip install -r requirements_web_demo.txt --index-url https://download.pytorch.org/whl/cu118

requirements_web_demo.txt 内容:

# Core dependencies
gradio==4.42.0
gradio_client==1.3.0
qwen-vl-utils==0.0.2
transformers-stream-generator==0.0.4
torch==2.4.0
torchvision==0.19.0
git+https://github.com/huggingface/transformers.git
accelerate
av

# Optional dependency
# Uncomment the following line if you need flash-attn
# flash-attn==2.6.1
badarrrr commented 2 months ago

https://github.com/huggingface/transformers 要手动安装,克隆transformers 仓库到本地,然后换到目录下再pip install . 最后会安装transformers-4.45.0.dev0非正式版本

fyabc commented 1 month ago

model = Qwen2VLForConditionalGeneration.from_pretrained( MODEL_PATH, torch_dtype="auto", device_map="auto",local_files_only=True # 确保只从本地加载 ) Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 2/2 [00:03<00:00, 1.52s/it] !!! Exception during processing !!! Incorrect path_or_model_id: 'Qwen2VLForConditionalGeneration( (visual): Qwen2VisionTransformerPretrainedModel( (patch_embed): PatchEmbed( (proj): Conv3d(3, 1280, kernel_size=(2, 14, 14), stride=(2, 14, 14), bias=False) ) (rotary_pos_emb): VisionRotaryEmbedding() (blocks): ModuleList( (0-31): 32 x Qwen2VLVisionBlock( (norm1): LayerNorm((1280,), eps=1e-06, elementwise_affine=True) (norm2): LayerNorm((1280,), eps=1e-06, elementwise_affine=True) (attn): VisionSdpaAttention( (qkv): Linear(in_features=1280, out_features=3840, bias

cannot import name 'Qwen2VLForConditionalGeneration' from 'transformers' 我这边报错,请问你transformers用的什么版本

您好,请参考此处 安装正确的transformers版本。