From 206accd15de341e10be68ae6139a3cdfb610eac3 Mon Sep 17 00:00:00 2001 From: Alison Shao <54658187+alisonshao@users.noreply.github.com> Date: Mon, 16 Feb 2026 00:02:31 -0800 Subject: [PATCH] Fix GLM-4V processor registration when glm_ocr is unavailable (#18885) --- python/sglang/srt/multimodal/processors/glm4v.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/python/sglang/srt/multimodal/processors/glm4v.py b/python/sglang/srt/multimodal/processors/glm4v.py index 0dce4e956..33cce6fe2 100644 --- a/python/sglang/srt/multimodal/processors/glm4v.py +++ b/python/sglang/srt/multimodal/processors/glm4v.py @@ -3,7 +3,6 @@ from typing import List, Union from sglang.srt.layers.rotary_embedding import MRotaryEmbedding from sglang.srt.models.glm4v import Glm4vForConditionalGeneration from sglang.srt.models.glm4v_moe import Glm4vMoeForConditionalGeneration -from sglang.srt.models.glm_ocr import GlmOcrForConditionalGeneration from sglang.srt.multimodal.processors.base_processor import ( BaseMultimodalProcessor as SGLangBaseProcessor, ) @@ -11,12 +10,21 @@ from sglang.srt.multimodal.processors.base_processor import ( MultimodalSpecialTokens, ) +try: + from sglang.srt.models.glm_ocr import GlmOcrForConditionalGeneration +except ImportError: + GlmOcrForConditionalGeneration = None + class Glm4vImageProcessor(SGLangBaseProcessor): models = [ - Glm4vForConditionalGeneration, - Glm4vMoeForConditionalGeneration, - GlmOcrForConditionalGeneration, + m + for m in [ + Glm4vForConditionalGeneration, + Glm4vMoeForConditionalGeneration, + GlmOcrForConditionalGeneration, + ] + if m is not None ] def __init__(self, hf_config, server_args, _processor, *args, **kwargs):