tjdnbj 2025-03-12 20:31 采纳率: 36.8%
浏览 25

deepseekvl2部署询问

想问一下部署deepseekvl2,运行github上面的sample后出现这个问题怎么解决呢?

import torch
from transformers import AutoModelForCausalLM

from deepseek_vl2.models import DeepseekVLV2Processor, DeepseekVLV2ForCausalLM
from deepseek_vl2.utils.io import load_pil_images


# specify the path to the model
model_path = "deepseek-ai/deepseek-vl2-small"
vl_chat_processor: DeepseekVLV2Processor = DeepseekVLV2Processor.from_pretrained(model_path)
tokenizer = vl_chat_processor.tokenizer

vl_gpt: DeepseekVLV2ForCausalLM = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True)
vl_gpt = vl_gpt.to(torch.bfloat16).cuda().eval()

## single image conversation example
conversation = [
    {
        "role": "<|User|>",
        "content": "<image>\n<|ref|>The giraffe at the back.<|/ref|>.",
        "images": ["./images/visual_grounding.jpeg"],
    },
    {"role": "<|Assistant|>", "content": ""},
]

## multiple images (or in-context learning) conversation example
# conversation = [
#     {
#         "role": "User",
#         "content": "<image_placeholder>A dog wearing nothing in the foreground, "
#                    "<image_placeholder>a dog wearing a santa hat, "
#                    "<image_placeholder>a dog wearing a wizard outfit, and "
#                    "<image_placeholder>what's the dog wearing?",
#         "images": [
#             "images/dog_a.png",
#             "images/dog_b.png",
#             "images/dog_c.png",
#             "images/dog_d.png",
#         ],
#     },
#     {"role": "Assistant", "content": ""}
# ]

# load images and prepare for inputs
pil_images = load_pil_images(conversation)
prepare_inputs = vl_chat_processor(
    conversations=conversation,
    images=pil_images,
    force_batchify=True,
    system_prompt=""
).to(vl_gpt.device)

# run image encoder to get the image embeddings
inputs_embeds = vl_gpt.prepare_inputs_embeds(**prepare_inputs)

# run the model to get the response
outputs = vl_gpt.language_model.generate(
    inputs_embeds=inputs_embeds,
    attention_mask=prepare_inputs.attention_mask,
    pad_token_id=tokenizer.eos_token_id,
    bos_token_id=tokenizer.bos_token_id,
    eos_token_id=tokenizer.eos_token_id,
    max_new_tokens=512,
    do_sample=False,
    use_cache=True
)

answer = tokenizer.decode(outputs[0].cpu().tolist(), skip_special_tokens=True)
print(f"{prepare_inputs['sft_format'][0]}", answer)


OSError Traceback (most recent call last)
Cell In[2], line 10
8 # specify the path to the model
9 model_path = "deepseek-ai/deepseek-vl2-small"
---> 10 vl_chat_processor: DeepseekVLV2Processor = DeepseekVLV2Processor.from_pretrained(model_path)
11 tokenizer = vl_chat_processor.tokenizer
13 vl_gpt: DeepseekVLV2ForCausalLM = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True)

File ~/autodl-tmp/conda/envs/DeepSeek_VL2/lib/python3.8/site-packages/transformers/processing_utils.py:465, in ProcessorMixin.from_pretrained(cls, pretrained_model_name_or_path, cache_dir, force_download, local_files_only, token, revision, **kwargs)
462 if token is not None:
463 kwargs["token"] = token
--> 465 args = cls._get_arguments_from_pretrained(pretrained_model_name_or_path, **kwargs)
466 processor_dict, kwargs = cls.get_processor_dict(pretrained_model_name_or_path, **kwargs)
468 return cls.from_args_and_dict(args, processor_dict, **kwargs)

File ~/autodl-tmp/conda/envs/DeepSeek_VL2/lib/python3.8/site-packages/transformers/processing_utils.py:511, in ProcessorMixin._get_arguments_from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
508 else:
509 attribute_class = getattr(transformers_module, class_name)
--> 511 args.append(attribute_class.from_pretrained(pretrained_model_name_or_path, **kwargs))
512 return args

File ~/autodl-tmp/conda/envs/DeepSeek_VL2/lib/python3.8/site-packages/transformers/tokenization_utils_base.py:2032, in PreTrainedTokenizerBase.from_pretrained(cls, pretrained_model_name_or_path, cache_dir, force_download, local_files_only, token, revision, trust_remote_code, *init_inputs, **kwargs)
2026 logger.info(
2027 f"Can't load following files from cache: {unresolved_files} and cannot check if these "
2028 "files are necessary for the tokenizer to operate."
2029 )
2031 if all(full_file_name is None for full_file_name in resolved_vocab_files.values()):
-> 2032 raise EnvironmentError(
2033 f"Can't load tokenizer for '{pretrained_model_name_or_path}'. If you were trying to load it from "
2034 "'https://huggingface.co/models', make sure you don't have a local directory with the same name. "
2035 f"Otherwise, make sure '{pretrained_model_name_or_path}' is the correct path to a directory "
2036 f"containing all relevant files for a {cls.name} tokenizer."
2037 )
2039 for file_id, file_path in vocab_files.items():
2040 if file_id not in resolved_vocab_files:

OSError: Can't load tokenizer for 'deepseek-ai/deepseek-vl2-small'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'deepseek-ai/deepseek-vl2-small' is the correct path to a directory containing all relevant files for a LlamaTokenizerFast tokenizer.
[ ]:

  • 写回答

4条回答 默认 最新

  • 道友老李 JWE233286一种基于机器视觉的水表指针读数识别及修正的方法 专利发明者 2025-03-12 20:31
    关注
    让【道友老李】来帮你解答,本回答参考gpt编写,并整理提供,如果还有疑问可以点击头像关注私信或评论。
    如果答案让您满意,请采纳、关注,非常感谢!
    这个错误看起来是由于无法找到指定的预训练模型路径引起的。请确保`model_path`指向的模型路径是正确的,如果是使用特定的预训练模型,还需要检查是否已经下载了该模型。 另外,如果您要运行GitHub上的示例代码,建议在运行之前先查看README文件或者文档,确保已经按照要求安装了所有必要的依赖项。 以下是可能的解决方案和代码片段:
    1. 确保正确指定预训练模型路径:
    model_path = "deepseek-ai/deepseek-vl2-small"
    
    1. 确保已经下载了指定的预训练模型:
    transformers-cli repo_info deepseek-ai/deepseek-vl2-small
    
    1. 可尝试更换其他预训练模型路径,或查看DeepseekVLV2Processor.from_pretrained()方法的文档,了解更多参数信息。 希望这些提示对您有帮助,如果需要进一步的帮助,请告诉我。
    评论

报告相同问题?

问题事件

  • 创建了问题 3月12日