transformers - ✅(Solved) Fix tiny-random glm4v configuration can't load due to config validation changes [1 pull requests, 1 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#45030Fetched 2026-04-08 01:36:00
View on GitHub
Comments
0
Participants
1
Timeline
7
Reactions
1
Author
Participants
Timeline (top)
cross-referenced ×2mentioned ×2subscribed ×2closed ×1

Error Message

Traceback (most recent call last): File "[sic]\demo_glm4v_config.py", line 4, in <module> config = AutoConfig.from_pretrained("tiny-random/glm-4v") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "[sic]\src\transformers\models\auto\configuration_auto.py", line 1484, in from_pretrained return config_class.from_dict(config_dict, **unused_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "[sic]\src\transformers\configuration_utils.py", line 757, in from_dict config = cls(**config_dict) ^^^^^^^^^^^^^^^^^^ File "[sic]\transformers\Lib\site-packages\huggingface_hub\dataclasses.py", line 280, in init_with_validate cls.validate(self) # type: ignore [attr-defined] ^^^^^^^^^^^^^^^^^^ File "[sic]\transformers\Lib\site-packages\huggingface_hub\dataclasses.py", line 255, in validate validator(self) File "[sic]\src\transformers\modeling_rope_utils.py", line 723, in validate_rope validation_fn(rope_parameters, ignore_keys=self.ignore_keys_at_rope_validation) File "[sic]\src\transformers\modeling_rope_utils.py", line 733, in _validate_default_rope_parameters self._check_received_keys(rope_type, received_keys, required_keys, ignore_keys=ignore_keys) File "[sic]\src\transformers\modeling_rope_utils.py", line 921, in _check_received_keys raise KeyError(f"Missing required keys in rope_parameters for 'rope_type'='{rope_type}': {missing_keys}") KeyError: "Missing required keys in rope_parameters for 'rope_type'='default': {'rope_theta'}"

Fix Action

Fixed

PR fix notes

PR #45036: [fix] BC for legacy configs with top-level rope_theta when rope_parameters is set via rope_scaling

Description (problem / solution / changelog)

What does this PR do?

Fixes #45030

Configs like tiny-random/glm-4v store rope_theta at the top level of config.json alongside a rope_scaling dict (legacy format). For config classes that don't declare rope_parameters as a dataclass field (e.g. Glm4vConfig), convert_rope_params_to_dict is skipped because hasattr(self, "rope_parameters") is False before the kwargs loop.

During initialization, the kwargs loop sets self.rope_parameters via the rope_scaling property setter — but without rope_theta — and assigns self.rope_theta as a separate attribute. When @strict's validate_rope runs after __init__, it expects rope_theta inside rope_parameters and raises a KeyError.

Fix

Add a normalization step in PreTrainedConfig.__post_init__ after the kwargs loop:

  • If rope_parameters is a dict
  • AND rope_theta is missing from it
  • AND self.rope_theta exists
  • AND the rope type is "default"

→ Inject rope_theta into rope_parameters.

This ensures backward compatibility with legacy configs while keeping behavior unchanged for newer ones.

Why this is safe

  • New configs already:
    • declare rope_parameters as a field → go through convert_rope_params_to_dict, or
    • include rope_theta inside rope_parameters
  • The fix only applies to legacy edge cases
  • No change to validation logic (modeling_rope_utils.py untouched)

Test

python -c "from transformers import AutoConfig; AutoConfig.from_pretrained('tiny-random/glm-4v'); print('ok')"

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. #45030
  • 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.

Tagging: @ArthurZucker @CyrilVallez (model loading)

Changed files

  • src/transformers/configuration_utils.py (modified, +15/-0)

Code Example

from transformers import AutoConfig

config = AutoConfig.from_pretrained("tiny-random/glm-4v")
print(type(config))

---

Traceback (most recent call last):
  File "[sic]\demo_glm4v_config.py", line 4, in <module>
    config = AutoConfig.from_pretrained("tiny-random/glm-4v")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]\src\transformers\models\auto\configuration_auto.py", line 1484, in from_pretrained
    return config_class.from_dict(config_dict, **unused_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]\src\transformers\configuration_utils.py", line 757, in from_dict
    config = cls(**config_dict)
             ^^^^^^^^^^^^^^^^^^
  File "[sic]\transformers\Lib\site-packages\huggingface_hub\dataclasses.py", line 280, in init_with_validate
    cls.validate(self)  # type: ignore [attr-defined]
    ^^^^^^^^^^^^^^^^^^
  File "[sic]\transformers\Lib\site-packages\huggingface_hub\dataclasses.py", line 255, in validate
    validator(self)
  File "[sic]\src\transformers\modeling_rope_utils.py", line 723, in validate_rope
    validation_fn(rope_parameters, ignore_keys=self.ignore_keys_at_rope_validation)
  File "[sic]\src\transformers\modeling_rope_utils.py", line 733, in _validate_default_rope_parameters
    self._check_received_keys(rope_type, received_keys, required_keys, ignore_keys=ignore_keys)
  File "[sic]\src\transformers\modeling_rope_utils.py", line 921, in _check_received_keys
    raise KeyError(f"Missing required keys in `rope_parameters` for 'rope_type'='{rope_type}': {missing_keys}")
KeyError: "Missing required keys in `rope_parameters` for 'rope_type'='default': {'rope_theta'}"
RAW_BUFFERClick to expand / collapse

Hello!

I'm getting failures with the following script starting from #41250

from transformers import AutoConfig

config = AutoConfig.from_pretrained("tiny-random/glm-4v")
print(type(config))
Traceback (most recent call last):
  File "[sic]\demo_glm4v_config.py", line 4, in <module>
    config = AutoConfig.from_pretrained("tiny-random/glm-4v")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]\src\transformers\models\auto\configuration_auto.py", line 1484, in from_pretrained
    return config_class.from_dict(config_dict, **unused_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]\src\transformers\configuration_utils.py", line 757, in from_dict
    config = cls(**config_dict)
             ^^^^^^^^^^^^^^^^^^
  File "[sic]\transformers\Lib\site-packages\huggingface_hub\dataclasses.py", line 280, in init_with_validate
    cls.validate(self)  # type: ignore [attr-defined]
    ^^^^^^^^^^^^^^^^^^
  File "[sic]\transformers\Lib\site-packages\huggingface_hub\dataclasses.py", line 255, in validate
    validator(self)
  File "[sic]\src\transformers\modeling_rope_utils.py", line 723, in validate_rope
    validation_fn(rope_parameters, ignore_keys=self.ignore_keys_at_rope_validation)
  File "[sic]\src\transformers\modeling_rope_utils.py", line 733, in _validate_default_rope_parameters
    self._check_received_keys(rope_type, received_keys, required_keys, ignore_keys=ignore_keys)
  File "[sic]\src\transformers\modeling_rope_utils.py", line 921, in _check_received_keys
    raise KeyError(f"Missing required keys in `rope_parameters` for 'rope_type'='{rope_type}': {missing_keys}")
KeyError: "Missing required keys in `rope_parameters` for 'rope_type'='default': {'rope_theta'}"

Note that the remote config uses the old-style top-level rope parameters, including rope_theta: https://huggingface.co/tiny-random/glm-4v/blob/main/config.json#L28-L37 Is this expected to fail now, or is this an issue of the old-style configuration not propagating nicely to this validation check?

cc @zucchini-nlp

  • Tom Aarsen

Originally posted by @tomaarsen in https://github.com/huggingface/transformers/issues/41250#issuecomment-4137165128

extent analysis

Fix Plan

To fix the issue, we need to update the configuration to use the new-style rope parameters.

Here are the steps:

  • Update the config.json file to use the new-style rope parameters.
  • Use the from_dict method to load the configuration from a dictionary.

Example code:

from transformers import AutoConfig

# Load the configuration from a dictionary
config_dict = {
    "rope": {
        "rope_type": "default",
        "rope_theta": 0.01
    }
}

# Create a new configuration object from the dictionary
config = AutoConfig.from_dict(config_dict)

print(type(config))

Alternatively, you can also update the config.json file to use the new-style rope parameters and then load it using the from_pretrained method:

from transformers import AutoConfig

# Update the config.json file to use the new-style rope parameters
# {
#     "rope": {
#         "rope_type": "default",
#         "rope_theta": 0.01
#     }
# }

# Load the configuration from the updated config.json file
config = AutoConfig.from_pretrained("tiny-random/glm-4v")

print(type(config))

Verification

To verify that the fix worked, you can check the type of the config object and make sure it is an instance of AutoConfig. You can also check the values of the rope parameters to ensure they are correct.

Extra Tips

Make sure to update the config.json file to use the new-style rope parameters to avoid any future issues. Also, note that the from_pretrained method will throw an error if the configuration file is not in the correct format.

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 tiny-random glm4v configuration can't load due to config validation changes [1 pull requests, 1 participants]