@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 90fc7f9109
Fork 0

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 7, 19:00 UTC

Fix custom processors that use deleted behaviour for Transformers v5 (#35107)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>

Harry Mellor committed Feb 25, 2026 at 10:36 UTC 90fc7f91097de57ad17887577a0da2a95c28c418
1 file changed +32
vllm/transformers_utils/processor.py
+32
@@ -44,7 +44,39 @@ def _transformers_v4_compatibility_import():
44 processing_utils.ChatTemplateLoadKwargs = new_import
45
46
47 +def _transformers_v4_compatibility_init() -> Any:
48 + """Some remote code processors may define `optional_attributes` in their
49 + `ProcessorMixin` subclass, and then pass these arbitrary attributes directly to
50 + `ProcessorMixin.__init__`, which is no longer allowed in Transformers v5. For
51 + backward compatibility, we intercept these optional attributes and set them on the
52 + processor instance before calling the original `ProcessorMixin.__init__`.
53 +
54 + This can be removed if `Molmo2ForConditionalGeneration` is upstreamed to
55 + Transformers."""
56 + # Transformers v4
57 + if hasattr(ProcessorMixin, "optional_attributes"):
58 + return
59 + # Transformers v5
60 + if hasattr(ProcessorMixin.__init__, "_vllm_patched"):
61 + return
62 +
63 + original_init = ProcessorMixin.__init__
64 +
65 + def __init__(self, *args, **kwargs):
66 + for optional_attribute in getattr(self, "optional_attributes", []):
67 + if optional_attribute in kwargs:
68 + setattr(self, optional_attribute, kwargs.pop(optional_attribute))
69 +
70 + original_init(self, *args, **kwargs)
71 +
72 + # Only patch if ProcessorMixin is not mocked (for docs builds)
73 + if not hasattr(ProcessorMixin, "_mock_name"):
74 + __init__._vllm_patched = True # type: ignore[attr-defined]
75 + ProcessorMixin.__init__ = __init__
76 +
77 +
78 _transformers_v4_compatibility_import()
79 +_transformers_v4_compatibility_init()
80
81 _P = TypeVar("_P", bound=ProcessorMixin, default=ProcessorMixin)
82 _V = TypeVar("_V", bound=BaseVideoProcessor, default=BaseVideoProcessor)