Latium is an open-source research framework for re-implementing and evaluating ROME (Rank-One Model Editing), with tooling for structural edit detection, causal tracing, artifact-backed analysis, and graph rendering.
The project is developed for cybersecurity research by the Security@FIT group in
collaboration with Red Hat Research. An archived branch preserves the ACM CCS
2026 submission snapshot. The current code was refactored because the submission-era
script and notebook layout had outgrown the project; the current runtime is
Hydra-first and uses python3 -m src.
For contributor structure and extension points, see docs/project.md and the
package README files under src/.
- Matej Olexa
- Jakub Res
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
make mkdirModel configs default to CUDA. Model downloads are cached under ../models,
datasets under ../datasets, and second-moment statistics under
data/second_moment_stats/.
make setup is also available for the conda-based setup path; it creates the
llms environment and then runs the same directory setup as make mkdir.
ROME edits usually need second-moment statistics. Compute them before running a new model:
python3 -m src second-moment model=gpt2-large
python3 -m src second-moment model=gpt2-large model.second_moment_target_samples=5000List registered edit methods, captures, analyses, and renderers:
python3 -m src methodsRun one manual ROME edit and chat with the edited model:
python3 -m src manual-rome model=gpt2-largePlan a structural run without loading a model:
python3 -m src structural plan \
'structural.run.models=[gpt2-large,qwen3-4b]' \
structural.run.n_tests=5 \
structural.capture.profile=paperRun the complete CCS report, including accuracy, ROME success, layer-window accuracy, paper JSON, and the six-panel per-layer signal figure:
python3 -m src structural run \
structural=ccs-report \
'structural.run.models=[qwen3-4b]' \
structural.run.n_tests=30 \
structural.run.run_id=qwen3-4b-ccs-reportPlan that workflow or re-render a saved run with the same complete report:
python3 -m src structural plan structural=ccs-report 'structural.run.models=[qwen3-4b]'
python3 -m src graphs run analysis_out/qwen3-4b-ccs-reportgraphs run defaults to ccs-report; the former aggregate-only renderer preset
paper now raises an error. structural.analysis.preset=paper still names the
analysis selection and is set by the workflow. The 5x4 structural artifact
grid remains available separately as structural-paper.
Structural runs derive capture requirements from the selected analyses. For
example, structural.analysis.preset=ccs-composite automatically captures its
spectral primitives and the five matrix columns it consumes: spectral_gap,
top1_energy, row_alignment, norm_cv, and effective_rank. The same rule
applies to blind, rank-one, presence, and study analyses. Explicit capture
profiles remain available for capture-only and graph-only workflows.
The default capture profile is none, so an end-to-end run is driven by the
analysis preset; a capture-only command must select a capture profile explicitly.
End-to-end renderer requirements are included in the same plan, preventing a
selected graph from being run without the matrix columns it needs.
Hydra overrides are the supported option style. Argparse flags such as
--models are no longer supported by the main CLI.
Tracking defaults to none. See W&B setup and fields.
| Workflow | Command / entrypoint |
|---|---|
| Single ROME edit | python3 -m src command=edit edit_method=rome model=gpt2-large |
| Manual ROME chat | python3 -m src manual-rome ... |
| ROME-only benchmark | python3 -m src rome-benchmark rome_benchmark.models=[gpt2-large] |
| Structural capture/analyze | python3 -m src structural run ... |
| Analysis-only replay | python3 -m src structural analyze ... |
| Graph rendering | python3 -m src graphs run <run-root> |
| Causal trace | python3 -m src causal-trace model=gpt2-large |
| Corrected Kuba tracing | python3 -m src causal-kuba-fix model=gpt2-large |
| Alternative trace | python3 -m src alt-trace model=gpt2-large |
| Prefix variability experiment | python3 -m src prefix-experiment prefix_experiment.model=gpt2-large |
| MetaCentrum causal trace -> ROME | jobs/submit.sh causal-rome -- pipeline.model=gpt2-large |
python3 -m src causal-trace model=gpt2-large command.causal_trace.num_valid_facts=100The active workflow corrupts the full subject-token embedding span, restores whole-MLP outputs at the last subject token over overlapping windows, and aggregates paired indirect effects across facts. Discovery predeclares robust contiguous regions; a held-out split must confirm a region before one representative center is reported.
See causal_tracing.md for method, configuration, outputs, and limitations.
Structural runs write manifest-backed run roots:
analysis_out/<run-id>/
manifest.json
plans/<model>/<plan-id>/...
graphs/<renderer>/...
The manifest tracks artifact IDs, paths, config hashes, content hashes, and
input dependencies. Re-running skips current artifacts. Use
structural.run.force=true or graphs.force=true to recompute explicitly.
The opt-in ROME layer localizer and its evidence limits are documented in
docs/detector.md.
The structural pipeline is split into:
src/structural/execution/: model loading, case selection, edits.src/structural/capture/: reusable matrix/capture artifacts.src/structural/analysis/: model-free analysis over saved artifacts.src/structural/detectors/: detector math and live-model adapters.src/graphs/: render artifacts and graph/data outputs.
The prefix experiment measures how sensitive structural detection is to the prefix/template used during a ROME edit.
python3 -m src prefix-experiment \
prefix_experiment.model=gpt2-large \
prefix_experiment.case_idx=0Render a prefix artifact:
python3 -m src graphs prefix analysis_out/<prefix-artifact>.jsonThe notebook prefixtest/prefixtest.ipynb remains available for inspecting
saved prefix experiment artifacts.
covariance_a100_remote.sh computes second-moment statistics on a remote GPU
node and pulls the resulting .pt files into data/second_moment_stats/.
./covariance_a100_remote.sh user@gpu-host
MODEL_KEYS="gpt2-xl gpt-j-6b" ./covariance_a100_remote.sh user@gpu-host /path/to/Latium refactor-clean llmsArguments are:
<user@host> [remote_repo_path] [remote_branch] [conda_env]
Models are selected by config key, for example model=gpt2-large or
structural.run.models=[gpt2-large,qwen3-4b]. Exact HuggingFace names are also
accepted when they match a configured model.
| Model key | Causal Trace | Weight intervention | Mean ES (n=100) | Notes |
|---|---|---|---|---|
gpt2-medium |
yes | yes | 0.980 | works |
gpt2-large |
yes | yes | 0.986 | works |
gpt2-xl |
yes | yes | 0.980 | works |
gpt-j-6b |
yes | yes | 0.990 | works |
qwen3-0.6b |
yes | yes | configured | |
qwen3-1.7b |
yes | yes | configured | |
qwen3-4b |
yes | yes | 1.000 | works |
qwen3-8b |
yes | yes | 1.000 | works |
qwen3.5-4b |
yes | yes | 1.000 | works; hybrid DeltaNet/full-attention architecture |
qwen2.5-1.5b |
yes | yes | configured | |
qwen3-guard-0.6b |
yes | yes | configured | |
granite4-micro |
yes | yes | 0.990 | works |
mistral-7b-v0.1 |
yes | yes | 0.960 | works |
mistral-7b-v0.3 |
yes | yes | 0.890 | works |
llama2-7b |
yes | yes | 0.990 | works |
falcon-7b |
yes | yes | 0.990 | works |
opt-6.7b |
yes | yes | 0.990 | works |
deepseek-7b-base |
yes | yes | 0.918 | works |
deepseek-r1-llama3-8b |
yes | yes | 1.000 | works |
granite-4.1-8b |
yes | yes | 0.990 | works |
ministral-3-8b |
yes | yes | 1.000 | works |
olmo-3-1025-7b |
yes | yes | 1.000 | works |
gemma-4-12b |
yes | yes | 0.990 | works |
llama3 |
planned | planned | roadmap | |
gpt-neo |
planned | planned | roadmap | |
baichuan |
planned | planned | roadmap | |
chatglm |
planned | planned | roadmap | |
t5 |
planned | planned | roadmap |
Prefix-variability configs for Qwen3-8B are available under
src/config/model/qwen3-8b-prefixtest-*.yaml.
docs/project.md: project structure and extension points.docs/wandb-monitoring.md: W&B setup, recorded fields, and dashboard layout.src/README.md: source tree and command wiring.src/config/README.md: config groups and override rules.src/editing/README.md: edit method contract.src/structural/README.md: capture, analysis, and detector flow.src/results/README.md: artifact manifest and cache rules.src/graphs/README.md: renderer contract.causal_tracing.md: causal-tracing and causal-to-ROME commands.jobs/README.md: MetaCentrum setup, PBS presets, and pipeline operation.
make check-rome
make lint
python3 -m compileall -q src rome_benchmark.py
python3 -m pytestUseful smoke checks:
python3 -m src methods
python3 -m src structural plan 'structural.run.models=[gpt2-large]' structural.run.n_tests=5make check-rome verifies that protected ROME paths still match main.
| Code | Meaning |
|---|---|
0 |
Success (including help and expected early exit). |
1 |
structural-validate-cov failure with structural.validate_cov.fail_missing=true, or an uncaught exception. |
2 |
Invalid CLI usage (unknown command or argparse-style -- flag). |
Use structural=gram or jobs/submit_paper_fleet.sh --workflow gram for
shared CounterFact cohorts, appendable ranges and cumulative Gram reports.
See Gram workflow for commands and result semantics.