Views
No views yet

Python >= 3.8 environment, install the necessary dependencies by running the following command:1git clone https://github.com/deepseek-ai/DeepSeek-VL
2cd DeepSeek-VL
3
4pip install -e .1import torch
2from transformers import AutoModelForCausalLM
3
4from deepseek_vl.models import VLChatProcessor, MultiModalityCausalLM
5from deepseek_vl.utils.io import load_pil_images
6
7
8# specify the path to the model
9model_path = "deepseek-ai/deepseek-vl-7b-base"
10vl_chat_processor: VLChatProcessor = VLChatProcessor.from_pretrained(model_path)
11tokenizer = vl_chat_processor.tokenizer
12
13vl_gpt: MultiModalityCausalLM = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True)
14vl_gpt = vl_gpt.to(torch.bfloat16).cuda().eval()
15
16conversation = [
17 {
18 "role": "User",
19 "content": "<image_placeholder>Describe each stage of this image.",
20 "images": ["./images/training_pipelines.png"]
21 },
22 {
23 "role": "Assistant",
24 "content": ""
25 }
26]
27
28# load images and prepare for inputs
29pil_images = load_pil_images(conversation)
30prepare_inputs = vl_chat_processor(
31 conversations=conversation,
32 images=pil_images,
33 force_batchify=True
34).to(vl_gpt.device)
35
36# run image encoder to get the image embeddings
37inputs_embeds = vl_gpt.prepare_inputs_embeds(**prepare_inputs)
38
39# run the model to get the response
40outputs = vl_gpt.language_model.generate(
41 inputs_embeds=inputs_embeds,
42 attention_mask=prepare_inputs.attention_mask,
43 pad_token_id=tokenizer.eos_token_id,
44 bos_token_id=tokenizer.bos_token_id,
45 eos_token_id=tokenizer.eos_token_id,
46 max_new_tokens=512,
47 do_sample=False,
48 use_cache=True
49)
50
51answer = tokenizer.decode(outputs[0].cpu().tolist(), skip_special_tokens=True)
52print(f"{prepare_inputs['sft_format'][0]}", answer)1
2python cli_chat.py --model_path "deepseek-ai/deepseek-vl-7b-base"
3
4# or local path
5python cli_chat.py --model_path "local model path"
6@misc{lu2024deepseekvl,
title={DeepSeek-VL: Towards Real-World Vision-Language Understanding},
author={Haoyu Lu and Wen Liu and Bo Zhang and Bingxuan Wang and Kai Dong and Bo Liu and Jingxiang Sun and Tongzheng Ren and Zhuoshu Li and Yaofeng Sun and Chengqi Deng and Hanwei Xu and Zhenda Xie and Chong Ruan},
year={2024},
eprint={2403.05525},
archivePrefix={arXiv},
primaryClass={cs.AI}
}