feat: Add generation_kwargs support to LogCompletionsCallback and Wea…#5625
feat: Add generation_kwargs support to LogCompletionsCallback and Wea…#5625LhaseParth2610 wants to merge 3 commits intohuggingface:mainfrom
Conversation
…veCallback Resolves an outstanding TODO in _generate_completions. This change allows users to pass simple generation keyword arguments (like max_new_tokens=50 or temperature=0.8) directly to the callbacks without needing to construct a full GenerationConfig object.
2b2f461 to
08b1df0
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 61468de. Configure here.
| generations = unwrapped_model.generate( | ||
| **tokenized_batch, | ||
| generation_config=generation_config, | ||
| **generation_kwargs, |
There was a problem hiding this comment.
Unfiltered kwargs risk TypeError in model.generate call
Low Severity
**generation_kwargs and **tokenized_batch are both unpacked into model.generate() without any key-conflict filtering. If generation_kwargs contains a key also present in tokenized_batch (e.g., input_ids, attention_mask), Python raises a TypeError for duplicate keyword arguments at the call site. The rest of the codebase avoids this by folding generation kwargs into a GenerationConfig object (via GenerationConfig(**generation_kwargs)) rather than passing them as raw **kwargs to generate().
Reviewed by Cursor Bugbot for commit 61468de. Configure here.


What does this PR do?
Resolves a
TODOin_generate_completions(callbacks.py) that originally requestedgeneration_kwargssupport.Before this PR,
LogCompletionsCallbackandWeaveCallbackonly accepted a fullGenerationConfigobject for controlling generation. This meant users couldn't pass simple, common keyword arguments likemax_new_tokens=50ortemperature=0.8directly to the callbacks.This PR introduces
**generation_kwargsto the following methods:_generate_completions()(the core utility)LogCompletionsCallback.__init__()WeaveCallback.__init__()These kwargs are stored and seamlessly forwarded to
model.generate(). Before being passed, we filter out any keys that conflict with explicitly defined arguments (likegeneration_configor tokenized batch keys) to preventTypeError: got multiple values for argument, adhering perfectly to standardtransformersbehavior safely.Before submitting
AI writing disclosure
We welcome the use of AI tools to help with contributions. For transparency and to help us improve our review process, please indicate the level of AI involvement in this PR.
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.
Note
Low Risk
Low risk: this only threads optional
**generation_kwargsthrough completion generation and logging, but could change logged outputs if users pass overrides that differ from the providedgeneration_config.Overview
Adds support for passing
**generation_kwargsthrough_generate_completions()and intomodel.generate(), allowing callers to overrideGenerationConfigfields via simple keyword args.Extends
LogCompletionsCallbackandWeaveCallbackto accept and store these kwargs, forwards them during completion generation, and records them in Weaveeval_attributesfor traceability.Reviewed by Cursor Bugbot for commit 61468de. Bugbot is set up for automated code reviews on this repo. Configure here.