A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 9, 18:15 UTC
[Model] Enable LoRA support for internvl2 (#32397)
Signed-off-by: Matteo Fari <matteofari06@gmail.com>
Matteo Fari committed
Jan 23, 2026 at 18:39 UTC
fec9da0af48da5fe9523914aeddf2c34f53166a9
1 file changed
+16
-3
vllm/model_executor/models/internvl.py
+16
-3
@@ -1086,9 +1086,8 @@ class InternVLChatModel(nn.Module, SupportsMultiModal, SupportsPP, SupportsLoRA)
1086
image_size = config.force_image_size or config.vision_config.image_size
1087
patch_size = config.vision_config.patch_size
1088
self.patch_size = patch_size
1089
- self.num_image_token = int(
1090
- (image_size // patch_size) ** 2 * (config.downsample_ratio**2)
1091
- )
1089
+ self.patch_tokens = (image_size // patch_size) ** 2
1090
+ self.num_image_token = int(self.patch_tokens * (config.downsample_ratio**2))
1091
self.downsample_ratio = config.downsample_ratio
1092
self.ps_version = config.ps_version
1093
@@ -1430,3 +1429,17 @@ class InternVLChatModel(nn.Module, SupportsMultiModal, SupportsPP, SupportsLoRA)
1429
connector="mlp1",
1430
tower_model="vision_model",
1431
)
1432
+
1433
+ def get_num_mm_encoder_tokens(self, num_image_tokens: int) -> int:
1434
+ if num_image_tokens <= 0 or self.num_image_token <= 0:
1435
+ return 0
1436
+
1437
+ num_patches = num_image_tokens // self.num_image_token
1438
+ return num_patches * (self.patch_tokens + 1)
1439
+
1440
+ def get_num_mm_connector_tokens(self, num_vision_tokens: int) -> int:
1441
+ if num_vision_tokens <= 0 or self.num_image_token <= 0:
1442
+ return 0
1443
+
1444
+ num_patches = num_vision_tokens // (self.patch_tokens + 1)
1445
+ return num_patches * self.num_image_token