[Model] Handle trust_remote_code for transformers backend (#32194)

Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
Cyrus Leung
2026-01-13 09:30:12 +08:00
committed by GitHub
parent a307ac0734
commit 78d13ea9de
2 changed files with 14 additions and 1 deletions

View File

@@ -887,6 +887,7 @@ class _ModelRegistry:
module,
model_config.model,
revision=model_config.revision,
trust_remote_code=model_config.trust_remote_code,
warn_on_fail=False,
)
@@ -899,6 +900,7 @@ class _ModelRegistry:
module,
model_config.model,
revision=model_config.revision,
trust_remote_code=model_config.trust_remote_code,
warn_on_fail=True,
)
if model_module is not None:

View File

@@ -2,7 +2,10 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import os
from transformers.dynamic_module_utils import get_class_from_dynamic_module
from transformers.dynamic_module_utils import (
get_class_from_dynamic_module,
resolve_trust_remote_code,
)
import vllm.envs as envs
from vllm.logger import init_logger
@@ -13,6 +16,7 @@ logger = init_logger(__name__)
def try_get_class_from_dynamic_module(
class_reference: str,
pretrained_model_name_or_path: str,
trust_remote_code: bool,
cache_dir: str | os.PathLike | None = None,
force_download: bool = False,
resume_download: bool | None = None,
@@ -30,6 +34,13 @@ def try_get_class_from_dynamic_module(
but ignoring any errors.
"""
try:
resolve_trust_remote_code(
trust_remote_code,
pretrained_model_name_or_path,
has_local_code=False,
has_remote_code=True,
)
return get_class_from_dynamic_module(
class_reference,
pretrained_model_name_or_path,