File size: 21,796 Bytes
c950b9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
516f313
c950b9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
516f313
c950b9e
516f313
 
c950b9e
 
 
516f313
c950b9e
516f313
c950b9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
---
language:
- en
tags:
- llm-routing
- mixture-of-experts
- calibration
- confidence-estimation
- logit-signals
---

<div align="center">

# 🧭 ScoutRoute

### Can a single forward pass tell you which LLM should answer?

*Logit-based competence routing: testing whether internal signals from small open-weight models predict expert competence, without RouterBench, verbal self-assessment, or sampling.*

[![arXiv](https://img.shields.io/badge/arXiv-2610.23443-B31B1B?style=flat-square&logo=arxiv&logoColor=white)](https://arxiv.org/abs/2610.23443)
[![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-3776AB?style=flat-square&logo=python&logoColor=white)](https://www.python.org/)
[![License: MIT](https://img.shields.io/badge/license-MIT-green?style=flat-square)](#license)
[![Models](https://img.shields.io/badge/models-5%20open--weight-8A2BE2?style=flat-square&logo=huggingface&logoColor=white)](#models)
[![Domains](https://img.shields.io/badge/domains-4%20benchmarks-orange?style=flat-square)](#datasets)
[![GPU](https://img.shields.io/badge/GPU-T4%20%7C%20~10hrs-76B900?style=flat-square&logo=nvidia&logoColor=white)](#estimated-compute-budget)

</div>

---

## πŸ“Œ TL;DR

> A **single cheap forward pass** through a small generalist scout model (`phi3_mini`), read through a trained logistic-regression probe on its hidden states, **matches β€” and slightly beats β€” a full 5-model ensemble**, at **β…• the inference cost**.

| | Passes required | Accuracy | Gap to oracle |
|---|:---:|:---:|:---:|
| Random routing | 0 | 0.355 | βˆ’0.472 |
| Best single signal (log-prob) | 5 | 0.650 | βˆ’0.177 |
| Domain-aware ensemble | 5 | 0.678 | βˆ’0.149 |
| **Cheap router β€” `phi3_mini` scout** | **1** | **0.684** ⭐ | **βˆ’0.143** |
| Oracle (offline upper bound) | 5 | 0.827 | 0.000 |

πŸ“„ Full write-up, per-domain breakdowns, and calibration analysis: **[arXiv:2610.23443](https://arxiv.org/abs/2610.23443)**.

πŸ“¦ Phase 1 data is also published as a dataset: **[Raj-deep/scoutroute-phase1-calibration](https://huggingface.co/datasets/Raj-deep/scoutroute-phase1-calibration)**.

---

## πŸ—ΊοΈ Table of contents

- [Motivation](#-motivation)
- [Models](#models)
- [Datasets](#datasets)
- [Routing signals](#-routing-signals)
- [Key findings](#-key-findings)
- [Project structure](#project-structure)
- [Setup & usage](#-setup--usage)
- [Running on Kaggle](#-running-on-kaggle-recommended)
- [Output files](#output-files-explained)
- [VRAM requirements](#vram-requirements-fp16)
- [Troubleshooting](#-troubleshooting)
- [Compute budget](#estimated-compute-budget)
- [Phase 1: earlier calibration study](#-phase-1-earlier-calibration-study)
- [Citation](#-citation)
- [License](#license)

---

## 🎯 Motivation

Routing between multiple LLMs usually means one of three things: an external benchmark like RouterBench, asking the model to self-report confidence in words, or sampling many completions and voting. All three are expensive, indirect, or both.

This project asks a narrower question: **do the numbers already sitting inside a model's forward pass β€” its logits and hidden states β€” carry enough signal to predict which expert will get a prompt right?** No extra sampling. No self-report. Just what a single pass already computes.

Five small (≀3.8B) open-weight models were pooled β€” three generalists, two domain specialists β€” and tested across four benchmark domains chosen specifically to surface real specialist-vs-generalist contrast, rather than a benchmark where every model performs identically.

---

## Models

| Key | HuggingFace ID | Size | Role |
|---|---|:---:|---|
| `qwen25_1b` | `Qwen/Qwen2.5-1.5B-Instruct` | 1.5B | πŸ”΅ General |
| `qwen25_3b` | `Qwen/Qwen2.5-3B-Instruct` | 3B | πŸ”΅ General |
| `phi3_mini` | `microsoft/Phi-3-mini-4k-instruct` | 3.8B | πŸ”΅ General (strong for size) |
| `qwen25_math` | `Qwen/Qwen2.5-Math-1.5B-Instruct` | 1.5B | 🟣 Math specialist |
| `qwen25_coder` | `Qwen/Qwen2.5-Coder-1.5B-Instruct` | 1.5B | 🟣 Code specialist |

All five are loaded in **fp16** β€” not 4-bit. At this parameter scale, quantization overhead isn't worth it; fp16 runs faster on a T4.

> **⚠️ Phi-3 quirk:** loaded with `trust_remote_code=False`. Its remote modeling code throws a `rope_scaling` `KeyError` on some `transformers` versions. Disabling remote code sidesteps it entirely, since Phi-3's architecture is natively supported.

---

## Datasets

Four domains, loaded directly from HuggingFace with clean ground-truth answer keys β€” no RouterBench, no reference-answer extraction hacks.

| Domain | Source | n | Why this domain |
|---|---|:---:|---|
| **GSM8K** | `gsm8k` (`main`, test) | 100 | **Harder half only** β€” a stratified sample from the back half of the test split. `qwen25_math` scores near 100% on easy GSM8K, leaving no negative examples for probe training; harder problems restore correctness variance. |
| **HumanEval** | `openai_humaneval` (test) | 164 (all) | Code execution scoring via a subprocess sandbox. `qwen25_coder` expected to dominate. |
| **MMLU** | `cais/mmlu` (6 subjects) | 100 | Six deliberately diverse subjects (abstract algebra, college physics, college CS, HS world history, clinical knowledge, professional law) rather than a random sample across all 57 β€” avoids wasting compute on subjects with uniform difficulty. |
| **CommonsenseQA** | `tau/commonsense_qa` (validation) | 100 | No specialist advantage β€” the baseline domain, testing whether routing degrades gracefully when no expert has a domain edge. |

**Total: ~464 prompts Γ— 5 models β‰ˆ 2,320 (prompt, expert) pairs.**

<details>
<summary>πŸ”Ž Why the <code>validation</code> split for CommonsenseQA?</summary>
<br>
CommonsenseQA's actual <code>test</code> split has withheld answer keys (reserved for a public leaderboard) β€” only <code>train</code> and <code>validation</code> have <code>answerKey</code> populated. The loader correctly uses <code>validation</code>.
</details>

<details>
<summary>πŸ”Ž Why the harder half of GSM8K?</summary>
<br>
Class imbalance kills probe training. If <code>qwen25_math</code> gets ~95% of easy GSM8K problems right, a probe trained on that data has almost no negative examples to learn from and just predicts "always correct." Taking the harder half (the later portion of the test split, which trends toward more reasoning steps) restores real variance.
</details>

---

## πŸ”¬ Routing signals

Three signals, all extracted from model internals during a **single forward pass** β€” no sampling, no self-report.

| Signal | Feature | How it's extracted | Training needed? |
|---|:---:|---|:---:|
| `mean_log_prob` | A | Average log-probability of generated answer tokens | ❌ |
| `neg_entropy` | B | Negated entropy of the first-token distribution | ❌ |
| `probe_score` | C | Logistic regression probe on the last-layer hidden state | βœ… (30% of prompts) |

**Baselines:** random routing Β· oracle (best expert, offline upper bound)

---

## πŸ† Key findings

<table>
<tr><td>βœ…</td><td><b>One pass matches five.</b> A single <code>phi3_mini</code> forward pass (0.684) beats the full domain-aware 5-model ensemble (0.678). The cheap router isn't an approximation of the expensive method β€” it's competitive with it.</td></tr>
<tr><td>βœ…</td><td><b>Scout quality tracks generality, not size.</b> Ranking: <code>phi3_mini</code> β€Ί <code>qwen25_1b</code> β€Ί <code>qwen25_3b</code> β€Ί <code>qwen25_coder</code> β€Ί <code>qwen25_math</code>. The two specialists are the weakest scouts β€” their narrow internal representations don't transfer across model families.</td></tr>
<tr><td>βœ…</td><td><b>Signals have complementary blind spots.</b> The trained probe wins on specialist domains (GSM8K, HumanEval); raw log-prob wins on generalist domains (CommonsenseQA, MMLU). Routing by domain recovers <b>+2.8 points</b> over the single best signal.</td></tr>
<tr><td>βœ…</td><td><b>Calibration enables defection thresholds.</b> Probe ECE of 0.13–0.24 vs. 0.32–0.47 for logit signals β€” a 3–4Γ— improvement. That reliability made a "don't switch experts on a low-confidence margin" rule viable, recovering <b>+4.4 points</b> on HumanEval (0.530 β†’ 0.574).</td></tr>
<tr><td>⚠️</td><td><b>The MMLU gap is structural, not algorithmic.</b> Best score there is 0.574 vs. an oracle of 0.882 β€” a 31-point gap. No specialist model exists for this domain in the pool, so no routing logic can close it. Only a new MMLU-capable model would.</td></tr>
<tr><td>⚠️</td><td><b>The probe can still misfire.</b> On HumanEval, it correctly detected specialist uncertainty but defected to generalists that did even worse on hard code problems β€” accuracy dropped to 15.6% before the defection threshold fix.</td></tr>
</table>

---

## Project structure

```
ScoutRoute/
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ .gitignore
β”‚
β”œβ”€β”€ src/                                 # the pipeline β€” run in numeric order, from the repo root
β”‚   β”œβ”€β”€ collect_data_helpers.py          #   shared: model loading, scoring, prompt formatting
β”‚   β”œβ”€β”€ 01_collect_data.py               #   Step 1  run inference, extract logit features
β”‚   β”œβ”€β”€ 02a_train_probes.py              #   Step 2a train probes (baseline: full cross-domain pool)
β”‚   β”œβ”€β”€ 02b_train_probes_specialist.py   #   Step 2b train probes (specialists trained in-domain only)
β”‚   β”œβ”€β”€ 03_domain_aware_router.py        #   Step 3  choose the routing signal per domain
β”‚   └── 04_cheap_router.py               #   Step 4  single-pass scout router (ScoutRoute)
β”‚
β”œβ”€β”€ notebooks/
β”‚   └── run_experiment.ipynb             # Kaggle / Colab runner for Steps 1–4
β”‚
β”œβ”€β”€ phase1/                              # earlier calibration study (see below)
β”‚   β”œβ”€β”€ notebooks/
β”‚   β”œβ”€β”€ data/
β”‚   └── results/
β”‚
β”‚   # ── auto-created by the scripts when you run them (git-ignored) ──
β”œβ”€β”€ checkpoints/                         # JSONL, one row per completed prompt. Safe to restart.
β”‚   └── {model}_progress.jsonl
β”œβ”€β”€ hidden_states/                       # compressed numpy arrays, shape (N, hidden_dim)
β”‚   └── {model}_hidden.npz
β”œβ”€β”€ results/                             # final output tables
β”œβ”€β”€ trained_models/                      # saved probe artifacts (PCA + LogisticRegression)
β”œβ”€β”€ plots/                               # reliability diagrams (PNG)
└── logs/                                # per-model run logs
```

> **2a vs 2b.** `02b` is `02a` plus one change: the `qwen25_math` and `qwen25_coder` probes train only on their own domain (GSM8K / HumanEval), which fixes a class-imbalance problem (see `SPECIALIST_DOMAINS` in the script). Both write to the same files in `results/` and `trained_models/`, so **run one or the other**, not both.

---

## πŸš€ Setup & usage

All commands run from the repo root.

### Install

```bash
pip install -r requirements.txt
```

### Step 1 β€” collect inference data

Runs each model on all four domains and saves three logit features per (prompt, model) pair. **Resumable** β€” safe to re-run after a crash; already-completed prompts are skipped.

```bash
# One model (recommended β€” one per Kaggle session)
python src/01_collect_data.py --model qwen25_1b

# Smoke test β€” small subset only
python src/01_collect_data.py --model qwen25_1b --max_prompts 50

# All models sequentially (local machine with enough GPU memory)
python src/01_collect_data.py
```

Recommended order (smallest/fastest first, to validate the pipeline early):

```
Session 1:  --model qwen25_1b      (1.5B)
Session 2:  --model qwen25_math    (1.5B)
Session 3:  --model qwen25_coder   (1.5B)
Session 4:  --model qwen25_3b      (3B)
Session 5:  --model phi3_mini      (3.8B)
```

### Step 2 β€” train probes and evaluate routing

Run after **all** models have finished Step 1.

```bash
python src/02a_train_probes.py                 # baseline
# or
python src/02b_train_probes_specialist.py      # specialists trained in-domain only
```

To preview Features A and B before the probes are ready (e.g. after only one or two models have finished):

```bash
python src/02a_train_probes.py --skip_probe
```

### Step 3 β€” domain-aware router

Uses the probe score on specialist domains and mean log-prob on generalist domains. Needs the probes from Step 2.

```bash
python src/03_domain_aware_router.py                       # realistic: a text classifier predicts the domain
python src/03_domain_aware_router.py --domain_mode label   # upper bound: ground-truth domain labels
```

### Step 4 β€” cheap single-pass router (ScoutRoute)

One scout model runs per prompt; cross-model probes on its hidden state predict every expert's competence.

```bash
python src/04_cheap_router.py --scout phi3_mini   # the scout behind the headline result above
python src/04_cheap_router.py                     # script default scout: qwen25_1b
python src/04_cheap_router.py --sweep_scouts      # try every model as the scout
```

---

## ☁️ Running on Kaggle (recommended)

Kaggle gives 30 free GPU-hours/week with 9-hour session limits. The checkpoint system handles interruptions β€” restarting picks up exactly where it stopped, at the level of individual prompts. `notebooks/run_experiment.ipynb` wraps all of this.

### First session

1. New Notebook β†’ Settings β†’ Accelerator: **GPU T4 x1** β†’ Internet: **On**
2. Get the code in: upload `src/` and `requirements.txt` as a Kaggle Dataset, or better, clone from a private GitHub repo (see below)
3. `!pip install -q -r requirements.txt`
4. `!python src/01_collect_data.py --model qwen25_1b`
5. **Before the session ends:** save `checkpoints/`, `hidden_states/`, and `results/` as Kaggle Output Datasets (see below)

### Subsequent sessions

1. Add your saved checkpoint Datasets as input
2. Restore them into the working directory
3. Run the next model

<details>
<summary>πŸ’‘ Using GitHub instead of re-uploading scripts each time</summary>

```python
# Get the code at the start of every session
import os, subprocess
HF_USER = "Raj-deep"   
REPO = f"https://huggingface.co/{HF_USER}/ScoutRoute"
PROJECT_DIR = "/kaggle/working/project"

if os.path.exists(f"{PROJECT_DIR}/.git"):
    subprocess.run(["git", "-C", PROJECT_DIR, "pull"], check=True)
else:
    subprocess.run(["git", "clone", REPO, PROJECT_DIR], check=True)
os.chdir(PROJECT_DIR)
```

Code lives on GitHub, data lives on Kaggle Datasets β€” a clean separation. Push a fix β†’ next session's `git pull` picks it up automatically.
</details>

<details>
<summary>πŸ’Ύ Saving checkpoints on Kaggle</summary>

**Why this matters:** `/kaggle/working` is wiped when a session ends. Without saving, every session starts from zero.

**At the end of a session:**

```python
import shutil
from pathlib import Path

for subfolder, output_name in [
    ("checkpoints",   "routerbench_checkpoints"),
    ("hidden_states", "routerbench_hidden_states"),
    ("results",       "routerbench_results"),
]:
    src = f"{PROJECT_DIR}/{subfolder}"
    dst = f"/kaggle/working/{output_name}"
    if Path(src).exists():
        shutil.copytree(src, dst, dirs_exist_ok=True)
        print(f"Copied {subfolder} β†’ {dst}")
```

Then in the Kaggle UI: **Output tab** β†’ click each folder β†’ **Save as Dataset** β†’ name it exactly as printed (e.g. `routerbench-checkpoints`) β†’ set **Private** β†’ Create.

**At the start of the next session:**

1. **+ Add Data** β†’ **Your Datasets** β†’ add `routerbench-checkpoints`, `routerbench-hidden-states`, `routerbench-results`
2. Restore them:

```python
import shutil
from pathlib import Path

for dataset_name, subfolder in [
    ("routerbench-checkpoints",   "checkpoints"),
    ("routerbench-hidden-states", "hidden_states"),
    ("routerbench-results",       "results"),
]:
    src = f"/kaggle/input/{dataset_name}"
    dst = f"{PROJECT_DIR}/{subfolder}"
    if Path(src).exists():
        shutil.copytree(src, dst, dirs_exist_ok=True)
        print(f"Restored {dataset_name}")
    else:
        print(f"Not found: {dataset_name} (first session, or different name)")
```

3. Re-run `src/01_collect_data.py --model <next_model>` β€” completed prompts from prior sessions are skipped automatically; the run continues where it left off, even mid-model if a session died partway through.
</details>

<details>
<summary>πŸ“Š Checking progress without re-running inference</summary>

```python
from pathlib import Path
for f in sorted(Path(f"{PROJECT_DIR}/checkpoints").glob("*_progress.jsonl")):
    n = sum(1 for _ in open(f))
    print(f"{f.stem.replace('_progress',''):<18} {n:>4} rows")
```
</details>

---

## Output files explained

| File | Produced by | Contents |
|---|:---:|---|
| `results/{model}_results.parquet` | 01 | One row per (prompt, model): `prompt_id`, `eval_name`, `dataset`, `answer_key`, `response`, `is_correct`, `mean_log_prob`, `first_tok_entropy` |
| `hidden_states/{model}_hidden.npz` | 01 | Arrays: `prompt_ids` (N,) and `vectors` (N, hidden_dim) |
| `results/routing_results.csv` | 02 | Accuracy for each routing signal + baselines |
| `results/ece_results.csv` | 02 | ECE per model per signal |
| `results/per_dataset_routing.csv` | 02 | Routing accuracy broken down by domain |
| `results/probe_metrics.csv` | 02 | AUROC, n_train, PCA dims per model probe (02b adds `domain_filter`) |
| `plots/reliability_*.png` | 02 | Reliability diagrams (predicted signal vs. actual accuracy) |
| `trained_models/{model}_probe.pkl` | 02 | Saved PCA + LogisticRegression probe (joblib) |
| `results/domain_aware_routing.csv` | 03 | Full domain-aware comparison table |
| `results/domain_classifier.csv` | 03 | Domain classifier accuracy (`predict` mode) |
| `trained_models/domain_clf.pkl` | 03 | Saved TF-IDF domain classifier (`predict` mode) |
| `results/cheap_router_results.csv` | 04 | Full cheap-router comparison table |
| `results/cheap_probe_metrics.csv` | 04 | AUROC per (scout β†’ target) probe |
| `trained_models/cheap_probes/` | 04 | Saved cross-model probes, one per target expert |

---

## VRAM requirements (fp16)

| Model | Params | VRAM |
|---|:---:|:---:|
| `qwen25_1b`, `qwen25_math`, `qwen25_coder` | 1.5B | ~3 GB |
| `qwen25_3b` | 3B | ~6 GB |
| `phi3_mini` | 3.8B | ~8 GB |

A T4 (16 GB) handles all five models comfortably in fp16.

---

## πŸ› οΈ Troubleshooting

<details>
<summary><b>"No *_results.parquet found"</b></summary>
<br>
Step 1 hasn't completed for any model. Run <code>src/01_collect_data.py</code> first.
</details>

<details>
<summary><b>Phi-3 fails to load / <code>rope_scaling</code> KeyError</b></summary>
<br>
Already handled β€” <code>TRUST_REMOTE_CODE["phi3_mini"] = False</code> in <code>src/01_collect_data.py</code>. If you see this error anyway, check your <code>transformers</code> version is recent (<code>pip install -U transformers</code>).
</details>

<details>
<summary><b>Phi-3 appears stuck / inference is extremely slow</b></summary>
<br>
Check it actually loaded on GPU, not CPU. <code>device_map={"": 0}</code> is used explicitly (not <code>"auto"</code>) because <code>"auto"</code> has been observed silently placing Phi-3 on CPU on some setups.
</details>

<details>
<summary><b>HumanEval scores look too low</b></summary>
<br>
Check <code>max_new_tokens</code> β€” code solutions need more room than other domains. This is already handled (<code>run_inference</code> bumps to 256 tokens for <code>dataset="humaneval"</code> automatically), but if you've modified the script, confirm that bump is still in place.
</details>

<details>
<summary><b>"Too few training samples β€” probe skipped"</b></summary>
<br>
That model's training split (30% of ~464 prompts β‰ˆ 140, then split again 80/20 inside <code>train_probe</code>) has fewer than 30 examples β€” usually because Step 1 didn't fully complete for that model. Check <code>checkpoints/{model}_progress.jsonl</code> row count. With <code>02b</code>, the specialist probes train on in-domain prompts only, so their pools are smaller still.
</details>

<details>
<summary><b>Kaggle session killed mid-run</b></summary>
<br>
Restore checkpoints (see above), re-run the same <code>--model</code> command. The script reads the JSONL checkpoint, skips completed prompts, and continues.
</details>

---

## Estimated compute budget

| Model | Domain prompts | Approx. GPU time (T4, fp16) |
|---|:---:|:---:|
| `qwen25_1b` | 464 | ~1.5 hrs |
| `qwen25_math` | 464 | ~1.5 hrs |
| `qwen25_coder` | 464 | ~1.5 hrs |
| `qwen25_3b` | 464 | ~2.5 hrs |
| `phi3_mini` | 464 | ~3 hrs |
| **Total** | | **~10 GPU-hours** |

Comfortably fits in a single week on Kaggle's free 30 GPU-hour/week tier β€” likely achievable in 2–3 sessions.

---

## πŸ§ͺ Phase 1: earlier calibration study

[`phase1/`](phase1/README.md) holds the exploratory study that came before the pipeline above: it compared *verbalised* confidence against answer-token confidence across the same five experts, and prototyped routers and a cascade on top. It is kept for reference and reproducibility; the pivot away from verbal self-assessment is what led to the logit-based approach in this repo.

---

## πŸ“– Citation

If you use this work, please cite the paper:

```bibtex
@misc{pandhare2026scoutroute,
  title         = {ScoutRoute: Efficient Mixture-of-Experts Routing Using Internal Language Model Signals},
  author        = {Pandhare, Rajdeep and Bharucha, Delzaan},
  year          = {2026},
  eprint        = {2610.23443},
  archivePrefix = {arXiv},
  primaryClass  = {cs.AI},
  url           = {https://arxiv.org/abs/2610.23443}
}
```

---

## License

Released under the MIT License.

<div align="center">
<sub>Built with 5 small open-weight models, 4 benchmarks, and zero extra sampling.</sub>
</div>