[Bugfix] unskip InternViT test for transformers v5 compatibility (#55767)
Signed-off-by: sahil <sahil@example.com> Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
Sahil Patel committed
Sep 21, 2026 at 17:38 UTC
4e61ad8ee126bf01dbc4d28979014a30628309ed
1 file changed
+18
-9
tests/models/multimodal/pooling/test_intern_vit.py
+18
-9
@@ -3,7 +3,7 @@
3
import pytest
4
import torch
5
import torch.nn as nn
6
-from transformers import AutoConfig, AutoModel, CLIPImageProcessor
6
+from transformers import AutoConfig, AutoModel, CLIPImageProcessor, PreTrainedModel
7
8
from vllm.distributed import cleanup_dist_env_and_memory
9
from vllm.platforms import current_platform
@@ -12,11 +12,6 @@ from vllm.utils.torch_utils import STR_DTYPE_TO_TORCH_DTYPE
12
13
from ....conftest import ImageTestAssets
14
15
-pytestmark = pytest.mark.skip(
16
- reason="InternVisionModel's custom code is incompatible with "
17
- "transformers v5 (missing all_tied_weights_keys)"
18
-)
19
-
15
# we use snapshot_download to prevent conflicts between
16
# dynamic_module and trust_remote_code for hf_runner
17
DOWNLOAD_PATTERN = ["*.json", "*.py", "*.safetensors", "*.txt", "*.model"]
@@ -45,9 +40,23 @@ def run_intern_vit_test(
40
if not getattr(config, "norm_type", None):
41
config.norm_type = "rms_norm"
42
48
- hf_model = AutoModel.from_pretrained(
49
- model, dtype=torch_dtype, trust_remote_code=True
50
- ).to(DEVICE_TYPE)
43
+ # Monkey-patch for transformers v5 compatibility: InternVisionModel's
44
+ # custom code doesn't call post_init(), so all_tied_weights_keys is
45
+ # never set. Remove once https://github.com/OpenGVLab/InternVL fixes it.
46
+ _orig_init = PreTrainedModel.__init__
47
+
48
+ def _patched_init(self, *args, **kwargs):
49
+ _orig_init(self, *args, **kwargs)
50
+ self.all_tied_weights_keys = {}
51
+
52
+ PreTrainedModel.__init__ = _patched_init
53
+
54
+ try:
55
+ hf_model = AutoModel.from_pretrained(
56
+ model, dtype=torch_dtype, trust_remote_code=True
57
+ ).to(DEVICE_TYPE)
58
+ finally:
59
+ PreTrainedModel.__init__ = _orig_init
60
hf_outputs_per_image = [
61
hf_model(pixel_value.to(DEVICE_TYPE)).last_hidden_state
62
for pixel_value in pixel_values