Knowledge Sufficiency Detection — internal-representation-based hallucination
/ knowledge-sufficiency detection research codebase, rebuilt per the project
implementation plan (研究项目重建实施计划.md). Read that document first for
the research process (stages 0-6); this README covers the engineering side
only.
If anything below is ambiguous or you're not sure a step applies to your situation, STOP and ask before proceeding (project plan §2.1) — do not guess and continue.
Server: AutoDL, project directory /root/autodl-tmp/ksdetect.
Model: LLaMA-3.1-8B-Instruct, fixed local path
/autodl-fs/data/Llama-3.1-8B-Instruct (do not change without adding a new
entry to docs/decisions.md).
Connection: PyCharm SSH Remote Interpreter, pointed at the conda
environment created below (not a local venv, not the system/base conda env).
cd /root/autodl-tmp/ksdetect
conda env create -f environment.yml
conda activate ksdetectIf this is a re-run (environment already exists and you need to update it):
conda env update -f environment.yml --pruneIf torch==2.4.1 (CUDA 12.1 build) fails to install or fails at runtime
with a CUDA version mismatch: run nvidia-smi on the server, check the
CUDA version in the top-right corner, then find the matching torch wheel at
https://pytorch.org/get-started/previous-versions/ and install that
specific version instead — do NOT loosen the pin in environment.yml to a
version range (>=); replace it with the specific correct version and note
the change in docs/decisions.md.
- PyCharm → Settings → Project → Python Interpreter → Add Interpreter → On SSH.
- Enter the AutoDL SSH connection details (host/port/user — from the AutoDL instance page).
- When asked for the interpreter path, use the conda env's python:
/root/miniconda3/envs/ksdetect/bin/python(adjust the miniconda/ anaconda path prefix if your AutoDL image differs — check withwhich pythonafterconda activate ksdetect). - Set the remote project path to
/root/autodl-tmp/ksdetect, sync.
ls -la /autodl-fs/data/Llama-3.1-8B-InstructShould list the model's config/weight files. If this path doesn't exist or is empty, stop here and resolve that before running anything — every experiment config assumes this path is already correct and populated.
ksdetect/
├── core/ # STABLE LAYER — see rule below
│ ├── extraction/ # model loading, forward hooks, batch extraction
│ ├── labeling/ # correctness judgment, hard/soft label construction
│ ├── stats/ # nested CV, multi-seed pooling, CI, significance tests
│ └── viz/ # publication-grade plotting (English-only)
├── experiments/ # EXPLORATION LAYER — one folder per experiment
│ ├── _template/ # copy this to start a new experiment
│ └── exp_00_sanity_check/ # infrastructure validation, run this first
├── docs/
│ ├── known_issues.md # bug log — check before debugging something familiar
│ └── decisions.md # decisions that shouldn't be silently re-litigated
├── environment.yml
└── README.md # this file
Non-negotiable rule: any experiment script under experiments/ may
ONLY call into core/* for cross-validation, feature selection,
significance testing, labeling, model loading, hook registration, or
plotting. If you find yourself about to write a for loop implementing
CV, or a plotting call with a Chinese string in it, or a raw
model.forward() with manual hook code, STOP — that logic belongs in
core/, not in an experiment script. This is what prevents the same bug
from needing to be fixed in five different places later.
conda activate ksdetect
cd /root/autodl-tmp/ksdetect
# Part 1 — no GPU needed, run this first
python experiments/exp_00_sanity_check/run_stats_sanity_check.py
# Part 2 — needs the GPU + real model
python experiments/exp_00_sanity_check/run_extraction_smoke_test.pySee experiments/exp_00_sanity_check/README.md for what each check means
and what to send back for review. Do not proceed to any other experiment
until both parts report PASS.
conda activate ksdetect
cd /root/autodl-tmp/ksdetect
python experiments/exp_<name>/run.py --config experiments/exp_<name>/config.yamlEvery experiment writes:
experiments/exp_<name>/run_log.txt— full execution logexperiments/exp_<name>/results/summary.json— machine-readable resultsexperiments/exp_<name>/results/*.pdf— figures (English-only, per §4.5 of the project plan)
cp -r experiments/_template experiments/exp_YYYYMMDD_short_name- Fill in every
REPLACE_MEfield in the newconfig.yaml— the runner refuses to start if any are left in place. - Fill in the numbered
TODOsections inrun.py— these correspond to: dataset loading, model loading (viacore.extraction, don't reimplement), activation extraction + shard saving, label construction (viacore.labeling), statistics (viacore.stats), plotting (viacore.viz), and finally writingresults/summary.json+results/run_report.md. - Before running: re-read the config against whatever was most recently discussed/decided (project plan §2.1's "确认最新要求已经完整对齐") — a stale config that technically runs without error is still wrong.
- Run on a SMALL scale first (
n_examplesset to something small in config.yaml) before the full run (project plan §2.2). - Once the small run looks right, scale up. Before increasing batch size/concurrency, watch GPU memory / throughput on the small run first (project plan §2.2, concurrency caution).
After any run — successful, partially successful, or failed — send back:
- Experiment path, e.g.
experiments/exp_20260101_layer_scan/ - Config used (the file itself, or a diff if it's a small change from a previous run)
- Run status: counts of completed / still-running / errored / not-yet-run tasks. If anything errored: the error message AND whether it's been fixed + re-run yet (project plan §2.4 — don't just report the count, report what's being done about it)
- Core results: key numbers with their std/CI, not just point estimates
- Figure paths
- Anything new and unexpected, and whether it's been added to
docs/known_issues.md
If a result looks surprising (e.g. an unexpectedly high/low AUC, an unstable-looking curve), say so explicitly rather than only reporting the final number — an anomaly should be investigated as a process question first ("did something leak / did a fold get corrupted / is the sample size too small"), not immediately attributed to "randomness" or "model behavior" (project plan §2.4).
- Don't just note that it failed and move on — find out why.
- Check
docs/known_issues.mdfirst; the failure may already be documented with a known fix. - Once fixed: re-run whatever failed (don't leave gaps in a batch job),
and if it's a new failure mode, add an entry to
docs/known_issues.mdin the same format as the existing entries.
See docs/known_issues.md and docs/decisions.md. Skim both before
starting new work — they capture context that isn't repeated elsewhere.