fix: prefer registered config over remote code in AutoConfig.from_pretrained (#45094)
* Prefer registered classes over remote code in Auto*.from_pretrained
When a class has been explicitly registered via AutoConfig.register()
(or other Auto*.register()), it should take precedence over auto_map
remote code. Previously, trust_remote_code=True with auto_map entries
in config.json would always load remote code, ignoring the registration.
This applies the same fix across all Auto classes:
AutoConfig, AutoModel, AutoTokenizer, AutoProcessor,
AutoFeatureExtractor, AutoImageProcessor, AutoVideoProcessor.
This caused issues for downstream libraries (e.g., vLLM) that vendor
fixed classes for models with broken remote code — internal calls
from AutoTokenizer/AutoProcessor would bypass the registration and
load the broken remote class.
Fixes: #45093
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Only ignore remote code if local code is explicit (i.e. doesn't belong to transformers)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
* update tests
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
* `make style`
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
* fix tokenizer test
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
* Fix tests
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
* Fix explicit registration detection
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
* make style
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
---------
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>