Skip to content

[Generation] Fix default overwrite for non-None defaults#42958

Merged
vasqu merged 7 commits intohuggingface:mainfrom
vasqu:fix-generation-config-overwrite
Dec 19, 2025
Merged

[Generation] Fix default overwrite for non-None defaults#42958
vasqu merged 7 commits intohuggingface:mainfrom
vasqu:fix-generation-config-overwrite

Conversation

@vasqu
Copy link
Copy Markdown
Contributor

@vasqu vasqu commented Dec 19, 2025

Followup to #42702 where defaults are now either None or a boolean value.

The logic was dependent on the values being None which ignored overriding other values, e.g. do_sample. The fails due to this can be seen in a few integration tests, e.g. gpt2.

@vasqu
Copy link
Copy Markdown
Contributor Author

vasqu commented Dec 19, 2025

run-slow: gpt2,whisper,qwen2_5_vl,glm4v,biogpt

@github-actions
Copy link
Copy Markdown
Contributor

This comment contains run-slow, running the specified jobs:

models: ["models/biogpt", "models/glm4v", "models/gpt2", "models/qwen2_5_vl", "models/whisper"]
quantizations: []

Copy link
Copy Markdown
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

We need a small fast test 🫡

@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.

Comment thread src/transformers/generation/utils.py Outdated

# Due to some values being boolean and not `None`, we need additional logic to overwrite
# them explicitly (`defaults_only=False`)
generation_config.update(**{k: v for k, v in self.generation_config.to_dict().items() if isinstance(v, bool)})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so we don't need to restrict that update? to something like

default_gc = GenerationConfig()


bool_defaults = {k: v for k, v in self.generation_config.to_dict().items() if isinstance(v, bool)
    and hasattr(generation_config, k)
    and hasattr(default_gc, k)
    and getattr(generation_config, k) == getattr(default_gc, k)
}

generation_config.update(**bool_defaults)

just to be sure I understand 😁

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup, it's correct I didnt notice that we can pass a generation config directly there as well (e.g. as in assisted decoding)

@vasqu
Copy link
Copy Markdown
Contributor Author

vasqu commented Dec 19, 2025

run-slow: whisper,gemma3n,gpt2,moshi,bert

@github-actions
Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

⚠️ No test being reported (jobs are skipped or cancelled)!

@github-actions
Copy link
Copy Markdown
Contributor

💔 This comment contains run-slow, but unknown error occurred and the workflow run aborted!

@vasqu
Copy link
Copy Markdown
Contributor Author

vasqu commented Dec 19, 2025

run-slow: whisper,gemma3n,gpt2,moshi,bert

@github-actions
Copy link
Copy Markdown
Contributor

This comment contains run-slow, running the specified jobs:

models: ["models/bert", "models/gemma3n", "models/gpt2", "models/moshi", "models/whisper"]
quantizations: []

@vasqu vasqu mentioned this pull request Dec 19, 2025
2 tasks
@github-actions
Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

✅ No failing test specific to this PR 🎉 !

@github-actions
Copy link
Copy Markdown
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=42958&sha=202fd1

@vasqu vasqu enabled auto-merge (squash) December 19, 2025 17:36
@vasqu vasqu merged commit f218ed2 into huggingface:main Dec 19, 2025
25 checks passed
@vasqu vasqu deleted the fix-generation-config-overwrite branch December 19, 2025 17:37
Comment on lines +1802 to +1810
generation_config.update(
**{
k: v
for k, v in self.generation_config.to_dict().items()
if isinstance(v, bool)
and hasattr(default_generation_config, k)
and getattr(generation_config, k, None) == getattr(default_generation_config, k)
}
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sorry for late review. I think we're back to the original issue where users pass do_sample=False in their custom config and the model has do_sample=True saved on the hub. And since False is the default value, we won't update it here and keep True

In that case we'd need to set the booleans to None by default as well, I dont' see a cleaner way than defining None as non-set

SangbumChoi pushed a commit to SangbumChoi/transformers that referenced this pull request Jan 23, 2026
…face#42958)

* fix

* test

* fix 2

* should not happen but safety

* fast "integration" test
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.

5 participants