| # Handoff: Automatic Layer Selection for Hallucination Detection |
|
|
| Last updated: 2026-07-20 17:06 UTC |
|
|
| Paper: **Automatic Layer Selection for Hallucination Detection** |
| arXiv: [2605.26366](https://huggingface.co/papers/2605.26366) |
| OpenReview: [srAuLCB3Ca](https://openreview.net/forum?id=srAuLCB3Ca) |
|
|
| ## Read this first |
|
|
| **An exact reproduction of the paper is virtually impossible from the released |
| artifacts.** The authors did not release the generated `best_answer` records, |
| the ten uncertainty candidates per input, judge decisions/labels, exact model |
| and dataset snapshots, dependency lock, selected layers, trained probe states, |
| or raw results. The released `method/ID_twonn.py` computes a TwoNN curve but |
| does not implement the paper's FEPoID peak selector. In addition, the paper says |
| "exact string match" while the released labeling code uses substring |
| containment. Any result produced here is therefore a pinned **independent, |
| scaled replication**, not a regeneration of the authors' exact AUROCs. |
|
|
| The current experimental scope is 1,000 flattened CoQA training examples and |
| 1,000 flattened validation examples for Llama. The paper uses 10,000 training |
| examples, the full 7,983-example CoQA test set, and averages five QA datasets. |
| Do not describe the current run as verification of the paper's five-dataset |
| Table 2 mean. |
|
|
| ## Persistent assets |
|
|
| - Llama A100 Job (active at handoff): |
| <https://huggingface.co/jobs/GwendalTsang/6a5e54a9d09dc1f57c6bd8f8> |
| - Llama hidden-state/result bucket: |
| <https://huggingface.co/buckets/GwendalTsang/fepoid-llama-hidden-states> |
| - Mistral TPU v5e-8 extractor repository: |
| <https://github.com/GwenTsang/mistral-tpu8-hidden-states> |
| - Mistral one-core verification artifact: |
| <https://huggingface.co/datasets/GwendalTsang/mistral-7b-hidden-states-tpu-verification> |
| - **Mistral TPU v5e-8 hidden-state bucket (add after the full repository run):** |
| `<PASTE_HF_BUCKET_URL_HERE>` |
| - Canonical reproduction logbook target (not yet published): |
| <https://huggingface.co/spaces/GwendalTsang/repro-automatic-layer-selection-for-hallucination-detection> |
| - Public handoff bundle (created after this file was written): |
| <https://huggingface.co/datasets/GwendalTsang/automatic-layer-selection-reproduction-bundle> |
| - Public handoff snapshot bucket: |
| <https://huggingface.co/buckets/GwendalTsang/automatic-layer-selection-reproduction-handoff> |
|
|
| ## Current live Llama run |
|
|
| Job ID: `GwendalTsang/6a5e54a9d09dc1f57c6bd8f8` |
| Job name: `fepoid-llama-coqa-2k-v3` |
| Hardware: one A100 80 GB (`a100-large`, $2.50/hour) |
| Hard timeout: 110 minutes (maximum substantive-run charge about $4.59) |
| Docker image: `pytorch/pytorch:2.7.1-cuda12.8-cudnn9-runtime` |
|
|
| At the snapshot time, the job was `RUNNING`. Both Llama answer-generation |
| splits had completed: 1,000 train + 1,000 validation examples in 162.49 seconds. |
| The job was downloading/loading the pinned Ministral judge. It is remote and |
| will continue after the current TPU session is terminated. |
|
|
| Monitor it with: |
|
|
| ```bash |
| hf jobs inspect GwendalTsang/6a5e54a9d09dc1f57c6bd8f8 --format json |
| hf jobs logs GwendalTsang/6a5e54a9d09dc1f57c6bd8f8 --tail 200 |
| hf jobs wait GwendalTsang/6a5e54a9d09dc1f57c6bd8f8 --timeout 30s --format json |
| ``` |
|
|
| The first two launch attempts are useful negative provenance, not successful |
| experiments: |
|
|
| - `6a5e5423d09dc1f57c6bd8f0`: inline `bash -lc` was parsed incorrectly; exit 127 |
| before inference. |
| - `6a5e545dd09dc1f57c6bd8f4`: launcher worked but `scikit-dimension` had an |
| undeclared Matplotlib import; failed before model loading. The pinned |
| dependency was added before v3. |
|
|
| The Jobs canary succeeded: |
| <https://huggingface.co/jobs/GwendalTsang/6a5e5324d09dc1f57c6bd897>. |
|
|
| ### Pinned inputs |
|
|
| - Model: `meta-llama/Llama-3.1-8B-Instruct` |
| - Model revision: `0e9e39f249a16976918f6564b8830bc894c89659` |
| - Judge: `mistralai/Ministral-8B-Instruct-2410` |
| - Judge revision: `2f494a194c5b980dfb9772cb92d26cbb671fce5a` |
| - Dataset: `stanfordnlp/coqa` |
| - Dataset revision: `0d9e9952f1ef6e5415492d3d84b5873259137e3c` |
| - Generation: seed 2024, temperature 0.1, 30-token cap |
| - FEPoID forward horizon: `w=7` |
| - The ten temperature-1 uncertainty candidates are intentionally omitted |
| because FEPoID itself does not consume them. |
|
|
| ### Expected persisted output |
|
|
| Bucket prefix: `coqa-2k-llama-20260720/` |
|
|
| - `environment.json` |
| - `prepared/*.jsonl`: generated answers, FST answers, labels, judge outputs, |
| model/dataset revisions, and source indices |
| - `hidden_states/llama/{full,fst}/{train,validation}/manifest.json` |
| - 16 SafeTensors shards in total: four views/splits times four 250-record shards |
| - Every shard contains: |
| - `hidden_states`: BF16 `[records, 32, 4096]` |
| - `labels`: int64 `[records]` |
| - `record_indices`: int64 `[records]` |
| - `metrics/llama_{full,fst}_layers.csv` |
| - `metrics/llama_{full,fst}_summary.json` |
| - `gpu_stage_summary.json` |
| - `SUCCESS` |
|
|
| Layer semantics match Transformers `output.hidden_states[1:]`: layers 0–30 are |
| post-block/pre-final-RMSNorm representations and layer 31 is post-final-block, |
| post-final-RMSNorm. Inputs are left padded; index `-1` is the last non-padding |
| token. `use_cache=False` is used for extraction. Full and FST answers are |
| retokenized using the paper release's prompt-plus-answer construction. |
|
|
| ## Verify the Llama artifact after completion |
|
|
| Do not treat `COMPLETED` alone as proof. Check the bucket and the success marker: |
|
|
| ```bash |
| hf buckets list GwendalTsang/fepoid-llama-hidden-states \ |
| --recursive --human-readable --format json |
| |
| mkdir -p outputs/llama-coqa-2k |
| hf buckets sync \ |
| hf://buckets/GwendalTsang/fepoid-llama-hidden-states/coqa-2k-llama-20260720 \ |
| outputs/llama-coqa-2k |
| |
| test -f outputs/llama-coqa-2k/SUCCESS |
| find outputs/llama-coqa-2k/hidden_states -name '*.safetensors' | wc -l |
| ``` |
|
|
| The shard count should be 16. Validate every manifest's record count, shape, |
| dtype, and SHA-256 against the downloaded shard. Also ensure every prepared |
| split has 1,000 rows and both labels are present in train and validation before |
| trusting AUROC. If the job fails after exporting some shards, do not mix partial |
| and rerun output under the same prefix; change the prefix in |
| `scripts/run_llama_hf_job.sh` and relaunch. |
|
|
| ## Local workspace layout |
|
|
| - `/content/main.tex`, `/content/sections/`, `/content/tables/`: extracted paper |
| source used for the audit. |
| - `/content/paper-code/`: authors' repository at commit `def3cb6`. |
| - `/content/repro_automatic-layer-selection-for-hallucination-detection/`: |
| scaled independent reproduction bundle. |
| - `/content/.trackio/logbook/`: canonical five-claim Trackio logbook scaffold. |
| - `/content/mistral-tpu8-hidden-states/`: published eight-device TPU extractor, |
| clean at commit `10cc151` on `main`. |
|
|
| Important reproduction files: |
|
|
| - `configs/scaled_coqa.json`: pinned revisions, scale, and limitations. |
| - `scripts/hybrid_gpu_stage.py`: Llama generation, judging, BF16 extraction, |
| sharding, TwoNN/FEPoID, and MLP probes. It now supports `--models llama` |
| without loading Mistral. |
| - `scripts/run_llama_hf_job.sh`: exact dependency lock and v3 Job command. |
| - `scripts/repro_common.py`: reconstructed FEPoID, FST scanner, TwoNN, probes. |
| - `scripts/analyze_mistral_tpu.py`: consumes provided TPU Mistral artifacts. |
|
|
| Local checks completed: |
|
|
| - Python compilation passed for all three Python scripts. |
| - `hybrid_gpu_stage.py --self-test` passed. |
| - A SafeTensors round trip confirmed BF16 `[N,32,4096]` export and sharding. |
| - The Mistral TPU repository has 5 passing unit tests and a successful GitHub |
| Actions run: |
| <https://github.com/GwenTsang/mistral-tpu8-hidden-states/actions/runs/29761410557>. |
| - A real one-core TPU v5e Mistral smoke test passed. Eight-device orchestration |
| was not available in the original session, so the extractor enforces |
| `--expected-world-size 8` to prevent silent underuse. |
|
|
| ## Mistral handoff contract |
|
|
| The user explicitly said they will provide the Mistral hidden states later. |
| **Do not spend GPU/TPU money regenerating Mistral unless the user changes that |
| instruction.** Ask for or locate the provided Mistral output, then validate it. |
|
|
| Preferred Mistral shape is BF16 `hidden_states=[N,32,4096]` plus JSONL metadata |
| with stable record order and labels for full/FST views. The published extractor |
| also saves `embedding=[N,4096]`; the analysis does not require the embedding. |
| Run its validator first, then adapt/execute: |
|
|
| ```bash |
| python /content/mistral-tpu8-hidden-states/validate_output.py /path/to/mistral-output |
| python scripts/analyze_mistral_tpu.py --help |
| ``` |
|
|
| Never compare Llama and Mistral AUROC unless they use the same flattened CoQA |
| indices, split definitions, prompt format, generated-answer policy, correctness |
| labeling policy, FST rule, probe split, and layer indexing. |
|
|
| ## Remaining work, in order |
|
|
| 1. Monitor v3 to a terminal state and perform the artifact audit above. |
| 2. Download only small summaries/manifests first; record wall time, estimated |
| cost, label balance, selected layers, full/FST AUROCs, last-layer AUROCs, and |
| oracle AUROCs in the logbook. |
| 3. Add a validator for all Llama manifests/shards if the current Job succeeds. |
| 4. When the user supplies Mistral activations, validate and analyze them with |
| the same split/probe conventions. Do not regenerate Mistral by default. |
| 5. Populate Trackio claim pages: |
| - Claim 1: Llama layer-wise AUROC curve and whether its maximum is |
| intermediate. |
| - Claim 2: scaled CoQA FEPoID versus last/max-ID/oracle; clearly state that |
| five-dataset means 0.7253/0.8531 were not reproduced. |
| - Claim 3: not empirically tested yet; a summarization run is still needed |
| for substantive verification. |
| - Claim 4: time the reconstructed selector separately from activation |
| extraction and probes; the paper's 10.14-second cross-benchmark mean cannot |
| be regenerated from author artifacts. |
| - Claim 5: compare the same records under full versus FST and report paired |
| AUROC changes. |
| 6. Build the required Chenruishuo/posterly poster with `--strict-polish`, add |
| `poster_embed.html` to Executive summary, and pin it below the summary. |
| 7. Register the dedicated reproduction folder as the Conclusion artifact. |
| 8. Validate and publish: |
| |
| ```bash |
| curl -sL https://huggingface.co/spaces/ICML-2026-agent-repro/challenge/raw/main/scripts/validate_icml_logbook.py | \ |
| python3 - --space GwendalTsang/repro-automatic-layer-selection-for-hallucination-detection |
| |
| trackio logbook publish \ |
| GwendalTsang/repro-automatic-layer-selection-for-hallucination-detection |
| ``` |
|
|
| The logbook is only a scaffold at handoff; it has **not** been validated or |
| published. Its Executive summary must prominently repeat that exact |
| reproduction is virtually impossible and distinguish the scaled independent |
| replication from the paper's full experiment. |
|
|