From e40cc07fe6ea0a2b26d00b4c6acce9c6299c88c0 Mon Sep 17 00:00:00 2001 From: Snakinya <70094531+Snakinya@users.noreply.github.com> Date: Wed, 17 Jun 2026 12:40:11 +0800 Subject: [PATCH] fix: block Hub kernel repo patterns in attn_implementation from config.json The fix for CVE-2026-4372 blocks _attn_implementation_internal from being set via config.json. However, the public field attn_implementation is processed by kwargs.pop() before the exclusion check and triggers a property setter that writes directly to _attn_implementation_internal, bypassing the fix. This patch validates that attn_implementation values loaded from config do not contain '/' (Hub repo pattern). Standard values (eager, sdpa, flash_attention_2, etc.) are unaffected. Users can still set kernel implementations explicitly via from_pretrained(attn_implementation=...). --- src/transformers/configuration_utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/transformers/configuration_utils.py b/src/transformers/configuration_utils.py index 2b6fdce06e28..7d213891d447 100755 --- a/src/transformers/configuration_utils.py +++ b/src/transformers/configuration_utils.py @@ -296,7 +296,15 @@ def __post_init__(self, **kwargs): # Attention/Experts implementation to use, if relevant (it sets it recursively on sub-configs) self._output_attentions: bool | None = kwargs.pop("output_attentions", False) - self._attn_implementation: str | None = kwargs.pop("attn_implementation", None) + _attn_from_config = kwargs.pop("attn_implementation", None) + if _attn_from_config is not None and "/" in str(_attn_from_config): + logger.warning_once( + f"Ignoring `attn_implementation='{_attn_from_config}'` from config as it looks like a Hub repo. " + "Kernel-style attention implementations must be set explicitly via " + "`from_pretrained(attn_implementation=...)`." + ) + _attn_from_config = None + self._attn_implementation: str | None = _attn_from_config self._experts_implementation: str | None = kwargs.pop("experts_implementation", None) # Additional attributes without default values