Skip to content

fix: prefer registered config over remote code in AutoConfig.from_pretrained#45094

Merged
hmellor merged 9 commits intohuggingface:mainfrom
HanFa:fix/autoconfig-register-precedence
Mar 31, 2026
Merged

fix: prefer registered config over remote code in AutoConfig.from_pretrained#45094
hmellor merged 9 commits intohuggingface:mainfrom
HanFa:fix/autoconfig-register-precedence

Conversation

@HanFa
Copy link
Copy Markdown
Contributor

@HanFa HanFa commented Mar 29, 2026

When a config class has been explicitly registered via AutoConfig.register(), it should take precedence over auto_map remote code. Previously, trust_remote_code=True with auto_map.AutoConfig in config.json would always load remote code, ignoring the registration.

This caused issues for downstream libraries (e.g., vLLM) that vendor fixed config classes for models with broken remote code — internal calls from AutoTokenizer/AutoProcessor would bypass the registration and load the broken remote class.

What does this PR do?

Fixes: #45093

Code Agent Policy

The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. We are currently bottlenecked by our ability to review and respond to them. As a result,
we ask that new users do not submit pure code agent PRs at this time.
You may use code agents in drafting or to help you diagnose issues. We'd also ask autonomous "OpenClaw"-like agents
not to open any PRs or issues for the moment.

PRs that appear to be fully agent-written will probably be closed without review, and we may block users who do this
repeatedly or maliciously.

This is a rapidly-evolving situation that's causing significant shockwaves in the open-source community. As a result,
this policy is likely to be updated regularly in the near future. For more information, please read CONTRIBUTING.md.

  • I confirm that this is not a pure code agent PR.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@HanFa HanFa force-pushed the fix/autoconfig-register-precedence branch from 25ef1a9 to 400e4bb Compare March 29, 2026 04:33
@HanFa HanFa marked this pull request as ready for review March 29, 2026 04:40
@HanFa HanFa force-pushed the fix/autoconfig-register-precedence branch 2 times, most recently from 6187543 to 06bcb31 Compare March 29, 2026 05:10
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: huggingface#45093

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hmellor
Copy link
Copy Markdown
Member

hmellor commented Mar 31, 2026

Closing as I believe it is expected behaviour that trust_remote_code=True will force load the remote code, even if local code exists.

@hmellor hmellor closed this Mar 31, 2026
@hmellor hmellor reopened this Mar 31, 2026
@hmellor
Copy link
Copy Markdown
Member

hmellor commented Mar 31, 2026

Having clarified, my understanding of the intended behaviour of trust_remote_code was incorrect.

If there is local code present, Transformers should use it in preference to any remote code.

Copy link
Copy Markdown
Member

@hmellor hmellor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this change but will wait for an additional stamp from @ArthurZucker to confirm that this is desired behaviour

hmellor added 3 commits March 31, 2026 14:21
…g to transformers)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@hmellor
Copy link
Copy Markdown
Member

hmellor commented Mar 31, 2026

The expected behaviour is as follows:

  • If local code exists in Transformers and remote code exists in the checkpoint - do what trust_remote_code says
  • If local code exists that was registered outside of Transformers (i.e. by vLLM) - ignore trust_remote_code and always use the expicitly registered local code

@hmellor hmellor enabled auto-merge March 31, 2026 12:40
hmellor added 4 commits March 31, 2026 14:07
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: auto

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@hmellor hmellor added this pull request to the merge queue Mar 31, 2026
Merged via the queue into huggingface:main with commit 81db7d3 Mar 31, 2026
29 checks passed
sirzechs66 pushed a commit to sirzechs66/transformers that referenced this pull request Mar 31, 2026
…trained (huggingface#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: huggingface#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>
SangbumChoi pushed a commit to SangbumChoi/transformers that referenced this pull request Apr 4, 2026
…trained (huggingface#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: huggingface#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AutoConfig.register() ignored when trust_remote_code=True and auto_map is present

3 participants