Repository navigation
Add repetition_filter operator for degenerate rollout responses - #643
Open
Kingpython123 wants to merge 1 commit into
Open
Kingpython123 wants to merge 1 commit into
Kingpython123 wants to merge 1 commit into
Conversation
…tscope-ai#620) Add a RepetitionFilter experience operator that drops experiences whose generated response has collapsed into repetition. The response is scored by its duplicate n-gram ratio (1 - unique_ngrams / total_ngrams) over the model-generated tokens only, ignoring prompt tokens and tokens masked out by action_mask. Experiences are dropped when the ratio is strictly greater than max_repeat_ratio; empty and very short responses are always kept. - Register as repetition_filter in EXPERIENCE_OPERATORS - Add unit tests for the ratio function, the filter, action_mask handling and registry creation - Document built-in operators in the operator development guide (en/zh)
This branch has not been deployed
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.
Motivation
Closes #620. Part of the operator wish list in #470.
None of the existing experience filters (
reward_filter,reward_std_filter,dapo_dynamic_sampling,mask_response_truncated,invalid_reward_filter) look at the text of a response. Repetition collapse is a common failure mode of on-policy rollouts, especially for smaller models on long-horizon tasks: the policy keeps emitting the same pattern instead of terminating. Those trajectories consume rollout budget and carry almost no learning signal, yet they currently enter the training buffer like any other experience.Implementation
New operator
repetition_filter(trinity/buffer/operators/filters/repetition_filter.py), implemented onExperienceOperatorV1and registered inEXPERIENCE_OPERATORS.1 - unique_ngrams / total_ngramsover sliding windows ofngram_sizetokens. It is0.0for a fully diverse response and approaches1.0for a response that keeps repeating a short pattern (e.g.[7, 8, 9] * 20scores0.947withngram_size=4). No new dependencies.prompt_lengthare ignored, and whenaction_maskis present (multi-turn experiences) tokens with a zero mask (environment observations) are ignored as well.ratio > max_repeat_ratio(strict). Empty responses and responses with fewer thanmin_response_tokensgenerated tokens are always kept, since the ratio is noisy on very short sequences. Dropping (rather than masking) matches the wording of Good First Issue List #470; switching to zeroingaction_maskwould be a small change if preferred.ngram_size=4,max_repeat_ratio=0.5,min_response_tokens=32, as proposed in [FEATURE] Repetition filter operator for degenerate rollout responses #620.max_repeat_ratio=1.0disables the filter. Invalid arguments raiseValueErrorat construction time.filtered_count,skipped_empty_count,skipped_short_count,repeat_ratio/mean,repeat_ratio/max(the last two only when at least one response was scored).Docs
Added a "Built-in Operators" table to the operator development guide (
docs/sphinx_doc/source/tutorial/develop_operator.mdand thesource_zhcounterpart) listing all registered experience operators and their main arguments, including the new one.Tests
tests/buffer/repetition_filter_test.py(CPU-only, 11 tests) covers:ngram_size, single duplicate);ratio == max_repeat_ratiois kept);action_mask-excluded tokens not affecting the decision;max_repeat_ratio=1.0disabling the filter, argument validation, and creation throughcreate_operatorsfrom the registry.pre-commit runpasses on all changed files.