From 11972e520709a76766f91744a672e92727fdcb09 Mon Sep 17 00:00:00 2001 From: Yihao Wang <42559837+AgainstEntropy@users.noreply.github.com> Date: Wed, 7 Oct 2026 02:04:08 -0700 Subject: [PATCH] [deps] bump transformers to 5.19.0 (#42784) Co-authored-by: Claude Opus 5.5 --- 3rdparty/amd/wheel/sglang/pyproject.toml | 2 +- docker/rocm.Dockerfile | 4 +-- python/pyproject.toml | 2 +- python/pyproject_cpu.toml | 2 +- python/pyproject_npu.toml | 2 +- python/pyproject_other.toml | 2 +- python/pyproject_xpu.toml | 2 +- .../runtime/models/encoders/hunyuan3d.py | 32 +++++++++++++++++++ .../runtime/pipelines/hunyuan3d_pipeline.py | 9 +++++- 9 files changed, 48 insertions(+), 9 deletions(-) diff --git a/3rdparty/amd/wheel/sglang/pyproject.toml b/3rdparty/amd/wheel/sglang/pyproject.toml index 5dd069c697..9153ee2fd6 100644 --- a/3rdparty/amd/wheel/sglang/pyproject.toml +++ b/3rdparty/amd/wheel/sglang/pyproject.toml @@ -59,7 +59,7 @@ runtime_common = [ "tiktoken", "timm==1.0.16", "tqdm", - "transformers==5.17.0", + "transformers==5.19.0", "uvicorn", "uvloop", "xgrammar==0.2.7", diff --git a/docker/rocm.Dockerfile b/docker/rocm.Dockerfile index 71d9133172..a486691040 100644 --- a/docker/rocm.Dockerfile +++ b/docker/rocm.Dockerfile @@ -735,9 +735,9 @@ RUN cd sglang \ all_extras="all_hip" ; \ CONS="-c /tmp/constraints.txt" ; \ echo 'diffusers==0.37.0' >> /tmp/constraints.txt ; \ - echo 'transformers==5.17.0' >> /tmp/constraints.txt ; \ + echo 'transformers==5.19.0' >> /tmp/constraints.txt ; \ echo 'tokenizers==0.23.2' >> /tmp/constraints.txt ; \ - echo 'huggingface_hub==1.27.0' >> /tmp/constraints.txt ; \ + echo 'huggingface_hub==1.33.0' >> /tmp/constraints.txt ; \ ;; \ esac \ && if [ "$BUILD_TYPE" = "srt" ]; then \ diff --git a/python/pyproject.toml b/python/pyproject.toml index 2f9a520060..768ceb52ba 100755 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -93,7 +93,7 @@ dependencies = [ "torchcodec==0.17.0 ; sys_platform != 'linux' or (sys_platform == 'linux' and platform_machine != 'aarch64' and platform_machine != 'arm64' and platform_machine != 'armv7l')", # Not available on Linux ARM. "torchvision", "tqdm", - "transformers==5.17.0", + "transformers==5.19.0", "uvicorn", "uvloop", "watchfiles", diff --git a/python/pyproject_cpu.toml b/python/pyproject_cpu.toml index b160116a07..01096f2a4d 100644 --- a/python/pyproject_cpu.toml +++ b/python/pyproject_cpu.toml @@ -66,7 +66,7 @@ dependencies = [ "torchcodec==0.12.0 ; sys_platform != 'linux' or (sys_platform == 'linux' and platform_machine != 'aarch64' and platform_machine != 'arm64' and platform_machine != 'armv7l')", "torchvision==0.29.0", "tqdm", - "transformers==5.17.0", + "transformers==5.19.0", "triton==3.8.0", "uvicorn", "uvloop", diff --git a/python/pyproject_npu.toml b/python/pyproject_npu.toml index a869e3ec11..3bc34ee5ef 100644 --- a/python/pyproject_npu.toml +++ b/python/pyproject_npu.toml @@ -62,7 +62,7 @@ dependencies = [ "tiktoken", "timm==1.0.16", "tqdm", - "transformers==5.17.0", + "transformers==5.19.0", "uvicorn", "uvloop", "xxhash", diff --git a/python/pyproject_other.toml b/python/pyproject_other.toml index d55af01af7..d0bc6b9581 100755 --- a/python/pyproject_other.toml +++ b/python/pyproject_other.toml @@ -62,7 +62,7 @@ runtime_base = [ "soundfile==0.13.1", "tiktoken", "tqdm", - "transformers==5.17.0", + "transformers==5.19.0", "uvicorn", "uvloop", "xxhash", diff --git a/python/pyproject_xpu.toml b/python/pyproject_xpu.toml index 6f7caafe80..ed425d27c3 100644 --- a/python/pyproject_xpu.toml +++ b/python/pyproject_xpu.toml @@ -66,7 +66,7 @@ dependencies = [ "torchcodec==0.13.0 ; sys_platform != 'linux' or (sys_platform == 'linux' and platform_machine != 'aarch64' and platform_machine != 'arm64' and platform_machine != 'armv7l')", # torch==2.13.0 on XPU uses torchcodec 0.13.0 "torchvision==0.28.0+xpu", "tqdm", - "transformers==5.17.0", + "transformers==5.19.0", "uvicorn", "xxhash", "uvloop", diff --git a/python/sglang/multimodal_gen/runtime/models/encoders/hunyuan3d.py b/python/sglang/multimodal_gen/runtime/models/encoders/hunyuan3d.py index 69f2431f81..a02c746cfb 100644 --- a/python/sglang/multimodal_gen/runtime/models/encoders/hunyuan3d.py +++ b/python/sglang/multimodal_gen/runtime/models/encoders/hunyuan3d.py @@ -33,6 +33,36 @@ def get_1d_sincos_pos_embed_from_grid(embed_dim, pos): return np.concatenate([emb_sin, emb_cos], axis=1) +# transformers 5.19 renamed Dinov2's attention projections and split its SwiGLU input +# projection into gate/up. from_pretrained remaps legacy checkpoints on its own, but +# Hunyuan3D builds Dinov2Model from a config and loads its own state dict, where a +# non-strict load would silently leave these weights randomly initialized. +_DINOV2_LEGACY_RENAMES = ( + ("attention.attention.query.", "attention.q_proj."), + ("attention.attention.key.", "attention.k_proj."), + ("attention.attention.value.", "attention.v_proj."), + ("attention.output.dense.", "attention.o_proj."), + ("mlp.weights_out.", "mlp.down_proj."), +) + + +def _remap_legacy_dinov2_keys(module, state_dict, prefix, *args): + if not hasattr(module.encoder.layer[0].attention, "q_proj"): + return # transformers < 5.19 still uses the checkpoint's layout + layer_prefix = prefix + "encoder.layer." + for key in [k for k in state_dict if k.startswith(layer_prefix)]: + for old, new in _DINOV2_LEGACY_RENAMES: + if old in key: + state_dict[key.replace(old, new)] = state_dict.pop(key) + break + else: + if ".mlp.weights_in." in key: + # SwiGLU computed silu(first half) * second half of weights_in. + gate, up = state_dict.pop(key).chunk(2, dim=0) + state_dict[key.replace("mlp.weights_in.", "mlp.gate_proj.")] = gate + state_dict[key.replace("mlp.weights_in.", "mlp.up_proj.")] = up + + class ImageEncoder( ConditioningEncoderMixin, nn.Module, LayerwiseOffloadableModuleMixin ): @@ -60,6 +90,8 @@ class ImageEncoder( self.model = self.MODEL_CLASS.from_pretrained(version) else: self.model = self.MODEL_CLASS(self.MODEL_CONFIG_CLASS.from_dict(config)) + if isinstance(self.model, Dinov2Model): + self.model.register_load_state_dict_pre_hook(_remap_legacy_dinov2_keys) self.model.eval() self.model.requires_grad_(False) self.use_cls_token = use_cls_token diff --git a/python/sglang/multimodal_gen/runtime/pipelines/hunyuan3d_pipeline.py b/python/sglang/multimodal_gen/runtime/pipelines/hunyuan3d_pipeline.py index af216a3e25..64a3d200fa 100644 --- a/python/sglang/multimodal_gen/runtime/pipelines/hunyuan3d_pipeline.py +++ b/python/sglang/multimodal_gen/runtime/pipelines/hunyuan3d_pipeline.py @@ -300,7 +300,14 @@ class Hunyuan3D2Pipeline(ComposedPipelineBase): component = target_cls(**params) if weights is not None: - component.load_state_dict(weights, strict=False) + # Extra checkpoint keys are tolerated, but a weight the module expects and + # the checkpoint lacks would stay randomly initialized and corrupt outputs. + missing = component.load_state_dict(weights, strict=False).missing_keys + if missing: + raise RuntimeError( + f"{cfg['target']} checkpoint is missing {len(missing)} weights, " + f"e.g. {missing[:5]}" + ) component.to(device=device, dtype=dtype) return component.eval()