Skip to content

FIX GCG: forward hf_token as None instead of an empty string#2275

Merged
romanlutz merged 2 commits into
microsoft:mainfrom
immu4989:fix/gcg-empty-hf-token
Jul 26, 2026
Merged

FIX GCG: forward hf_token as None instead of an empty string#2275
romanlutz merged 2 commits into
microsoft:mainfrom
immu4989:fix/gcg-empty-hf-token

Conversation

@immu4989

Copy link
Copy Markdown
Contributor

Fixes #2274.

GCGGenerator._to_attack_params built the attack 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:

_StrategyRuntimeError: Strategy execution failed for GCGGenerator: Illegal header value b'Bearer '

None is HuggingFace's value for anonymous access, so it is forwarded unchanged now.

Changes

  • generator.py: forward self._hf_token as-is instead of coercing None to "".
  • attack_manager.py: widen ModelWorker.__init__'s token parameter to str | None, matching what is now passed.
  • test_generator.py: new TestToAttackParamsToken covering both the absent-token and supplied-token cases.

The absent-token test fails on the current code with assert '' is None and passes with the fix, so it pins the regression.

Verification

pytest tests/unit/executor/promptgen/gcg
=> 199 passed

pre-commit run
=> all hooks passed, including ruff and ty

I am separately setting up a run against TinyLlama/TinyLlama-1.1B-Chat-v1.0 on 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.

immu4989 and others added 2 commits July 25, 2026 07:16
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 romanlutz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Thanks @immu4989

@romanlutz
romanlutz enabled auto-merge July 26, 2026 00:41
@romanlutz
romanlutz added this pull request to the merge queue Jul 26, 2026
Merged via the queue into microsoft:main with commit 944a551 Jul 26, 2026
54 checks passed
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.

BUG GCGGenerator cannot load public models: empty hf_token sends an illegal 'Bearer ' header

2 participants