vllm.models.deepseek_v4.common.vision ¶
DeepSeek-V4 vision tower (ViT + aligner) with TP-sharded linears.
Ported from the official reference implementation (deepseek-ai/DeepSeek-V4-Flash-Vision-Exp). Weight names match the HF checkpoint so no renaming is needed at load time. Attention and MLP weights are tensor-parallel sharded (replicated when the vision head count is not divisible by TP size, or under --mm-encoder-tp-mode data); the patch embed and norms are replicated, so the residual stream is full-width on every rank.
Classes:
-
DeepseekV4Aligner–Spatial merge (downsample_ratio x downsample_ratio) + MLP projector.
-
DeepseekV4ViT–DeepSeek-V4 ViT: full bidirectional attention per image, 2D RoPE.
Functions:
-
run_dp_sharded_vision_tower–Run the ViT + aligner with images sharded across TP ranks.
DeepseekV4Aligner ¶
Bases: Module
Spatial merge (downsample_ratio x downsample_ratio) + MLP projector.
Source code in vllm/models/deepseek_v4/common/vision.py
DeepseekV4ViT ¶
Bases: Module
DeepSeek-V4 ViT: full bidirectional attention per image, 2D RoPE.
Source code in vllm/models/deepseek_v4/common/vision.py
run_dp_sharded_vision_tower(vision_model, aligner, patches, vit_grid) ¶
Run the ViT + aligner with images sharded across TP ranks.
Every rank holds the full tower weights (--mm-encoder-tp-mode data) and receives the full patches batch. Images are assigned to ranks by patch count (greedy load balancing), each rank encodes only its share, and per-image embeddings are exchanged with one padded all-gather and returned in the original image order.
Parameters:
-
(vision_model¶DeepseekV4ViT) –The (weight-replicated) ViT tower.
-
(aligner¶DeepseekV4Aligner) –The (weight-replicated) spatial-merge projector.
-
(patches¶Tensor) –(sum(n_vit_h * n_vit_w), 3, p, p)patches of all images. -
(vit_grid¶list[list[int]]) –[n_vit_h, n_vit_w]per image.
Returns:
Source code in vllm/models/deepseek_v4/common/vision.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |