Repository navigation
FEAT: Add a HarmBench classifier scorer - #4237
Open
Siddhant Rajhans (siddhant-rajhans) wants to merge 5 commits into
Open
Siddhant Rajhans (siddhant-rajhans) wants to merge 5 commits into
Siddhant Rajhans (siddhant-rajhans) wants to merge 5 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>
Siddhant Rajhans (siddhant-rajhans)
force-pushed
the
feat/harmbench-classifier-scorer
branch
from
November 12, 2026 08:50
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.
Contributor
Author
|
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.
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
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.