Spatial Code VSI-Bench Workspace
This workspace evaluates VSI-Bench question answering with several input regimes: raw video frames, perceived spatial codes from SAM3 + Depth Anything 3 caches, ground-truth spatial codes from dataset annotations, and a deterministic symbolic solver. The code is organized so important outputs are reproducible from fixed inputs, fixed packages, fixed model checkpoints, and fixed SAM3/DA3 caches.
The repository intentionally separates three artifact classes:
- source code and tests in
/workspace - data, caches, and model checkpoints under
/root/dataand/root/models - generated results and reports under
/root/resultsand/workspace/reports
Quick Start
# Install packages, clone external repos, download data/models where allowed.
./setup.sh
# Non-interactive setup with a Hugging Face token.
HF_TOKEN=hf_xxx ./setup.sh -y
# Run all unit tests. Tests do not require data, results, or checkpoints.
python -m pytest -q
# Check style and syntax.
python -m black --check /workspace
python -m compileall -q /workspace
Useful setup variants:
./setup.sh --skip-models # packages + repos + data, but no model checkpoints
./setup.sh --skip-data # packages + model repos/checkpoints, but no VSI-Bench data
./setup.sh --skip-workspace # do not sync workspace source from the backup dataset
./setup.sh --with-caches # also sync cached SAM3/DA3 artifacts from the backup dataset
./setup.sh --with-segvggt # clone/install optional SegVGGT support
./setup.sh --force # recreate/re-download targets
After setup, use:
source /root/.venv/bin/activate
source /root/vsi-env.sh
/root/vsi-env.sh sets the path variables the code expects, including
VSI_CODES="/root/data/spatial codes".
Runtime Paths
The default paths can be overridden by environment variables, but these are the expected locations:
| Artifact | Default path | Notes |
|---|---|---|
| Workspace source | /workspace |
Python packages, tests, setup, README |
| VSI-Bench dataset | /root/data/VSI-Bench |
test.jsonl plus videos under dataset folders |
| Official VSI scorer and meta info | /root/data/thinking-in-space |
lmms_eval/tasks/vsibench/utils.py and data/meta_info |
| SAM3/DA3/raw caches | /root/data/caches |
Input to encoder |
| Spatial codes | /root/data/spatial codes |
Set with VSI_CODES; tests do not depend on it |
| Model repos/checkpoints | /root/models |
SAM3, DA3, VLM checkpoints, optional SegVGGT |
| Harness results | /root/results |
One JSON per question |
| Reports | /workspace/reports |
Generated by analysis.letters_reports |
Generated/cache folders in /workspace such as __pycache__, .pytest_cache,
.cache, .ipynb_checkpoints, reports, and results are not
source modules. They are not required by tests.
Reproducibility Contract
Assuming the same inputs, packages, checkpoints, command/config, and frozen SAM3/DA3 caches:
- spatial-code generation from fixed SAM3/DA3 caches is code-level reproducible
- VLM calls use fixed prompts and deterministic decoding config
- Harness outputs are organized by every meaningful config axis to avoid collisions
- reports have deterministic manifest timestamps by default
- tests use synthetic fixtures and do not require data, results, caches, or checkpoints
Regenerating SAM3/DA3 raw caches themselves is not guaranteed deterministic.
Workflow Overview
- Run perception caches if needed with
inference.runorinference.launch. - Build perceived spatial codes with
encoder.runorencoder.launch. - Run VLM harnesses A-C or symbolic harness F.
- Regenerate reports with
analysis.letters_reports. - Back up selected outputs with
backup.py.
Command Reference
Every CLI supports --help; that is the authoritative flag list. The examples below
show the intended interfaces and common combinations.
Setup And Backup
./setup.sh [--skip-models] [--skip-data] [--skip-workspace] [--with-caches] [--with-segvggt] [--force]
python backup.py all --repo owner/dataset --dry-run
python backup.py code --repo owner/dataset
python backup.py reports --repo owner/dataset
python backup.py spatial-codes --repo owner/dataset
python backup.py A,B,C --repo owner/dataset
backup.py targets are defined in TARGETS: code, reports, spatial-codes,
Dry-run mode does not import or call huggingface_hub.
Inference: Raw Model Caches
# One scene, one model backend.
python -m inference.run SCENE --model sam3 --tracking tracking --input uniform --frames 32 --device cuda
python -m inference.run SCENE --model depth-anything-3 --depth metric --input uniform --frames 32 --device cuda
# Batch across selected or all manifest scenes.
python -m inference.launch --model sam3 --tracking tracking --input uniform --frames 32 --scenes scene1,scene2
python -m inference.launch --model depth-anything-3 --depth metric --input uniform --frames 32
Important files:
inference/__init__.py: paths, cache path helpers, frame-selection vocabularyinference/adapters.py: SAM3, DA3, DA3 metric, optional SegVGGT adaptersinference/prompts.py: dataset-specific object prompts for SAM3inference/run.py: single-scene cache writerinference/launch.py: multi-scene worker launcher
Encoder: Spatial Codes
# One scene from existing SAM3/DA3 caches.
python -m encoder.run SCENE --depth metric --tracking tracking --input uniform --frames 32
# Batch over every manifest scene with required caches.
python -m encoder.launch --depth metric --tracking tracking --input uniform --frames 32
# Full-video mode; depth and tracking remain independently selected.
python -m encoder.run SCENE --depth relative --tracking tracking --video
python -m encoder.launch --depth relative --tracking tracking --video
Important files:
encoder/config.py: path construction and validated axesencoder/adapters.py: raw-cache readers into canonical geometryencoder/geometric.py: spatial-code construction mathencoder/render.py: writes final explicit spatial-code JSONencoder/run.py: loads/verifies raw caches and builds one sceneencoder/launch.py: CPU-parallel batch driver
Experiments: Geometry Hypotheses
# List available hypothesis forks.
python -m experiments.run --list
# Build one hypothesis spatial code from existing caches only.
python -m experiments.run SCENE --hypothesis "Compute Gravity Before Building Object Instances" --depth metric --tracking tracking --input uniform --frames 64 --format explicit
# Batch all scenes with existing combined or native SAM3/DA3 caches.
python -m experiments.launch --hypothesis "Compute Gravity Before Building Object Instances" --depth metric --tracking tracking --input uniform --frames 64 --format explicit
# Evaluate generated experiment spatial codes with the symbolic scorer.
python -m experiments.evaluate --hypothesis "Compute Gravity Before Building Object Instances" --depth metric --tracking tracking --input uniform --frames 64 --format explicit --quiet --errors
Files:
experiments/__init__.py: experiments package markerexperiments/README.md: experiment workflow notesexperiments/EXPERIMENT FINDINGS.md: single consolidated findings reportexperiments/hypotheses.md: hypothesis index and notesexperiments/config.py: experiment-local path constructionexperiments/adapters.py: build-call adapter for explicit and compact hypothesis forksexperiments/loader.py: dynamic loader for human-readable hypothesis filenamesexperiments/run.py: one-scene cache-only hypothesis spatial-code builderexperiments/launch.py: batch launcher over scenes with existing cachesexperiments/evaluate.py: symbolic evaluation of experiment spatial codesexperiments/hypotheses/*.py: standalone geometry hypothesis forks; each exposesbuild_spatial_code()anddump_spatial_code()
Symbolic Solver
# One scene.
python -m symbolic.run SCENE --depth metric --tracking tracking --input uniform --frames 32 --format explicit
# Batch over available spatial codes.
python -m symbolic.launch --depth metric --tracking tracking --input uniform --frames 32 --format explicit
# Interactive/debug solver entry point.
python -m symbolic.solver
Important files:
symbolic/adapters.py: adapts compact/explicit codes into solver shapesymbolic/solver.py: deterministic VSI-Bench answering logicsymbolic/run.py: scores one scene and writes per-question JSONsymbolic/launch.py: multi-scene symbolic orchestration
Harness A: Frames or Native Video
The shared policy is configured in harness/A/__init__.py as QUESTION_PROTOCOLS. Edit that mapping once to switch either question group. Both groups write to the same configuration folder; each result JSON records its own question_group and protocol.
python -m harness.A.run --model qwen3.5-4b --frame-selection uniform --frames 32 --scene SCENE
python -m harness.A.launch --model qwen3.5-4b --frame-selection uniform --frames 32 --scenes scene1,scene2
python -m harness.A.sweep --models all --frame-selections all --frames 16,32
python -m harness.A.run --model qwen3.5-4b --video --scene SCENE
python -m harness.A.launch --model qwen3.5-4b --video
python -m harness.A.sweep --models all --video
Question protocols are hardcoded centrally: numerical questions use base; multiple-choice questions use thinking. --reasoning-budget and --force-budget affect only thinking questions. Other flags include --results-dir, --rebuild, --limit, --device, and --no-write.
Files:
harness/A/__init__.py: model paths, protocol constants, result rootharness/A/frames.py: uniform/selective frame samplingharness/A/models.py: VLM adapters and deterministic generation configharness/A/prompts.py: VSI-Bench prompt text for frame inputsharness/A/run.py: one model/config/sceneharness/A/launch.py: persistent GPU workers for one configharness/A/sweep.py: grid over models, frame selections, frame counts
Harness B: Spatial Code Text Only
python -m harness.B.run --model qwen3.5-4b --depth metric --tracking tracking --input-selection uniform --frames 32 --scene SCENE
python -m harness.B.launch --model qwen3.5-4b --depth metric --tracking tracking --input-selection uniform --frames 32
python -m harness.B.sweep --models all --depths metric --trackings tracking --input-selections uniform --frames 32
python -m harness.B.run --model qwen3.5-4b --depth metric --tracking tracking --video --scene SCENE
python -m harness.B.launch --model qwen3.5-4b --depth metric --tracking tracking --video
python -m harness.B.sweep --models all --depths metric --trackings tracking --video
Question protocols use the same hardcoded numerical=base, multiple-choice=thinking policy. Budget flags affect only thinking questions. Other common flags are --results-dir and --rebuild.
Files:
harness/B/__init__.py: B constants and result rootharness/B/spatial_codes.py: loads perceived explicit JSONharness/B/prompts.py: spatial-code-only prompt constructionharness/B/run.py: one model/config/sceneharness/B/launch.py: persistent GPU workers for one configharness/B/sweep.py: grid over model/depth/tracking/input/frame axes
Harness C: Frames Plus Spatial Code
python -m harness.C.run --model qwen3.5-4b --depth metric --tracking tracking --input-selection uniform --frames 32 --spatial-code-source frames --spatial-code-input-selection selective --spatial-code-frames 64 --scene SCENE
python -m harness.C.launch --model qwen3.5-4b --depth metric --tracking tracking --input-selection uniform --frames 32 --spatial-code-source frames --spatial-code-input-selection selective --spatial-code-frames 64
python -m harness.C.sweep --models all --depths metric --trackings tracking --input-selections uniform --frames 32 --spatial-code-sources frames --spatial-code-input-selections selective --spatial-code-frames 64
python -m harness.C.run --model qwen3.5-4b --depth metric --tracking tracking --input-selection uniform --frames 32 --spatial-code-source video --scene SCENE
python -m harness.C.launch --model qwen3.5-4b --depth metric --tracking tracking --input-selection uniform --frames 32 --spatial-code-source video
python -m harness.C.sweep --models all --depths metric --trackings tracking --input-selections uniform --frames 32 --spatial-code-sources video
Files:
harness/C/__init__.py: C constants and result rootharness/C/prompts.py: combined frames + code prompt constructionharness/C/run.py: one model/config/sceneharness/C/launch.py: persistent GPU workers for one configharness/C/sweep.py: grid over independent visual-input and spatial-code-input axes
Harness F: Symbolic Solver As A Harness
python -m harness.F.run --source perceived --depth metric --tracking tracking --input-selection uniform --frames 32 --scene SCENE
python -m harness.F.launch --source perceived --depth metric --tracking tracking --input-selection uniform --frames 32
python -m harness.F.sweep --sources perceived --depths metric --trackings tracking --input-selections uniform --frames 32
python -m harness.F.run --source perceived --depth metric --tracking tracking --video --scene SCENE
python -m harness.F.launch --source perceived --depth metric --tracking tracking --video
python -m harness.F.sweep --sources perceived --depths metric --trackings tracking --video
Files:
harness/F/__init__.py: F constants and result rootharness/F/run.py: symbolic scoring path as a harnessharness/F/launch.py: thin launch entry point torun.mainharness/F/sweep.py: grid over symbolic source/config axes
Analysis And Reports
Current analysis is centered on report generation through analysis.letters_reports and
letter-specific wrappers.
# Regenerate the standard report set from existing results.
python -m analysis.letters_reports \
--cell A=/root/results/A \
--cell B=/root/results/B \
--cell C=/root/results/C \
--cell D=/root/results/D \
--cell F=/root/results/F \
--output-dir /workspace/reports \
--spatial-codes-dir "/root/data/spatial codes"
# Generate one letter report.
python -m analysis.A_reports --results-dir /root/results/A --output-dir /workspace/reports
python -m analysis.B_reports --results-dir /root/results/B --output-dir /workspace/reports
python -m analysis.C_reports --results-dir /root/results/C --output-dir /workspace/reports
python -m analysis.F_reports --results-dir /root/results/F --output-dir /workspace/reports
Files:
analysis/letters_reports.py: shared record discovery, matched summaries, report exportanalysis/A_reports.py: wrapper for A reportanalysis/B_reports.py: wrapper for B reportanalysis/C_reports.py: wrapper for C reportanalysis/F_reports.py: wrapper for F report
Result Layouts
| Producer | Default output layout |
|---|---|
| Inference SAM3 | /root/data/caches/sam3/<tracking>/frames/<input>/<frames>/<scene>.pt |
| Inference DA3 | /root/data/caches/depth-anything-3/<depth>/frames/<input>/<frames>/<scene>.pkl |
| Encoder combined cache | /root/data/caches/sam3+depth-anything-3/<tracking>/frames/<input>/<frames>/<scene>.pkl.gz or /root/data/caches/sam3+depth-anything-3/<tracking>/video/<scene>.pkl.gz |
| Perceived spatial code | $VSI_CODES/sam3+depth-anything-3/<tracking>/frames/<input>/<frames>/explicit/<scene>.json or $VSI_CODES/sam3+depth-anything-3/<tracking>/video/explicit/<scene>.json |
| A results | `/root/results/A//{/ |
| B results | `/root/results/B//explicit///{/ |
| C results | `/root/results/C//explicit///{/ |
| F results | `/root/results/F/perceived///{/ |
| Reports | /workspace/reports/*_report.json |
Full Source File Index
Top Level
| File | Purpose |
|---|---|
README.md |
This documentation |
setup.sh |
Environment, package, data, model, and validation setup |
backup.py |
Hugging Face dataset backup utility |
.gitattributes |
Git LFS attributes for large/binary artifact patterns |
.gitignore |
Excludes generated caches, notebooks, envs, and result folders |
selective_frame_counts.csv |
Static frame-count/reference data used by selection workflows |
bundles/spatial-codes.tar.gz |
Packed spatial-code artifact used by setup sync |
analysis/
| File | Purpose |
|---|---|
analysis/A_reports.py |
CLI wrapper for A report |
analysis/B_reports.py |
CLI wrapper for B report |
analysis/C_reports.py |
CLI wrapper for C report |
analysis/F_reports.py |
CLI wrapper for F report |
analysis/letters_reports.py |
Shared analysis/report implementation |
encoder/
| File | Purpose |
|---|---|
encoder/__init__.py |
Encoder package marker |
encoder/config.py |
Paths and validated dimensions |
encoder/adapters.py |
Raw model-cache adapters |
encoder/geometric.py |
Spatial-code geometry math |
encoder/render.py |
Writes explicit JSON |
encoder/run.py |
One-scene perceived-code build |
encoder/launch.py |
Batch perceived-code build |
harness/
| File | Purpose |
|---|---|
harness/__init__.py |
Harness package marker |
harness/A/__init__.py |
A constants/model paths |
harness/A/frames.py |
Frame sampling |
harness/A/models.py |
VLM adapters |
harness/A/prompts.py |
Frame-only prompts |
harness/A/run.py |
A one-scene runner |
harness/A/launch.py |
A batch launcher |
harness/A/sweep.py |
A sweep launcher |
harness/B/__init__.py |
B constants |
harness/B/spatial_codes.py |
Perceived-code loader |
harness/B/prompts.py |
Code-only prompts |
harness/B/run.py |
B one-scene runner |
harness/B/launch.py |
B batch launcher |
harness/B/sweep.py |
B sweep launcher |
harness/C/__init__.py |
C constants |
harness/C/prompts.py |
Frames+code prompts |
harness/C/run.py |
C one-scene runner |
harness/C/launch.py |
C batch launcher |
harness/C/sweep.py |
C sweep launcher |
harness/F/__init__.py |
F constants |
harness/F/run.py |
Symbolic solver as harness |
harness/F/launch.py |
Thin F launch entry point |
harness/F/sweep.py |
F sweep launcher |
inference/
| File | Purpose |
|---|---|
inference/__init__.py |
Inference constants/path helpers |
inference/adapters.py |
SAM3, DA3, SegVGGT adapters |
inference/prompts.py |
Object prompts for SAM3 |
inference/run.py |
One-scene raw-cache runner |
inference/launch.py |
Batch raw-cache launcher |
symbolic/
| File | Purpose |
|---|---|
symbolic/adapters.py |
Code schema adapter for solver |
symbolic/solver.py |
Deterministic solver |
symbolic/run.py |
One-scene symbolic scoring/writing |
symbolic/launch.py |
Batch symbolic scoring |
Test File Index
The tests mirror source folders. They are written to run without real data, results, or model checkpoints.
tests/
tests/__init__.pytests/conftest.py
tests/test_A/
tests/test_A/__init__.pytests/test_A/conftest.pytests/test_A/test_A.pytests/test_A/test_frames.pytests/test_A/test_launch.pytests/test_A/test_models.pytests/test_A/test_prompts.pytests/test_A/test_run.pytests/test_A/test_sweep.py
tests/test_B/
tests/test_B/__init__.pytests/test_B/conftest.pytests/test_B/test_B.pytests/test_B/test_launch.pytests/test_B/test_prompts.pytests/test_B/test_run.pytests/test_B/test_spatial_codes.pytests/test_B/test_sweep.py
tests/test_C/
tests/test_C/__init__.pytests/test_C/conftest.pytests/test_C/test_C.pytests/test_C/test_launch.pytests/test_C/test_prompts.pytests/test_C/test_run.pytests/test_C/test_sweep.py
tests/test_F/
tests/test_F/__init__.pytests/test_F/conftest.pytests/test_F/test_F.pytests/test_F/test_launch.pytests/test_F/test_run.pytests/test_F/test_sweep.py
tests/test_analysis/
tests/test_analysis/__init__.pytests/test_analysis/conftest.pytests/test_analysis/test_A_reports.pytests/test_analysis/test_B_reports.pytests/test_analysis/test_C_reports.pytests/test_analysis/test_F_reports.pytests/test_analysis/test_analysis.pytests/test_analysis/test_letters_reports.py
tests/
tests/test_backup.py
tests/test_encoder/
tests/test_encoder/conftest.pytests/test_encoder/test_adapters.pytests/test_encoder/test_config.pytests/test_encoder/test_encoder.pytests/test_encoder/test_geometric.pytests/test_encoder/test_ground_truth.pytests/test_encoder/test_init.pytests/test_encoder/test_launch.pytests/test_encoder/test_render.pytests/test_encoder/test_run.py
tests/test_experiments/
tests/test_experiments/__init__.pytests/test_experiments/conftest.pytests/test_experiments/test_config.pytests/test_experiments/test_evaluate.pytests/test_experiments/test_experiments.pytests/test_experiments/test_hypotheses.pytests/test_experiments/test_launch.pytests/test_experiments/test_loader.pytests/test_experiments/test_run.py
tests/test_harness/
tests/test_harness/__init__.pytests/test_harness/conftest.pytests/test_harness/test_harness.py
tests/test_inference/
tests/test_inference/conftest.pytests/test_inference/test_adapters.pytests/test_inference/test_inference.pytests/test_inference/test_init.pytests/test_inference/test_launch.pytests/test_inference/test_prompts.pytests/test_inference/test_run.py
tests/test_symbolic/
tests/test_symbolic/conftest.pytests/test_symbolic/test_adapters.pytests/test_symbolic/test_launch.pytests/test_symbolic/test_run.pytests/test_symbolic/test_solver.pytests/test_symbolic/test_symbolic.py
Maintenance Rules
When adding a Python source file, add the corresponding test in the mirrored test folder. For example:
Every tests/test_<folder>/ directory should contain both conftest.py and
test_<folder>.py. Tests should use temporary files, monkeypatching, and synthetic
fixtures rather than relying on /root/data, /root/results, /workspace/data, or
model checkpoints.
Before handing off changes, run:
python -m black /workspace
python -m black --check /workspace
python -m compileall -q /workspace
python -m pytest -q