FIX GCG: forward hf_token as None instead of an empty string#2275
Open
immu4989 wants to merge 2 commits into
Open
FIX GCG: forward hf_token as None instead of an empty string#2275immu4989 wants to merge 2 commits into
immu4989 wants to merge 2 commits into
Conversation
GCGGenerator._to_attack_params built params with token=self._hf_token or "". Since hf_token defaults to None (correct for a public model), the or "" turned it into an empty string, which huggingface_hub sends as 'Authorization: Bearer ' with no credential. httpx rejects that as an illegal header, so GCG could not load any ungated model. None is HuggingFace's value for anonymous access, so it is now forwarded unchanged. Widens ModelWorker.__init__'s token parameter to str | None to match, and adds regression tests for both the absent-token and supplied-token cases.
romanlutz
enabled auto-merge
July 26, 2026 00:41
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.
Fixes #2274.
GCGGenerator._to_attack_paramsbuilt the attack params withtoken=self._hf_token or "". Sincehf_tokendefaults toNone(correct for a public model), theor ""turned it into an empty string, whichhuggingface_hubsends asAuthorization: Bearerwith no credential. httpx rejects that as an illegal header, so GCG could not load any ungated model:Noneis HuggingFace's value for anonymous access, so it is forwarded unchanged now.Changes
generator.py: forwardself._hf_tokenas-is instead of coercingNoneto"".attack_manager.py: widenModelWorker.__init__'stokenparameter tostr | None, matching what is now passed.test_generator.py: newTestToAttackParamsTokencovering both the absent-token and supplied-token cases.The absent-token test fails on the current code with
assert '' is Noneand passes with the fix, so it pins the regression.Verification
I am separately setting up a run against
TinyLlama/TinyLlama-1.1B-Chat-v1.0on a free GPU to confirm the full load path end to end, and will post that here once it completes. The unit coverage above pins the specific defect regardless.