Repository navigation
FIX GCG: render decoded controls without a second separator space - #3581
Open
devangpratap wants to merge 1 commit into
Open
devangpratap wants to merge 1 commit into
devangpratap wants to merge 1 commit into
Conversation
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.
Description
GCG renders the user turn as
f"{goal} {control}", and every accepted candidate comes back as a string decoded from the control tokens. On Gemma and on byte-level BPE tokenizers the first control token carries the separator space (▁!,Ġ!), so the decoded candidate starts with a space. Writing it back throughcontrol_strthen rendersgoal controlwith a double space.LengthPreservingFilterandget_filtered_candscannot catch this because they re-tokenize the candidate on its own, where the leading space is absorbed into the first token. In the rendered prompt it becomes an extra token.I ran 6 accepted candidates through
LengthPreservingFilterandcontrol_stron the real tokenizers of 10 models. On main:suncat)._goal_sliceand_control_slice, so the model is optimized on a prompt with an extra token._update_idsnow drops that one leading space before rendering. Every write to the control goes through it (__init__,control_str,control_toks). With this change all 10 tokenizers keep 4 control tokens and render no double space, and the control tokens in the prompt are the ones the candidate was scored with. On main they differed for Gemma on every accepted candidate.The fix is in the rendering rather than in the filters because the decoded form is the right candidate string:
logits()and the length check tokenize it on its own, and" z sun"tokenizes toĠz Ġsun, matching the prompt, while"z sun"givesz Ġsun.PR 5 of the #2489 series. The adapter-contract PR is next; I already have it in progress.
Tests and Documentation
test_decoded_candidate_with_the_separator_space_renders_like_the_originalwith the byte-level offline tokenizer: settingcontrol_strto the decoded form" ! !"gives the same control,input_idsand control slice as the original prompt. It fails on main.uv run pytest tests/unit/executor/promptgen/gcg/: 445 passed, 0 skipped.pre-commit runon the changed files passes, including ruff and ty.