Run this model with HF Jobs
Run imperial-cpg/gpt-oss-20b-secalign-lr1e-4-1ep on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/imperial-cpg/gpt-oss-20b-secalign-lr1e-4-1ep. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/imperial-cpg/gpt-oss-20b-secalign-lr1e-4-1ep on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/imperial-cpg/gpt-oss-20b-secalign-lr1e-4-1ep. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/imperial-cpg/gpt-oss-20b-secalign-lr1e-4-1ep. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use imperial-cpg/gpt-oss-20b-secalign-lr1e-4-1ep with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use imperial-cpg/gpt-oss-20b-secalign-lr1e-4-1ep with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("/mnt/data/artifacts/hf_cache/hub/models--openai--gpt-oss-20b/snapshots/6cee5e81ee83917806bbde320786a8fb61efebee") model = PeftModel.from_pretrained(base_model, "imperial-cpg/gpt-oss-20b-secalign-lr1e-4-1ep") - Notebooks
- Google Colab
- Kaggle
gpt-oss-20b-secalign-lr1e-4-1ep
A Meta SecAlign adapter for
openai/gpt-oss-20b: LoRA DPO on preference pairs where the chosen response ignores
an injected instruction and the rejected response follows it, with the untrusted
span wrapped in its own delimited turn — which is SecAlign's actual mechanism.
The untrusted span renders as a dedicated Harmony turn:
<|start|>input<|message|>{tool output}<|end|>
mirroring SecAlign's Llama delimiter (<|start_header_id|>input<|end_header_id|>), so
the model can learn a boundary the prompt does not control. Concretely, input is an
untrusted header role rather than an inline one:
| tokenizer setting | value |
|---|---|
untrusted_inline_roles |
[] |
untrusted_header_roles |
["ipython", "tool", "input"] |
role_remap |
{"tool": "input"} at inference |
The role_remap is required at inference. Tool output arrives on the tool role
but was trained behind the input delimiter; serving it as tool is a train/serve
format mismatch that still produces plausible-looking numbers.
⚠️ The delimiter is escapable, and its exploitability is unmeasured. Nothing stops
untrusted content from emitting the boundary's own bytes: a tool result containing
<|end|><|start|>user lands in a second, attacker-authored user turn. That is inherent
to any defense implemented as bytes in the token stream, not a flaw in this training
run.
Whether it works is a separate question this evaluation does not answer. The reported
ASR comes from AgentDojo's important_instructions, which does not attempt delimiter
forgery, so these numbers place no bound on forgery resistance. The adapter is
published as a baseline to compare against, which is what it is good for.
Learning rate 1e-4, 1 epoch. Arm v2secalign_ep1 in the sweep described below.
Training
| base model | openai/gpt-oss-20b (MXFP4, dequantized to bf16) |
| objective | DPO (β=0.1, no label smoothing) |
| data | AlpacaFarm-derived preference traces (preference_gptoss120b_traces_dpo_jul28), 90/10 train/eval split |
| LoRA rank / α | 64 / 8 (α/r = 0.125) |
| dropout | 0.0 — forced; peft's 3-D expert ParamWrapper raises on nonzero |
| target modules | q_proj, v_proj |
| target parameters | mlp.experts.gate_up_proj, mlp.experts.down_proj |
| trainable params | 38,043,648 (0.18% of ~21B) — 15.9M attention + 22.1M expert |
| learning rate | 1e-4, cosine, no warmup |
| epochs | 1 |
| max sequence length | 4096 |
| precision | bf16, activation checkpointing on |
The MoE expert weights are 3-D nn.Parameters inside GptOssExperts, reachable only
via peft's target_parameters. Rank is divided by the expert count, so per-expert
effective_r = 64 // 32 = 2, keeping the adapter budget comparable to a dense layer.
Results — AgentDojo v1.2.2, attack important_instructions
| suite | clean util | attacked util | ASR | n attacked |
|---|---|---|---|---|
| workspace | 73.7% | 71.1% | 0.19% | 532 |
| slack | 71.4% | 49.5% | 3.88% | 103 |
| travel | 20.0% | 22.9% | 0.00% | 140 |
| banking | 62.5% | 54.9% | 6.25% | 144 |
| pooled | 60.0% | 58.8% | 1.52% | 919 |
Against the unmodified base model on the same task set — clean 66.3%, attacked 53.6%, ASR 24.00%:
- attack success rate 24.00% → 1.52% (-22.47pp)
- attacked utility 53.6% → 58.8% (+5.1pp)
- clean utility 66.3% → 60.0% (-6.3pp)
Scoring convention
AgentDojo's own utility and security verdicts are used exactly as recorded.
Nothing is overridden. Two workspace user tasks are excluded from every arm alike:
user_task_35, user_task_38 — one never fits the 12288-token
context cap, and the other sits at it, so whether it fits depends on how verbose the
arm is, which measures verbosity rather than defense.
An earlier version of this card described a different convention, in which a task the
harness could not evaluate was forced to fail both axes. That was retired after reading
the trajectories: a prompt only exceeds the cap after many turns, so such a task has
usually already acted — and some had already carried the injection out. Forcing
security=False there deletes real attack successes.
Usage
Serve the adapter — do not merge it. The trained delta is tiny:
|B@A|·scaling ≈ 7e-6, roughly 16× below the bf16 representable step near the base weights
(1.26e-4). merge_and_unload() rounds 84.8% of q_proj's delta elements to exactly
zero, silently producing something very close to the base model — a defense that reports
as broken for reasons that have nothing to do with training. Runtime LoRA keeps B@(A@x)
as a separate term and is unaffected.
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM
base = AutoModelForCausalLM.from_pretrained(
"openai/gpt-oss-20b", torch_dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(base, "imperial-cpg/gpt-oss-20b-secalign-lr1e-4-1ep").eval()
Rendering is the whole defense here, so use the channel tokenizer configured the way
this adapter was trained — AutoTokenizer will not produce the input delimiter:
from interppi.attention_gating.model_utils import gated_classes_for
_, tok_cls = gated_classes_for("openai/gpt-oss-20b")
tok = tok_cls.from_pretrained(
"openai/gpt-oss-20b",
role_remap={"tool": "input"}, # AgentDojo sends `tool`; train-time role is `input`
untrusted_inline_roles=[], # override the default ["input"]
untrusted_header_roles=["ipython", "tool", "input"])
A worked end-to-end example is in
notebooks/attention_gate/demos/gpt_oss_secalign_demo.ipynb.
Prompt rendering matters more than you would expect
The reported numbers assume tool results are rendered as raw text in the Harmony
format. Rendering them through a template that JSON-escapes tool content (HF's stock
gpt-oss Jinja template applies |tojson) acts as an accidental injection defense worth
3.6% vs 8.6% ASR on identical tasks — a difference attributable purely to prompt
bytes. If you compare this adapter against anything, hold rendering fixed.
Limitations
- Single training run, single seed. ~11% of AgentDojo trajectories differ run-to-run at temperature 0 on this model (suspected MoE top-4 routing sensitivity), so ASR differences below ~2pp are inside noise.
- One attack (
important_instructions) on AgentDojo v1.2.2. No claim about others. - Clean utility rests on 95 tasks, so ~1pp is ~1 task.
- Conversation date pinned to 2024-06-01 for training and evaluation.
- Served with
--max-model-len 12288and--max-tokens 8192; longer limits will change which tasks are reachable. - Scored over 919 attacked pairs, not 921.
slack/user_task_20 × injection_task_1produced no result file, andslack/user_task_19 × injection_task_1crashes AgentDojo's own utility checker withKeyError: 'Alice'(slack/user_tasks.py:337indexesuser_channels["Alice"]unguarded, so an agent that removed Alice makes it raise instead of returningFalse). Deterministic, so retrying cannot fix it. 12 of the 13 arms scored that task without incident.
Related
The comparison arm is learned per-head channel attention gates — a [3, 3, 64]
log-bias added pre-softmax per layer, 13,824 trainable parameters against this
adapter's 38M, i.e. 2,752× smaller. On the same data and task set the best gate setting
reaches lower ASR than the SecAlign baseline at higher clean and attacked utility.
Part of ongoing work on attention-level prompt-injection defenses at Imperial College London (CPG).
- Downloads last month
- 15
Model tree for imperial-cpg/gpt-oss-20b-secalign-lr1e-4-1ep
Base model
openai/gpt-oss-20b