Don't let generation_kwargs leak into the class-level PIPELINE_KWARGS - #5
Closed
tonycoder-hub wants to merge 1 commit into
Closed
Don't let generation_kwargs leak into the class-level PIPELINE_KWARGS#5tonycoder-hub wants to merge 1 commit into
tonycoder-hub wants to merge 1 commit into
Conversation
Text2TextGenerationEvaluator.compute() updated the class attribute PIPELINE_KWARGS in place, so generation_kwargs passed to one call kept being forwarded to the pipeline on every later call and on every other instance of the evaluator. Co-authored-by: Tony Coder <407243179@qq.com>
Owner
Author
|
Closing as stale — opened on or before 2026-08-17 and still unmerged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Text2TextGenerationEvaluator.compute()merged the caller'sgeneration_kwargsintoPIPELINE_KWARGSwith an in-place update:PIPELINE_KWARGSis a class attribute, soself.PIPELINE_KWARGS.update(...)mutates the dict that is shared by the class and every one of its instances. Ageneration_kwargsvalue passed to a singlecompute()call is therefore forwarded to the pipeline on every later call in the same process, including calls made through a completely separate evaluator object.Reproduced on
main(a7dd338) with a dummy pipeline that records the kwargs it is called with:The second
compute()call was made on a brand newevaluator("text2text-generation")and passed nogeneration_kwargs, yet the pipeline still receivedmax_length=5. The same applies toSummarizationEvaluatorandTranslationEvaluator, which each define their ownPIPELINE_KWARGS.Fix
Build a per-call dict from the class defaults instead of mutating them, so
generation_kwargsare scoped to thecompute()call that supplied them:Using
type(self)keeps the subclass defaults (SummarizationEvaluator,TranslationEvaluator) intact, and assigning toselfshadows rather than mutates the class attribute.Tests
tests/test_evaluator.py:DummyText2TextGenerationPipelinenow records the kwargs it was called with, so tests can assert what actually reached the pipeline.test_generation_kwargschecks thatgeneration_kwargsare forwarded to the pipeline alongside the class defaults.test_generation_kwargs_are_not_persistedchecks that the class attribute is untouched and that a latercompute()withoutgeneration_kwargsno longer sees them. This test fails onmainand passes with the fix.black,isortandflake8are clean on both changed files.