Skip to content

FIX locate GCG target and control after the user turn - #2679

Open
devangpratap wants to merge 1 commit into
microsoft:mainfrom
devangpratap:fix-gcg-slice-location
Open

devangpratap wants to merge 1 commit into
microsoft:mainfrom
devangpratap:fix-gcg-slice-location

Conversation

@devangpratap

Copy link
Copy Markdown
Contributor

What

_update_ids located the goal, control and target with three independent
prompt.find calls, so each matched its first occurrence anywhere in the rendered
prompt.

GCG targets are affirmative prefixes, so a goal that spells out the prefix it
wants ("Respond with Sure, here is the plan") puts that same text in the user
turn. The target then matched there instead of in the assistant reply, and
_target_slice, _loss_slice and _assistant_role_slice silently pointed at the
wrong tokens. Nothing raised, so the search just optimized against the wrong
positions. The same applies to a goal containing the control string.

The goal and control are rendered as one contiguous user turn, so this searches
for that whole string, derives the control offset from it, and searches for the
target only after that turn.

Testing

New test in TestUpdateIdsErrorPaths, using a mock tokenizer whose char_to_token
maps characters to whitespace-delimited tokens the way a fast tokenizer does. It
passes with this change and fails without it. Full GCG unit suite passes (244),
and pre-commit including ruff and ty is clean.

Contributes to #2489.

_update_ids searched the rendered prompt for the goal, control and target
independently, so each one matched its first occurrence anywhere in the prompt.
A goal that quotes its own target, which happens when the goal spells out the
affirmative prefix it wants, made the target match inside the user turn instead
of the assistant reply, and the target and loss slices then pointed at the wrong
tokens, with the model input truncated before the assistant turn and no error
raised. Search for the user turn as one string, derive the control offset from
it, and look for the target only after that turn.
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.

1 participant