DeepSeek Multimodal Tutorial
DeepSeek VL2 vision-language model and Janus multimodal understanding and image generation. From environment setup to complete inference, covering all core capabilities including OCR, chart analysis, visual question answering, and text-to-image.
Start LearningMultimodal Model Overview
DeepSeek has released two multimodal models: VL2 focuses on vision-language understanding, while Janus supports both multimodal understanding and image generation. They differ in architecture design, capability focus, and applicable scenarios.
Multimodal Model Overview — VL2 and Janus
Understanding the core differences between VL2 and Janus is a prerequisite for choosing the right model. The following provides a comprehensive comparison across architecture, capabilities, application scenarios, and more.
Positioning Comparison of VL2 and Janus
| Comparison Dimension | DeepSeek VL2 | DeepSeek Janus |
|---|---|---|
| Core Capability | Visual language understanding (unidirectional) | Multimodal understanding + image generation (bidirectional) |
| Architecture Design | Visual encoder + language model projection | Unified autoregressive Transformer |
| Image Understanding | Professional-grade, dynamic resolution | Supported, fixed 384x384 resolution |
| Image Generation | Not supported | Supported, text-to-image generation |
| OCR Capability | Extremely strong, enhanced by dynamic resolution | Basic support |
| Model Scale | Tiny / Small / Full three tiers | Janus-Pro-7B (7B parameters) |
| Typical Scenarios | OCR document recognition, chart analysis, visual question answering | Image captioning, multimodal dialogue, text-to-image creation |
Detailed Architecture Differences
DeepSeek VL2 adopts the classic visual encoder + large language model architecture. SigLIP serves as the visual encoder to extract image features, which are then mapped to the language model's embedding space via an MLP projection layer, and finally the DeepSeekMoE language model generates text responses. VL2 supports dynamic resolution, which splits high-resolution images into multiple tiles for separate encoding, and then feeds them together with a global thumbnail into the model, significantly improving OCR and fine-grained visual understanding.
DeepSeek Janus adopts a unified Transformer autoregressive architecture, unifying image understanding and generation in a single framework. The understanding path uses a SigLIP encoder to extract visual features and adapt them to the LLM; the generation path uses a VQ tokenizer to convert images into discrete token sequences, which are then generated autoregressively by the LLM. Janus-Pro-7B further optimizes Janus, improving multimodal understanding performance and image generation quality.
Selection Recommendations
- Need high-precision OCR and document understanding: Choose VL2; its dynamic resolution mechanism makes it excel in text recognition
- Need image generation capability: Choose Janus; it supports text-to-image generation at 384x384 resolution
- Need visual question answering and chart analysis: VL2 is the first choice, with higher visual understanding accuracy
- Need a unified multimodal dialogue experience: Janus switches more naturally between understanding and generation
- Limited resources: VL2 Tiny (3B) or VL2 Small (16B) can run on consumer-grade GPUs
DeepSeek VL2 Environment Setup
Install dependencies, download models, and configure the environment. VL2 offers three model sizes: Tiny, Small, and Full, which can be flexibly selected based on hardware configuration.
VL2 Model Size Comparison
| Model Version | Parameter Size | Vision Encoder | GPU Memory Requirement | Use Cases |
|---|---|---|---|---|
| VL2-Tiny | 3B | SigLIP-SO400M | ~8GB | Rapid prototyping, mobile deployment |
| VL2-Small | 16B | SigLIP-SO400M | ~40GB | Research, high-precision OCR |
| VL2-Full | 27B (MoE) | SigLIP-SO400M | ~80GB | Professional-grade visual understanding, complex document analysis |
Install Dependencies
Download Models from Hugging Face
Tip
If the download speed is slow, you can set the HF mirror: export HF_ENDPOINT=https://hf-mirror.com. For more model download tips, see the DeepSeek Model Download Guide.
VL2 Image Understanding
VL2 supports core capabilities such as image captioning, visual question answering, OCR text extraction, chart analysis, and visual grounding. The following demonstrates the code implementation for each.
Loading Model and Image
Visual Question Answering (VQA)
OCR Text Extraction
Chart Understanding
Visual Grounding
VL2 Dynamic Resolution
Dynamic resolution is one of VL2's core innovations. It allows the model to adaptively split the input image into multiple tiles for processing based on its actual size, thereby preserving details in high-resolution images.
How Dynamic Resolution Works
Traditional vision models typically resize images to a fixed size (e.g., 384x384), causing loss of text and details in high-resolution images. VL2's dynamic resolution mechanism splits the image into multiple local tiles (each tile defaults to 384x384) while also keeping a global thumbnail, allowing the model to understand both the overall layout and capture local details.
Dynamic Resolution Processing Pipeline:
- Calculate the optimal tiling scheme based on the image aspect ratio (e.g., 2x2, 3x2, 1x3, etc.)
- Resize the image to the target resolution and split it into multiple tiles
- Generate a global thumbnail to preserve overall layout information
- Feed all tiles and the thumbnail into the vision encoder separately
- Concatenate the encoded visual features and feed them into the language model
Configuring Dynamic Resolution
Dynamic Resolution vs. Fixed Resolution
| Comparison | Fixed Resolution | Dynamic Resolution |
|---|---|---|
| OCR Accuracy | Low, small text blurry | High, small text clearly readable |
| Inference Speed | Fast, single tile | Slower, multiple tiles in parallel |
| Memory Usage | Low | Higher, increases with number of tiles |
| Applicable Scenarios | Quick preview, low-resolution images | High-precision OCR, document analysis, chart reading |
Best Practices
For document OCR and chart analysis, always use dynamic resolution mode. For simple scene classification or object recognition, you can use fixed resolution to save computational resources. It is recommended to keep the number of tiles within 9 (approximately 1152x1152); beyond that, marginal returns diminish.
VL2 Multi-turn Visual Dialogue
VL2 supports multi-turn dialogue, allowing you to switch between different images during the conversation. The model remembers the context and continues to answer. Below we demonstrate how to implement multi-turn dialogue.
Multi-turn Dialogue Code Implementation
Dialogue Context Management
In multi-turn dialogue, note the following:
- Context length limit: VL2's context window is limited; for long conversations, you need to trim history or use summarization strategies.
- Image accumulation strategy: Each turn you can choose whether to carry historical images; carrying all images consumes more GPU memory.
- Dialogue history structure: Maintain the alternating structure of role (user/assistant) and content to ensure the model understands the conversation flow.
- Image reference: Explicitly reference images in questions (e.g., "in the first image...") to avoid confusion.
- Timely cleanup: When switching conversation topics, it is recommended to reset conversation_history to avoid context pollution.
Optimization Suggestions
For long conversations, it is recommended to keep only the last 3-5 turns as context each turn to avoid exceeding the token limit. If you need to compare multiple images, you can put all images in a single turn instead of sending them across multiple turns.
Janus Environment Setup
Janus is DeepSeek's unified multimodal model that supports both image understanding and image generation. Janus-Pro-7B is the latest version, with significant improvements in both understanding and generation.
Install Dependencies
Download Janus-Pro-7B
Janus Model Size Comparison
| Model Version | Parameter Size | Image Understanding | Image Generation | GPU Memory Requirement |
|---|---|---|---|---|
| Janus-1.3B | 1.3B | Basic support | 384x384 | ~6GB |
| Janus-Pro-7B | 7B | Enhanced | 384x384 (improved quality) | ~20GB |
Janus Multimodal Understanding
Janus supports image captioning, visual question answering, and multimodal reasoning. Although its understanding accuracy is not as high as VL2, its unified architecture allows seamless switching between understanding and generation.
Loading the Janus Model
Image Captioning
Visual Question Answering
Multimodal Reasoning
Janus Image Generation
Janus supports text-to-image generation, outputting images at 384x384 resolution. By adjusting generation parameters, you can control the diversity and quality of the images.
Text-to-Image Generation
Generation Parameter Description
| Parameter | Description | Recommended Value |
|---|---|---|
| temperature | Controls generation diversity. Higher is more random, lower is more deterministic | 0.8 - 1.2 |
| top_p | Nucleus sampling threshold, controls candidate token range | 0.9 - 0.95 |
| max_new_tokens | Maximum number of tokens to generate, affects image detail | 1024 - 2048 |
| do_sample | Whether to use sampling. If False, greedy decoding is used | True (for image generation) |
Batch Image Generation
Tip
Janus's image generation is based on an autoregressive Transformer, and the generation speed depends on max_new_tokens. The 384x384 resolution is suitable for most scenarios; if higher resolution is needed, you can later use a super-resolution model to upscale. It is recommended to write prompts in English; the more specific the description, the better the generation results.
Comprehensive Comparison of VL2 and Janus
Compare VL2 and Janus across dimensions such as architecture, capabilities, model scale, inference speed, and applicable scenarios to help you make the right model choice.
Core Capability Comparison
| Capability Dimension | DeepSeek VL2 | DeepSeek Janus (Pro-7B) |
|---|---|---|
| OCR Text Recognition | Extremely strong (with dynamic resolution) | Average |
| Chart/Document Understanding | Professional grade | Basic support |
| Visual Question Answering | High accuracy | Medium |
| Image Captioning | Detailed and precise | Natural and fluent |
| Image Generation | Not supported | Supported (384x384) |
| Text-only Conversation | Supported | Supported (more natural) |
| Inference Speed | Medium (slower with many tiles) | Faster (fixed resolution) |
| Model Scale | 3B / 16B / 27B(MoE) | 1.3B / 7B |
Recommended Use Cases
| Scenario | Recommended Model | Reason |
|---|---|---|
| Document OCR Recognition | VL2 | Dynamic resolution, clear small text |
| Financial Statement Analysis | VL2 | Chart understanding + data extraction |
| Multimodal Chatbot | Janus | Unified experience of understanding + generation |
| AI Painting Application | Janus | Native support for text-to-image |
| Medical Image Analysis | VL2 | High-precision fine-grained recognition |
| Creative Content Generation | Janus | Closed loop of understanding + generation |
Combined Usage Plan
In real projects, VL2 and Janus can be used complementarily:
- VL2 for understanding + Janus for generation: Use VL2 to understand user-uploaded images with high precision, extract key information, then use Janus to generate responses or new images
- VL2 for preprocessing + Janus for conversation: VL2 handles OCR and document parsing, Janus handles natural language conversation and creative generation
- Route by scenario: Route document-related requests to VL2, creative requests to Janus, achieving optimal resource utilization
For more model comparisons and selection guides, see DeepSeek Open Source Model List and DeepSeek Model Architecture Details.
Hands-on: Multimodal AI Application
Integrate VL2 and Janus into a complete web application that supports image upload, visual question answering, and image generation. Use Streamlit to build an interactive UI.
Complete Application Code: multimodal_app.py
Installation and Running
Application Features
- VL2 Visual Understanding: Supports image upload, multiple task types (OCR/chart/detection/description), custom questions
- Janus Image Understanding: Upload images and conduct natural language Q&A
- Janus Image Generation: Text-to-image generation, supports adjusting temperature and batch generation
- Model Caching: Uses Streamlit caching mechanism, model loaded only once
- Sidebar Configuration: Flexible switching between models and modes, adjust generation parameters
Deployment Recommendations
For production environments, it is recommended to use VL2-Tiny or Janus-1.3B to reduce hardware costs. For high-performance inference, you can use vLLM or TGI to deploy the model service, and the frontend calls via API. See DeepSeek Deployment Tutorial.
DeepSeek Multimodal FAQ
DeepSeek Related Tutorials
Dive deeper into DeepSeek model usage, deployment, and ecosystem tools.
DeepSeek Model Architecture
Technical architecture, benchmarks, and model selection comparison.
DeepSeek Open-Source Models
Complete catalog of 6 series and 20+ models.
DeepSeek Deployment Guide
Deployment options with Ollama, Docker, vLLM, and K8s.
How to Use DeepSeek Models
Four usage methods, beginner-friendly tutorial.
DeepSeek Model Downloads
Download guides for Ollama, Hugging Face, and GitHub.
DeepSeek Model Fine-tuning
Hands-on tutorials for LoRA and QLoRA fine-tuning.