Repository navigation
FEAT: Add a HarmBench classifier scorer - #4237
Open
Siddhant Rajhans (siddhant-rajhans) wants to merge 1 commit into
Open
Siddhant Rajhans (siddhant-rajhans) wants to merge 1 commit into
Siddhant Rajhans (siddhant-rajhans) wants to merge 1 commit 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
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.