File size: 8,262 Bytes
03d73e0
fabb099
 
 
 
 
 
03d73e0
 
fabb099
 
 
 
03d73e0
fabb099
 
 
 
 
 
b5c2de7
a25eba0
fabb099
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
---
base_model: thinkingmachines/Inkling-2-Mini
library_name: transformers
language:
- en
datasets:
- dehackangel/patchguard-inkling-data
tags:
- halo
- security
- grpo
- code-patching
- white-circle
---

# PatchGuard-Inkling (`dehackangel/patchguard-inkling-2-mini`)

**PatchGuard-Inkling** is a post-trained **26.4B** (`bfloat16`) Python security patching model fine-tuned from [`thinkingmachines/Inkling-2-Mini`](https://huggingface.co/thinkingmachines/Inkling-2-Mini) using the [Halo](https://github.com/whitecircle/halo) post-training framework for the **White Circle Halo Competition** (`ft-inkling` track).

- **Team Lead:** `@HackAngeldon` (`@dehackangel`)
- **Interactive Monochrome Report, 8-CWE Diff Explorer & Live Zero-Login Playground:** https://patchguard-research-atlas.lovable.app/#playground
- **Live Inference API (Scale-to-Zero Modal `1x B200` + White Circle + Nebius Plain-English Brief + Public GitHub AST Repo Triage):** https://hackangeldon--patchguard-live-api-fastapi-app.us-east.modal.run
- **Public Competition Repository (`work` branch):** https://github.com/HackAngeldon/halo/tree/work
- **Dataset & Redacted Agent Trajectories:** https://huggingface.co/datasets/dehackangel/patchguard-inkling-data
- **Public X Announcement:** https://x.com/dehackangel/status/2128134874376679787

![PatchGuard-Inkling Cross-Model Benchmark](assets/patchguard_cross_model_benchmark.png)

---

## Why PatchGuard-Inkling?

When code-repair models are optimized purely against unit tests via reinforcement learning, they learn **reward hacking**: taking lazy shortcuts (hardcoding outputs, catching broad exceptions, or blocking single exploit strings) that turn tests green while leaving the underlying vulnerability unfixed.

PatchGuard-Inkling combines **two-stage Halo post-training** on `1x NVIDIA B200`:
1. **Stage 1 — Supervised Fine-Tuning (LoRA SFT):** `24` steps (`151.7s`, loss `0.4394 -> 0.1813`, `184,743` unmasked tokens) on Firecrawl-grounded, execution-verified security patches across 8 CWE families (`sqli`, `path_traversal`, `cmd_injection`, `ssrf`, `idor_auth`, `unsafe_deser_eval`, `xss`, `crypto_secrets`), merged into `26,386,412,544` `bfloat16` parameters.
2. **Stage 2 — Anti-Shortcut Halo Offline GRPO (`dapo`, `kl_beta=0.05`):** Scored **`242/242`** rollouts & Nebius contrast pairs with both an isolated subprocess functional/exploit verifier and **12 live White Circle anti-shortcut policies** (`75` flagged, catching `32` test-passing shortcuts). `whitecircle/checkpoint-122` (`122` steps) was selected and merged for final release.

---

## Official 3-Seed Evaluation (`n=32` per split, `seeds=[42, 43, 44]`, `T=0.2`, `max_new_tokens=768`, `1x B200`)

| Split | Model | Clean Pass Rate | Exploit Pass | Functional Pass | Shortcut Rate ↓ | Mean Reward |
|---|---|---:|---:|---:|---:|---:|
| **`fresh` (unseen domain)** | `thinkingmachines/Inkling-2-Mini` (Base) | `41.66%` (±`0.0181`) | `44.44%` | `41.66%` | `53.12%` | `0.4166` |
| **`fresh` (unseen domain)** | **PatchGuard-Inkling (Final)** | **`91.67%`** (±`0.065`) | **`100.00%`** | **`96.36%`** | **`1.04%`** | **`0.9336`** |
| **`test` (held-out)** | `thinkingmachines/Inkling-2-Mini` (Base) | `38.54%` (±`0.065`) | `46.88%` | `41.67%` | `46.88%` | `0.4008` |
| **`test` (held-out)** | **PatchGuard-Inkling (Final)** | **`87.50%`** (±`0.0312`) | **`99.22%`** | **`96.35%`** | **`3.12%`** | **`0.9233`** |

- Eval runtime (`3` seeds × `2` splits on `1x B200`): Base `879.78s` vs. PatchGuard-Inkling `1260.07s`.
- Seed `43` peak on `fresh`: **`96.88%`** clean pass rate, **`0.00%`** shortcuts, **`75.00%`** on `unsafe_deser_eval`.

---

## Paired Offline GRPO Ablation (`Tests-Only` vs. `Tests + White Circle`)

| Experiment | Setting | `Tests-Only` Baseline | `Tests + White Circle` (Ours) |
|---|---|---:|---:|
| `test` Clean Pass Rate | `512` tokens, `n=32` | `71.88%` *(regressed)* | **`87.50%`** |
| `test` Shortcut Rate ↓ | `512` tokens, `n=32` | `12.50%` | **`3.12%`** |
| White Circle Live Judge Clean Rate | `512` tokens, `128/128` scored | `87.50%` | **`90.62%`** |
| Nebius Independent Judge Secure Rate | `512` tokens, `Qwen/Qwen3-30B-A3B-Instruct-2507` | `81.25%` | **`96.88%`** |
| Hardest CWE (`fresh` `unsafe_deser_eval`) | `768` tokens (`ckpt-60` vs. `ckpt-122`) | `0.00%` | **`50.00%`** |

---

## Cross-Model Security Benchmark (`fresh` & `test`, `n=32` per split, `T=0.2`)

Evaluated through the identical isolated subprocess functional/exploit harness and 12-policy White Circle verifier. *Base & PatchGuard-Inkling report 3-seed means (`768` tokens); external API peers report 1-seed `T=0.2` runs (`768` tokens for non-reasoning peers, `2048` tokens for reasoning peers).*

| Model | Protocol | `fresh` Clean Pass | `fresh` Exploit Pass | `fresh` Shortcut Rate ↓ | `test` Clean Pass | `test` Shortcut Rate ↓ |
|---|---|---:|---:|---:|---:|---:|
| **PatchGuard-Inkling (Ours, 26.4B)** | 3-seed mean, `768` tok | **91.67%** | **100.00%** | **1.04%** | **87.50%** | **3.12%** |
| `openai/gpt-4.1-mini` (OpenRouter) | 1-seed API, `768` tok | 75.00% | 84.38% | 0.00% | 87.50% | 0.00% |
| `Qwen/Qwen3-30B-A3B-Instruct-2507` (Nebius) | 1-seed API, `768` tok | 71.88% | 89.06% | 12.50% | 71.88% | 9.38% |
| `openai/gpt-oss-120b` (Nebius) | 1-seed API, `2048` tok | 65.62% | 83.33% | 6.25% | 81.25% | 0.00% |
| `thinkingmachines/Inkling-2-Small` (Nebius) | 1-seed API, `2048` tok | 56.25% | 57.29% | 37.50% *(9/32 empty)* | 46.88% | 50.00% *(10/32 empty)* |
| `google/gemma-3-27b-it` (Nebius) | 1-seed API, `768` tok | 53.12% | 80.21% | 12.50% | 40.62% | 15.62% |
| `thinkingmachines/Inkling-2-Mini` (Base 26.4B) | 3-seed mean, `768` tok | 41.66% | 44.44% | 53.12% | 38.54% | 46.88% |

---

## Quickstart & Reproduction

### Inference (`transformers`, `bfloat16`)

```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "dehackangel/patchguard-inkling-2-mini"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto",
)

messages = [
    {"role": "system", "content": "Return a secure structural Python patch without shortcuts."},
    {"role": "user", "content": "Fix SQL injection in:\ndef get_user(conn, name):\n    return conn.execute(f"SELECT * FROM users WHERE name = '{name}'").fetchall()"},
]
prompt = tokenizer.apply_chat_template(
    messages,
    add_generation_prompt=True,
    tokenize=False,
    reasoning_effort="none",
)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=768, temperature=0.2, do_sample=True)
print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
```

### Official Competition Evaluation Reproduction (`1x NVIDIA B200`, ~21 min)

```bash
git clone -b work https://github.com/HackAngeldon/halo.git
cd halo
python -m patchguard.eval.run_eval \
  --model dehackangel/patchguard-inkling-2-mini \
  --n 32 \
  --seeds 42 43 44 \
  --temperature 0.2 \
  --max-new-tokens 768 \
  --batch-size 16 \
  --reasoning-effort none \
  --output-dir eval_out
```

---

## Stack & Partner Platforms Used

- **Modal:** `1x B200` SFT (`24` steps), LoRA weight merges, rollout sampling, paired Offline GRPO ablation, and official 3-seed evaluations.
- **White Circle:** 12 custom security & anti-shortcut policies scoring `242/242` Offline GRPO rollouts and `128/128` held-out evaluation outputs.
- **Firecrawl:** `48` security grounding documents (`firecrawl_grounding.jsonl`).
- **Nebius Token Factory:** `Qwen/Qwen3-30B-A3B-Instruct-2507` shortcut-contrast generation and independent security judging.
- **OpenRouter:** `openai/gpt-4.1-mini` SFT synthesis and cross-model comparison.
- **Lovable:** Monochrome interactive writeup and 3-seed / 8-CWE verification dashboard.

## Limitations

Evaluated on a synthetic parametric benchmark of 8 single-module Python CWE families rather than full multi-file repository CVEs. Structural patch generation increases 3-seed evaluation runtime from `879.78s` (Base) to `1260.07s` (PatchGuard-Inkling), and `unsafe_deser_eval` remains the hardest category when format constraints require plain literal structures without type prefixes.