DeepSeek-VL2项目安装与配置指南

DeepSeek-VL2 DeepSeek-VL2: Mixture-of-Experts Vision-Language Models for Advanced Multimodal Understanding DeepSeek-VL2 项目地址: https://gitcode.com/gh_mirrors/de/DeepSeek-VL2

1. 项目基础介绍

DeepSeek-VL2是一个开源的视觉语言模型项目,旨在通过结合图像和文本信息,进行高级的多模态理解。该项目基于Mixture-of-Experts(MoE)架构,提供了三个不同规模变体的模型,分别为DeepSeek-VL2-Tiny、DeepSeek-VL2-Small和DeepSeek-VL2,分别具有1.0B、2.8B和4.5B激活参数。DeepSeek-VL2在视觉问答、光学字符识别、文档表格图表理解以及视觉定位等任务中表现出色。

主要编程语言:Python

2. 关键技术和框架

  • Mixture-of-Experts (MoE): 一种模型架构,通过组合多个专家模型的输出,提高模型的效率和性能。
  • Transformers: 一个流行的自然语言处理库,提供了构建和训练Transformer模型的能力。
  • PyTorch: 一个开源的机器学习库,广泛用于应用如计算机视觉和自然语言处理中的深度学习。

3. 安装和配置准备工作

在开始安装之前,请确保您的系统满足以下要求:

  • Python版本:3.8或更高
  • GPU内存:至少80GB,根据所选模型变体可能需要更多
  • 确保已经安装了CUDA和PyTorch

安装步骤

  1. 克隆项目仓库:

    git clone https://github.com/deepseek-ai/DeepSeek-VL2.git
    cd DeepSeek-VL2
    
  2. 安装项目依赖:

    pip install -e .
    
  3. 根据您的系统配置和项目需求,选择适当的模型变体。以下以DeepSeek-VL2-Tiny为例:

    model_path="deepseek-ai/deepseek-vl2-tiny"
    
  4. 初始化模型处理器和模型:

    from transformers import AutoModelForCausalLM
    from deepseek_vl2.models import DeepseekVLV2Processor, DeepseekVLV2ForCausalLM
    from deepseek_vl2.utils.io import load_pil_images
    
    vl_chat_processor = DeepseekVLV2Processor.from_pretrained(model_path)
    tokenizer = vl_chat_processor.tokenizer
    vl_gpt = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True)
    vl_gpt = vl_gpt.to('cuda').eval()
    
  5. 加载图像并进行预处理:

    conversation = [
        {
            "role": "<|User|>",
            "content": "<image>\n<|ref|>The giraffe at the back.<|/ref|>.",
            "images": ["./images/visual_grounding_1.jpeg"],
        },
        {
            "role": "<|Assistant|>",
            "content": "",
        },
    ]
    
    pil_images = load_pil_images(conversation)
    prepare_inputs = vl_chat_processor(conversations=conversation, images=pil_images, force_batchify=True, system_prompt="")
    
  6. 运行模型并获取响应:

    inputs_embeds = vl_gpt.prepare_inputs_embeds(**prepare_inputs)
    outputs = vl_gpt.language.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=False)
    print(answer)
    

请确保按照项目的具体要求调整以上步骤。如果您遇到任何问题,请查阅项目的官方文档或向社区寻求帮助。

DeepSeek-VL2 DeepSeek-VL2: Mixture-of-Experts Vision-Language Models for Advanced Multimodal Understanding DeepSeek-VL2 项目地址: https://gitcode.com/gh_mirrors/de/DeepSeek-VL2

Logo

欢迎加入DeepSeek 技术社区。在这里,你可以找到志同道合的朋友,共同探索AI技术的奥秘。

更多推荐