birgermoell's picture
Upload trace-loop-classifier (distilroberta-base) with ID & OOD benchmark card
4ab7986 verified
|
Raw History Blame Contribute Delete
6.02 kB
---
license: apache-2.0
base_model: distilroberta-base
datasets:
- open-thoughts/AgentTrove
- Agent-Ark/Toucan-1.5M
- openbmb/UltraData-SFT-Agent-2609
- jupyter-agent/jupyter-agent-dataset
- FineEnvs/SmolDataEnvs-sft
- jedisct1/security-audits
- SWE-bench/SWE-smith-trajectories
- Lego-X/LegoFlow-SWE
language:
- en
tags:
- text-classification
- agent-traces
- post-training
- sft-filter
- rl-rollouts
- renaissancelabs
library_name: transformers
---
# trace-loop-classifier
A fast, lightweight (82M-parameter `distilroberta-base`) binary classifier trained by [Renaissance Labs](https://renaissancelabs.eu) to detect **agent stall loops and semantic repetition** in multi-turn tool-calling and coding-agent trajectories — built to complement exact-match regex filters in SFT data curation and RL rollout monitoring (motivated by [Marin `#12264`](https://github.com/marin-community/marin/issues/12264)).
Labels:
- `0` (`clean`): normal multi-turn progress (including legitimate single-retry-then-succeed recoveries)
- `1` (`loop_or_stall`): consecutive stalls, argument-jittered retries, A-B-A-B oscillations, circular apology/plan-restate stalls, or doom-loop suffix repetition
---
## Benchmark results (vs. exact-match regex baselines)
Evaluated on both **in-distribution held-out trajectories** (`test_id`, 217 traces from 6 permissive sources) and **unseen-source OOD trajectories** (`test_ood`, 500 traces from `SWE-bench/SWE-smith-trajectories` and `Lego-X/LegoFlow-SWE`, never seen during training):
### In-distribution test (`test_id`, `n = 217`)
| Detector | F1 | Precision | Recall | Accuracy | AUROC | Latency |
|---|---:|---:|---:|---:|---:|---:|
| Regex: consecutive exact stall (`>=3x`) | `0.3762` | `1.0000` | `0.2317` | `0.7097` | `0.6159` | `<0.1 ms` |
| Regex: spread exact duplicate (`>=30%`) | `0.5487` | `1.0000` | `0.3780` | `0.7650` | `0.6890` | `<0.1 ms` |
| Regex: combined (`exact OR spread`) | `0.6102` | `1.0000` | `0.4390` | `0.7880` | `0.7195` | `<0.1 ms` |
| **`RenaissanceLabsEU/trace-loop-classifier`** | **`0.9487`** | **`1.0000`** | **`0.9024`** | **`0.9631`** | **`0.9587`** | **`17.7 ms/trace` (M5 MPS)** |
### Unseen-source OOD test (`test_ood`, `n = 500`: `SWE-smith` + `LegoFlow-SWE`)
| Detector | F1 | Precision | Recall | Accuracy | AUROC | Latency |
|---|---:|---:|---:|---:|---:|---:|
| Regex: consecutive exact stall (`>=3x`) | `0.4266` | `1.0000` | `0.2711` | `0.6720` | `0.6356` | `<0.1 ms` |
| Regex: spread exact duplicate (`>=30%`) | `0.0769` | `1.0000` | `0.0400` | `0.5680` | `0.5200` | `<0.1 ms` |
| Regex: combined (`exact OR spread`) | `0.4483` | `1.0000` | `0.2889` | `0.6800` | `0.6444` | `<0.1 ms` |
| **`RenaissanceLabsEU/trace-loop-classifier`** | **`0.9933`** | **`1.0000`** | **`0.9867`** | **`0.9940`** | **`0.9912`** | **`18.1 ms/trace` (M5 MPS)** |
### OOD breakdown by subtype (`test_ood`)
| Subtype | True label | Count | Accuracy |
|---|---:|---:|---:|
| `clean` (real unseen SWE traces) | `0` | `225` | `100.0%` |
| `hard_neg_single_retry` (1 retry → success) | `0` | `50` | `100.0%` |
| `exact_stall` (3–5× consecutive repeat) | `1` | `54` | `100.0%` |
| `jitter_retry` (argument/comment-tweaked retries) | `1` | `36` | `100.0%` |
| `ab_oscillation` (A-B-A-B cycle) | `1` | `42` | `100.0%` |
| `apology_stall` (circular plan-restate / apology) | `1` | `40` | `100.0%` |
| `doom_suffix` (repeated tail chunk) | `1` | `50` | `100.0%` |
| `real_loop` (natural spread-out repeats in 99-turn `LegoFlow-SWE` runs) | `1` | `3` | **`0.0%`** *(see Limits)* |
---
## Run Card
- **Base model:** `distilroberta-base` (82M params, Apache-2.0)
- **Splits:** `1,346` train / `209` val / `217` ID test (from 6 Apache-2.0 / MIT HF trace datasets: `AgentTrove`, `Toucan-1.5M`, `UltraData-SFT-Agent-2609`, `jupyter-agent-dataset`, `SmolDataEnvs-sft`, `security-audits`) + `500` unseen-source OOD test (`SWE-smith-trajectories`, `LegoFlow-SWE`).
- **Truncation:** `max_length=512`, `truncation_side="left"` (always preserves the tail of the trajectory where stalls occur).
- **Hyperparameters:** full fine-tune in fp32, `AdamW`, `lr=3e-5`, cosine warmup, `batch_size=8`, `grad_accum=2` (eff batch 16), `4` epochs, best checkpoint selected by validation F1 (`0.9867`, val AUROC `0.9999`).
- **Hardware & wall-clock:** Apple M5 (MPS), `429.5s` (~7 minutes total).
---
## Quick start
```python
from transformers import pipeline
clf = pipeline(
"text-classification",
model="RenaissanceLabsEU/trace-loop-classifier",
truncation=True,
max_length=512,
)
# Format trajectory as [ROLE] content lines (keep the tail for long runs)
trace = "[USER] Fix failing tests\n[ASSISTANT] Running pytest...\n[TOOL] Exit code 1\n..."
print(clf(trace))
```
---
## Honest limits & recommended usage
1. **512-token tail window misses early-episode spread-out repeats:** On the 3 natural `real_loop` traces in `test_ood` (`LegoFlow-SWE`, averaging ~99 turns), the repeated actions happened earlier than the final 512 tokens, so the model scored `0/3`. **Recommended production setup:** run this classifier **together with** a cheap whole-episode exact-duplicate counter (`spread_repeat >= 30%` OR `trace-loop-classifier >= 0.5`).
2. **Synthetic semantic-loop positives:** Because natural permissive trace datasets contain relatively few labeled semantic loops, the `jitter_retry`, `ab_oscillation`, `apology_stall`, and `doom_suffix` positives were injected onto real clean trajectories. Real-world semantic loops outside those templates should be audited before relying on this model as a sole gate.
3. **English-primary:** Trained on English-dominant coding and tool-calling traces.
## Links & license
- **Agentic Traces Audit & Shortlist:** [RenaissanceLabs-EU/datasets/agentic-traces](https://github.com/RenaissanceLabs-EU/datasets/blob/main/agentic-traces/SHORTLIST.md)
- **Open Agent Skills:** [skills.renaissancelabs.eu](https://skills.renaissancelabs.eu)
- **Lab:** [renaissancelabs.eu](https://renaissancelabs.eu)
- **License:** Apache 2.0.