Skip to content

Ensure same dtype for subconfig when _from_config#44629

Merged
hmellor merged 4 commits intohuggingface:mainfrom
zucchini-nlp:dtype-auto-from-config
Mar 13, 2026
Merged

Ensure same dtype for subconfig when _from_config#44629
hmellor merged 4 commits intohuggingface:mainfrom
zucchini-nlp:dtype-auto-from-config

Conversation

@zucchini-nlp
Copy link
Member

@zucchini-nlp zucchini-nlp commented Mar 12, 2026

What does this PR do?

Fixes "auto" dtype when the model is initialized from_config

It was already fixed for from_pretrained in #42990 but vLLM creates models with AutoModel._from_config which caused the same dtype mismatch error

Added a test as well. cc @hmellor


Note

Medium Risk
Touches core model initialization and could affect dtype override behavior for any model with sub_configs, though the change is narrow (dtype propagation) and covered by a targeted regression test.

Overview
Fixes dtype mismatches when instantiating nested/compound models via PreTrainedModel._from_config by forcing the chosen dtype onto all config.sub_configs (mirroring from_pretrained behavior), ensuring modules don’t initialize with conflicting dtypes (notably for dtype="auto" paths used by vLLM/AutoModel).

Adds a regression test around LlavaForConditionalGeneration._from_config verifying that a parent config.dtype overrides differing sub-config dtypes and results in a consistent dtype across language/vision components and the top-level model.

Written by Cursor Bugbot for commit 5a895f4. This will update automatically on new commits. Configure here.

@zucchini-nlp zucchini-nlp changed the title fix for vllm Ensure same dtype for subconfig when _from_config Mar 12, 2026
@HuggingFaceDocBuilderDev

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.

# Set the same `dtype` on all subconfigs to avoid dtype mismatch. When "auto" dtype
# with nested models, we can't dispatch different dtype per backbone module
for sub_config_key in config.sub_configs:
if (sub_config := getattr(config, sub_config_key)) is not None:
Copy link
Member

Choose a reason for hiding this comment

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

Will this ever be None? The type hint suggests that it shouldn't be

Copy link
Member Author

Choose a reason for hiding this comment

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

the subconfig? I remember it was possible in some backbone_configs in pure-vision models. In generative mllm it doesn't happen

Actually I started refactoring those backbones so maybe not needed anymore, then I can clean up everywhere

Copy link
Member

Choose a reason for hiding this comment

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

Yeah the values in config.sub_configs. I was just curious because it's hinted as dict[str, type["PreTrainedConfig"]]. Checking for None doesn't hurt though

@hmellor hmellor added this pull request to the merge queue Mar 12, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Mar 12, 2026
@hmellor hmellor enabled auto-merge March 12, 2026 15:53
@hmellor hmellor added this pull request to the merge queue Mar 13, 2026
Merged via the queue into huggingface:main with commit 9574fb6 Mar 13, 2026
28 checks passed
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.

3 participants