Repository navigation
FEAT: Add a HarmBench classifier scorer - #4237
hannahwestra25 merged 8 commits into
Conversation
HarmBench measures attack success with a fine-tuned classifier (cais/HarmBench-Llama-2-13b-cls) that answers whether a generation is an instance of a behavior. HarmBenchScorer sends HarmBench's own classifier prompts (MIT), standard and contextual, to a target serving the classifier and returns True when it answers yes. The objective is the behavior; a contextual behavior is read the way PyRIT's HarmBench dataset builds it. Like HarmBench, it clips each response to 512 tokens of the classifier's pinned tokenizer before classification. Signed-off-by: Siddhant Rajhans <51508945+siddhant-rajhans@users.noreply.github.com>
5a6e123 to
0c0afb3
Compare
…ctives up front - The parser no longer writes a harmbench_raw_output metadata key: the rationale already quotes the classifier's answer and nothing read the key, so there is no namespaced key left without an owning model. - Reject a whitespace-only objective in HarmBenchScorer._validate_expectation, after the shared check, instead of in the piece hook, so it raises MissingConditionError before any classifier call.
|
Updated ahead of review, to match what #4229's review asked for (c751703, after merging main):
|
ty 0.0.105, now pinned on main, renamed unresolved-attribute to missing-attribute and reports an annotated assignment from an Any value as unsound. Use the new rule name and narrow the tokenizer's decode() result with cast, as main does elsewhere.
hannahwestra25
left a comment
There was a problem hiding this comment.
Question about doc/code/scoring/0_scoring.ipynb: since this branch was cut, main (#4358) added a scorer reference table to that notebook. The table is generated from pyrit.score.__all__, so it will pick up HarmBenchScorer automatically, but the committed notebook output on main won't list it until the notebook is re-executed. Do you mind merging main and re-running this notebook so the committed table includes HarmBenchScorer?
|
Done: merged main (9c26548; the conflicts were the StrongREJECT entries from #4229 in |
hannahwestra25
left a comment
There was a problem hiding this comment.
Automated review completed. No blocking concerns remain. This review records source coverage; merging is handled separately.
Description
PyRIT loads HarmBench's behaviors but has no scorer for HarmBench's attack-success classifier (Mazeika et al., 2024, arXiv:2402.04249), the fine-tuned
cais/HarmBench-Llama-2-13b-clsthat answers whether a response is an instance of a behavior. This addsHarmBenchScorer, which reproduces HarmBench's classification step.HarmBenchScorersends HarmBench's classifier prompt, standard or contextual, to a target serving the classifier and returns True when it answers "Yes", so it can serve as an attack's objective scorer. The objective is the behavior; a contextual behavior is read the wayharmbench_dataset.pybuilds it. HarmBench's copyright behaviors are scored by hashing and are out of scope.[INST]wrapper the classifier was trained on, so the classifier is served from a completions endpoint (OpenAICompletionTarget), as withWildGuardScorer.huggingfaceextra), which also keeps long responses inside the classifier's 2,048-token context.clip_generations=Falsesends full responses.InvalidJsonExceptionotherwise, so the judge retry applies. Judgments replay like LlamaGuard's.With the real classifier on the 395 human-labelled responses in
scorer_evals/objective, the scorer gives the same label as HarmBench's own pipeline (evaluate_completions.pyclipping, thenvllm.LLM.generateat temperature 0) for 394 of 395 responses; the one difference is between vLLM's offline and server modes on an identical request. Against the human labels,ObjectiveScorerEvaluatorgives accuracy 0.878, precision 0.918, recall 0.822 and F1 0.867.