transformers - ✅(Solved) Fix AutoConfig.register() ignored when trust_remote_code=True and auto_map is present [1 pull requests, 3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
huggingface/transformers#45093Fetched 2026-04-08 01:45:14
View on GitHub
Comments
3
Participants
3
Timeline
19
Reactions
0
Author
Timeline (top)
referenced ×8commented ×3cross-referenced ×3closed ×2

AutoConfig.register() is silently ignored when trust_remote_code=True and the model's config.json contains auto_map.AutoConfig. This makes it impossible for downstream libraries to override a broken remote config class.

Root Cause

In configuration_auto.py, from_pretrained checks has_remote_code and trust_remote_code before checking CONFIG_MAPPING:

# Line 1478-1483
if has_remote_code and trust_remote_code:
    config_class = get_class_from_dynamic_module(class_ref, ...)  # always wins
    return config_class.from_pretrained(...)
elif "model_type" in config_dict:
    config_class = CONFIG_MAPPING[config_dict["model_type"]]  # never reached

When a class has been explicitly registered via AutoConfig.register(), it should take precedence over auto_map remote code — the caller has explicitly said "use this class for this model_type."

Fix Action

Fixed

PR fix notes

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

Description (problem / solution / changelog)

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?

<!-- Congratulations! You've made it this far! You're not quite done yet though. Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution. Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change. Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost. --> <!-- Remove if not applicable -->

Fixes: https://github.com/huggingface/transformers/issues/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.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @ If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**. Please tag fewer than 3 people. Models: - text models: @ArthurZucker @Cyrilvallez - vision models: @yonigozlan @molbap - audio models: @eustlb @ebezzam @vasqu - multimodal models: @zucchini-nlp - graph models: @clefourrier Library: - generate: @zucchini-nlp (visual-language models) or @gante (all others) - continuous batching: @remi-or @ArthurZucker @McPatate - pipelines: @Rocketknight1 - tokenizers: @ArthurZucker and @itazap - trainer: @SunMarc - attention: @vasqu @ArthurZucker @CyrilVallez - model loading (from pretrained, etc): @CyrilVallez - distributed: @3outeille @ArthurZucker - CIs: @ydshieh Integrations: - ray/raytune: @richardliaw, @amogkam - Big Model Inference: @SunMarc - quantization: @SunMarc - kernels: @drbh - peft: @BenjaminBossan @githubnemo Devices/Backends: - AMD ROCm: @ivarflakstad - Intel XPU: @IlyasMoutawwakil - Ascend NPU: @ivarflakstad Documentation: @stevhliu Research projects are not maintained and should be taken as is. -->

Changed files

  • src/transformers/models/auto/auto_factory.py (modified, +2/-2)
  • src/transformers/models/auto/configuration_auto.py (modified, +1/-1)
  • src/transformers/models/auto/feature_extraction_auto.py (modified, +1/-1)
  • src/transformers/models/auto/image_processing_auto.py (modified, +1/-1)
  • src/transformers/models/auto/processing_auto.py (modified, +1/-1)
  • src/transformers/models/auto/tokenization_auto.py (modified, +1/-1)
  • src/transformers/models/auto/video_processing_auto.py (modified, +1/-1)
  • tests/models/auto/test_configuration_auto.py (modified, +6/-1)
  • tests/models/auto/test_feature_extraction_auto.py (modified, +10/-1)
  • tests/models/auto/test_image_processing_auto.py (modified, +10/-1)
  • tests/models/auto/test_modeling_auto.py (modified, +7/-1)
  • tests/models/auto/test_processor_auto.py (modified, +4/-4)
  • tests/models/auto/test_tokenization_auto.py (modified, +11/-0)
  • tests/models/auto/test_video_processing_auto.py (modified, +10/-1)

Code Example

from transformers import AutoConfig, PretrainedConfig

# 1. Register a local config class for a model_type
class MyFixedConfig(PretrainedConfig):
    model_type = "hyperclovax_vlm"
    def __init__(self, text_config=None, **kwargs):
        self.text_config = None  # always set
        super().__init__(**kwargs)
    def get_text_config(self, decoder=False):
        return self.text_config if self.text_config is not None else self

AutoConfig.register("hyperclovax_vlm", MyFixedConfig, exist_ok=True)

# 2. Load with trust_remote_code=False — uses registered classconfig = AutoConfig.from_pretrained(
    "naver-hyperclovax/HyperCLOVAX-SEED-Vision-Instruct-3B",
    trust_remote_code=False,
)
print(type(config))  # <class 'MyFixedConfig'>

# 3. Load with trust_remote_code=True — ignores registered classconfig = AutoConfig.from_pretrained(
    "naver-hyperclovax/HyperCLOVAX-SEED-Vision-Instruct-3B",
    trust_remote_code=True,
)
print(type(config))  # remote HCXVisionConfig, NOT MyFixedConfig
# This crashes because the remote code has a bug in get_text_config()

---

# Line 1478-1483
if has_remote_code and trust_remote_code:
    config_class = get_class_from_dynamic_module(class_ref, ...)  # always wins
    return config_class.from_pretrained(...)
elif "model_type" in config_dict:
    config_class = CONFIG_MAPPING[config_dict["model_type"]]  # never reached

---

vLLM code (we control):
    AutoProcessor.from_pretrained(..., trust_remote_code=True)  ← must pass True
                                                                   because the PROCESSOR
                                                                   itself is remote code

    transformers internals (we don't control):
AutoConfig.from_pretrained(..., trust_remote_code=True)  ✗ loads broken remote config

---

if has_remote_code and trust_remote_code and not has_local_code:
    config_class = get_class_from_dynamic_module(class_ref, ...)
elif "model_type" in config_dict:
    config_class = CONFIG_MAPPING[config_dict["model_type"]]
RAW_BUFFERClick to expand / collapse

Description

AutoConfig.register() is silently ignored when trust_remote_code=True and the model's config.json contains auto_map.AutoConfig. This makes it impossible for downstream libraries to override a broken remote config class.

Reproduction

from transformers import AutoConfig, PretrainedConfig

# 1. Register a local config class for a model_type
class MyFixedConfig(PretrainedConfig):
    model_type = "hyperclovax_vlm"
    def __init__(self, text_config=None, **kwargs):
        self.text_config = None  # always set
        super().__init__(**kwargs)
    def get_text_config(self, decoder=False):
        return self.text_config if self.text_config is not None else self

AutoConfig.register("hyperclovax_vlm", MyFixedConfig, exist_ok=True)

# 2. Load with trust_remote_code=False — uses registered class ✓
config = AutoConfig.from_pretrained(
    "naver-hyperclovax/HyperCLOVAX-SEED-Vision-Instruct-3B",
    trust_remote_code=False,
)
print(type(config))  # <class 'MyFixedConfig'>

# 3. Load with trust_remote_code=True — ignores registered class ✗
config = AutoConfig.from_pretrained(
    "naver-hyperclovax/HyperCLOVAX-SEED-Vision-Instruct-3B",
    trust_remote_code=True,
)
print(type(config))  # remote HCXVisionConfig, NOT MyFixedConfig
# This crashes because the remote code has a bug in get_text_config()

Root Cause

In configuration_auto.py, from_pretrained checks has_remote_code and trust_remote_code before checking CONFIG_MAPPING:

# Line 1478-1483
if has_remote_code and trust_remote_code:
    config_class = get_class_from_dynamic_module(class_ref, ...)  # always wins
    return config_class.from_pretrained(...)
elif "model_type" in config_dict:
    config_class = CONFIG_MAPPING[config_dict["model_type"]]  # never reached

When a class has been explicitly registered via AutoConfig.register(), it should take precedence over auto_map remote code — the caller has explicitly said "use this class for this model_type."

Impact

This affects any downstream library (e.g., vLLM) that vendors config fixes for models with broken remote code. Even after registering the fixed config, internal calls from AutoTokenizer.from_pretrained() and AutoProcessor.from_pretrained() pass trust_remote_code=True and bypass the registration.

The code trace looks something like:

vLLM code (we control):
    AutoProcessor.from_pretrained(..., trust_remote_code=True)  ← must pass True
                                                                   because the PROCESSOR
                                                                   itself is remote code

    transformers internals (we don't control):
      → AutoConfig.from_pretrained(..., trust_remote_code=True)  ✗ loads broken remote config

Concrete example: vLLM vendors a fixed HCXVisionConfig to handle empty initialization (needed for v5's @strict validation). get_config() correctly uses the vendored class, but AutoProcessor internally calls AutoConfig.from_pretrained(trust_remote_code=True) which loads the broken remote code and crashes.

Related: vllm-project/vllm#38387, #44956

Suggested Fix

Only prefer remote code when no local/registered class exists:

if has_remote_code and trust_remote_code and not has_local_code:
    config_class = get_class_from_dynamic_module(class_ref, ...)
elif "model_type" in config_dict:
    config_class = CONFIG_MAPPING[config_dict["model_type"]]

Environment

  • transformers: main branch (commit 9a9997fd73)
  • Python: 3.12

extent analysis

Fix Plan

To fix the issue, we need to modify the from_pretrained method in configuration_auto.py to prefer registered local classes over remote code when trust_remote_code=True.

Here are the steps:

  • Modify the from_pretrained method to check for local classes before loading remote code.
  • Update the condition to load remote code only when no local class is registered.

Example code:

if has_remote_code and trust_remote_code and not CONFIG_MAPPING.get(config_dict["model_type"]):
    config_class = get_class_from_dynamic_module(class_ref, ...)  # load remote code
elif "model_type" in config_dict:
    config_class = CONFIG_MAPPING[config_dict["model_type"]]  # use registered local class

Alternatively, you can use the suggested fix:

if has_remote_code and trust_remote_code and not has_local_code:
    config_class = get_class_from_dynamic_module(class_ref, ...)
elif "model_type" in config_dict:
    config_class = CONFIG_MAPPING[config_dict["model_type"]]

Make sure to update the has_local_code variable to check if a local class is registered for the given model_type.

Verification

To verify the fix, run the reproduction code with trust_remote_code=True and check if the registered local class is used:

config = AutoConfig.from_pretrained(
    "naver-hyperclovax/HyperCLOVAX-SEED-Vision-Instruct-3B",
    trust_remote_code=True,
)
print(type(config))  # should print <class 'MyFixedConfig'>

Extra Tips

  • Make sure to test the fix with different models and configurations to ensure it works as expected.
  • Consider adding a test case to the transformers library to prevent similar issues in the future.
  • If you're using a downstream library like vLLM, make sure to update the library to use the fixed AutoConfig class.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

transformers - ✅(Solved) Fix AutoConfig.register() ignored when trust_remote_code=True and auto_map is present [1 pull requests, 3 comments, 3 participants]