This guide is for extending and maintaining the SAE tools codebase.
conda create -n sae-tl3 python=3.11 -y
conda activate sae-tl3
pip install -e ".[dev,workflow,tui]"If the package is not installed in the current Python, use PYTHONPATH=src for
local checks:
PYTHONPATH=src python -m pytest
PYTHONPATH=src python -m sae_tools_tui --helpsrc/sae_tools/
adapters/ model, SAE, and dataset adapter registries
analysis/ statistical, geometric, and dashboard analysis code
experiment_store/ experiment bundle manifest and Parquet indexes
model/ model loading, hooks, activation generation helpers
reporting/ HTML report rendering and read-only HTTP dashboard service
workflow/ registry models, artifact path helpers, runtime scans
scripts/
gen_activations_one.py
analyze_stat.py
analyze_geo.py
collect_stat_seeds.py
inspect_registry.py
run_idle_gpu_workflow.py
src/sae_tools_tui/
__main__.py CLI/module entrypoint
app.py Textual UI
backend.py TUI-facing backend wrapper
widgets.py presentation helpers
configs/
registry/ stable model, SAE, dataset, and analysis IDs
experiments/ experiment matrices
docs/
user and developer documentation
Single-artifact scripts do the expensive work. Snakemake owns dependencies and reuse. The idle-GPU runner only allocates Snakemake targets to GPUs. The TUI is a frontend over the workflow runtime and runner.
Do not duplicate target expansion, artifact status, GPU parsing, or command construction in UI code. Use:
from sae_tools.workflow import runtimeImportant runtime helpers:
workflow_target_records: expand experiment YAML into activation/stat/geometric targets.scan_artifacts: classify targets asdone,missing,incomplete, orfailed.scan_resources: check requested models, datasets, and every requested SAE layer.check_environment: return displayable environment checks without crashing.query_gpusandclassify_gpus: parsenvidia-smiand idle-selection reasons.build_snakemake_dry_run_command: build TUI dry-run commands.build_idle_runner_command: build TUI run-missing commands.
The browser report service lives under src/sae_tools/reporting/.
Responsibilities:
- Render existing analysis outputs as HTML.
- Serve files under
artifacts/experiments/<experiment>/reports/through safe path checks. - Display experiment and artifact status from
sae_tools.workflow.runtime. - Reuse
FeatureActivationViewerfor token heatmaps without requiringipywidgets.
Non-responsibilities:
- No workflow scheduling or Snakemake launches.
- No artifact deletion or regeneration.
- No full model or GPU loading for the default dashboard. Feature heatmaps may load a local tokenizer and dataset metadata only when requested.
Models:
- Add or edit
configs/registry/models.yaml. - Add a matching profile under
src/sae_tools/adapters/models/if needed. - Keep
local_pathrelative toMODEL_ROOT; machine-specific roots belong in.env.
SAEs:
- Add or edit
configs/registry/saes.yaml. - Add a matching profile/adapter under
src/sae_tools/adapters/saes/if needed. - List all supported layers in
layers. - Keep
local_dirrelative toSAE_ROOT; machine-specific roots belong in.env. - Keep
file_templatecompatible withSAESpec.layer_filename(layer).
Datasets:
- Add or edit
configs/registry/datasets.yaml. - Add a dataset adapter under
src/sae_tools/adapters/datasets/if needed. - Use IDs that encode the analyzed text field, such as
MyDataset_promptorMyDataset_response. - Set
label_fieldwhen the default<data_type>_labelis not correct. - Keep
folderrelative toDATASET_ROOT; machine-specific roots belong in.env.
Analyses:
- Add or edit
configs/registry/analyses.yaml. - Keep
kindasstatisticalorgeometric. - Verify the corresponding scripts can consume the configured metrics or methods.
Validate:
python scripts/inspect_registry.py --strict
snakemake -nCreate configs/experiments/<name>.yaml:
models: [qwen3-8b]
saes:
- qwen-scope-qwen3-8b-l0-50
layers: [18]
datasets:
- ToxicChat_prompt
activation:
overwrite: false
batch_size: 2
analyses:
- stat_basic
- geo_basicRules:
- Omit
layersonly when each SAE should use its default layer. - Set
activation.overwrite: falseunless regeneration is intentional. - Use per-dataset
max_samplesoverrides when an experiment needs a different cache key. - Dry-run before launching GPU work.
The TUI lives under src/sae_tools_tui/.
Responsibilities:
- Display scans from
sae_tools.workflow.runtime. - Create experiment YAML files through the registry-backed TUI wizard.
- Stream stdout/stderr from Snakemake dry runs and idle-GPU runner commands.
- Refresh artifact and GPU state while a command runs.
- Disable run buttons when environment checks fail.
Non-responsibilities:
- No independent scheduling.
- No automatic
conda activate. - No model, SAE, or dataset downloads.
- No direct artifact mutation beyond launching existing backend commands.
Focused workflow/TUI checks:
PYTHONPATH=src python -m pytest \
tests/test_tui_runtime.py \
tests/test_idle_gpu_runner.py \
tests/test_workflow_registry.pyFull suite:
PYTHONPATH=src python -m pytestSmoke checks:
PYTHONPATH=src python -m sae_tools_tui --help
PYTHONPATH=src python -m sae_tools.reporting --help
python -m compileall -q src scripts
python -c "import tomllib; tomllib.load(open('pyproject.toml','rb'))"The console script smoke check requires an installed editable package:
pip install -e ".[tui]"
sae-tools-tui --help
sae-tools-report --helpGenerated outputs are not source files:
artifacts/
logs/
.snakemake/
runs/gpu_memory/<run_id>/
*.pt
*.safetensors
Keep source control focused on:
src/scripts/configs/docs/tests/- stable planning files such as
runs/gpu_memory/allocation_table.md
Do not delete, force-regenerate, or rewrite expensive artifacts during routine
development. Use Snakemake reuse and --rerun-incomplete for interrupted runs.
Before handing off substantial changes:
PYTHONPATH=src python -m pytest
PYTHONPATH=src python -m sae_tools_tui --help
python -m compileall -q src scripts
python scripts/inspect_registry.py --strict
snakemake -nSome checks require optional dependencies, GPUs, and configured local resources. Report any skipped or unavailable checks explicitly.