Remove old tests before replacement
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tests/__init__.py +0 -0
- tests/conftest.py +0 -48
- tests/test_A/__init__.py +0 -0
- tests/test_A/conftest.py +0 -12
- tests/test_A/test_A.py +0 -68
- tests/test_A/test_frames.py +0 -79
- tests/test_A/test_init.py +0 -60
- tests/test_A/test_launch.py +0 -90
- tests/test_A/test_models.py +0 -94
- tests/test_A/test_prompts.py +0 -55
- tests/test_A/test_run.py +0 -229
- tests/test_A/test_sweep.py +0 -69
- tests/test_B/__init__.py +0 -0
- tests/test_B/conftest.py +0 -12
- tests/test_B/test_B.py +0 -35
- tests/test_B/test_init.py +0 -33
- tests/test_B/test_launch.py +0 -85
- tests/test_B/test_prompts.py +0 -103
- tests/test_B/test_run.py +0 -231
- tests/test_B/test_spatial_codes.py +0 -48
- tests/test_B/test_sweep.py +0 -67
- tests/test_C/__init__.py +0 -0
- tests/test_C/conftest.py +0 -12
- tests/test_C/test_C.py +0 -27
- tests/test_C/test_init.py +0 -25
- tests/test_C/test_launch.py +0 -69
- tests/test_C/test_overlay.py +0 -209
- tests/test_C/test_overlay_launch.py +0 -144
- tests/test_C/test_prompts.py +0 -66
- tests/test_C/test_run.py +0 -176
- tests/test_C/test_sweep.py +0 -67
- tests/test_D/__init__.py +0 -0
- tests/test_D/conftest.py +0 -45
- tests/test_D/test_D.py +0 -21
- tests/test_D/test_init.py +0 -19
- tests/test_D/test_launch.py +0 -67
- tests/test_D/test_prompts.py +0 -55
- tests/test_D/test_run.py +0 -246
- tests/test_D/test_spatial_codes.py +0 -33
- tests/test_D/test_sweep.py +0 -28
- tests/test_D/test_symbolic_eval.py +0 -116
- tests/test_E/__init__.py +0 -0
- tests/test_E/conftest.py +0 -12
- tests/test_E/test_E.py +0 -20
- tests/test_E/test_launch.py +0 -66
- tests/test_E/test_prompts.py +0 -48
- tests/test_E/test_run.py +0 -97
- tests/test_E/test_sweep.py +0 -40
- tests/test_F/__init__.py +0 -0
- tests/test_F/conftest.py +0 -12
tests/__init__.py
DELETED
|
File without changes
|
tests/conftest.py
DELETED
|
@@ -1,48 +0,0 @@
|
|
| 1 |
-
"""Global test setup that keeps unit tests independent of optional native packages."""
|
| 2 |
-
|
| 3 |
-
from __future__ import annotations
|
| 4 |
-
|
| 5 |
-
import importlib.util
|
| 6 |
-
import sys
|
| 7 |
-
import types
|
| 8 |
-
from pathlib import Path
|
| 9 |
-
|
| 10 |
-
ROOT = Path(__file__).resolve().parents[1]
|
| 11 |
-
if str(ROOT) not in sys.path:
|
| 12 |
-
sys.path.insert(0, str(ROOT))
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
class _FakeCapture:
|
| 16 |
-
def __init__(self, path):
|
| 17 |
-
self.path = path
|
| 18 |
-
|
| 19 |
-
def get(self, prop):
|
| 20 |
-
return 0.0
|
| 21 |
-
|
| 22 |
-
def release(self):
|
| 23 |
-
pass
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
if importlib.util.find_spec("cv2") is None and "cv2" not in sys.modules:
|
| 27 |
-
cv2 = types.ModuleType("cv2")
|
| 28 |
-
cv2.CAP_PROP_FPS = 5
|
| 29 |
-
cv2.INTER_NEAREST = 0
|
| 30 |
-
cv2.MORPH_CLOSE = 3
|
| 31 |
-
cv2.RETR_EXTERNAL = 0
|
| 32 |
-
cv2.RETR_CCOMP = 2
|
| 33 |
-
cv2.CHAIN_APPROX_SIMPLE = 0
|
| 34 |
-
cv2.GC_PR_BGD = 2
|
| 35 |
-
cv2.GC_PR_FGD = 3
|
| 36 |
-
cv2.GC_FGD = 1
|
| 37 |
-
cv2.GC_INIT_WITH_MASK = 1
|
| 38 |
-
cv2.VideoCapture = _FakeCapture
|
| 39 |
-
cv2.resize = lambda image, size, interpolation=None: image
|
| 40 |
-
cv2.erode = lambda image, kernel, iterations=1: image
|
| 41 |
-
cv2.dilate = lambda image, kernel, iterations=1: image
|
| 42 |
-
cv2.morphologyEx = lambda image, op, kernel: image
|
| 43 |
-
cv2.findContours = lambda image, mode, method: ([], None)
|
| 44 |
-
cv2.approxPolyDP = lambda contour, epsilon, closed: contour
|
| 45 |
-
cv2.contourArea = lambda contour: 0
|
| 46 |
-
cv2.imread = lambda path: None
|
| 47 |
-
cv2.grabCut = lambda *args, **kwargs: None
|
| 48 |
-
sys.modules["cv2"] = cv2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_A/__init__.py
DELETED
|
File without changes
|
tests/test_A/conftest.py
DELETED
|
@@ -1,12 +0,0 @@
|
|
| 1 |
-
"""Shared import setup for harness.A tests."""
|
| 2 |
-
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
import sys
|
| 5 |
-
|
| 6 |
-
ROOT = Path(__file__).resolve().parents[2]
|
| 7 |
-
if str(ROOT) not in sys.path:
|
| 8 |
-
sys.path.insert(0, str(ROOT))
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def pytest_configure(config):
|
| 12 |
-
config.option.importmode = "importlib"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_A/test_A.py
DELETED
|
@@ -1,68 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/A/__init__.py -- shared config constants."""
|
| 2 |
-
|
| 3 |
-
from argparse import ArgumentParser, Namespace
|
| 4 |
-
from pathlib import Path
|
| 5 |
-
|
| 6 |
-
import pytest
|
| 7 |
-
|
| 8 |
-
from harness import A
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def test_thinking_mode_resolves_default_budgets():
|
| 12 |
-
args = Namespace(extended=True, reasoning_budget=None, force_budget=None)
|
| 13 |
-
A.resolve_protocol_budgets(ArgumentParser(), args)
|
| 14 |
-
assert args.reasoning_budget == A.EXTENDED_MAX_NEW_TOKENS
|
| 15 |
-
assert args.force_budget == A.MAX_NEW_TOKENS
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def test_base_mode_keeps_budgets_unset_without_budget_flags():
|
| 19 |
-
args = Namespace(extended=False, reasoning_budget=None, force_budget=None)
|
| 20 |
-
A.resolve_protocol_budgets(ArgumentParser(), args)
|
| 21 |
-
assert args.reasoning_budget is None
|
| 22 |
-
assert args.force_budget is None
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
@pytest.mark.parametrize("flag", ["reasoning_budget", "force_budget"])
|
| 26 |
-
def test_base_mode_rejects_thinking_budget_flags(flag):
|
| 27 |
-
args = Namespace(extended=False, reasoning_budget=None, force_budget=None)
|
| 28 |
-
setattr(args, flag, 8)
|
| 29 |
-
with pytest.raises(SystemExit):
|
| 30 |
-
A.resolve_protocol_budgets(ArgumentParser(), args)
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def test_generation_protocol_matches_vsibench_yaml():
|
| 34 |
-
# thinking-in-space/lmms_eval/tasks/vsibench/vsibench.yaml generation_kwargs.
|
| 35 |
-
assert A.MAX_NEW_TOKENS == 16
|
| 36 |
-
assert A.TEMPERATURE == 0.0
|
| 37 |
-
assert A.DO_SAMPLE is False
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
def test_thinking_generation_protocol():
|
| 41 |
-
assert A.EXTENDED_MAX_NEW_TOKENS == 2048
|
| 42 |
-
assert A.EXTENDED_MAX_NEW_TOKENS > A.MAX_NEW_TOKENS
|
| 43 |
-
assert isinstance(A.FORCE_ANSWER_PROMPT, str) and A.FORCE_ANSWER_PROMPT.strip()
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
def test_frame_selections_match_inference_vocabulary():
|
| 47 |
-
from inference import SAM3_FRAME_SELECTIONS
|
| 48 |
-
|
| 49 |
-
assert A.FRAME_SELECTIONS == SAM3_FRAME_SELECTIONS
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
def test_default_frame_selection_is_a_valid_selection():
|
| 53 |
-
assert A.DEFAULT_FRAME_SELECTION in A.FRAME_SELECTIONS
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
def test_model_paths_cover_every_registered_model():
|
| 57 |
-
assert set(A.MODEL_PATHS) == {
|
| 58 |
-
"qwen3.5-4b",
|
| 59 |
-
"qwen3.5-2b",
|
| 60 |
-
"internvl3.5-4b",
|
| 61 |
-
"internvl3.5-2b",
|
| 62 |
-
}
|
| 63 |
-
for path in A.MODEL_PATHS.values():
|
| 64 |
-
assert path.parent == A.MODELS_ROOT
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
def test_results_dir_defaults_under_root_results():
|
| 68 |
-
assert A.RESULTS_DIR == Path("/root/results/A")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_A/test_frames.py
DELETED
|
@@ -1,79 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/A/frames.py -- uniform/selective frame sampling."""
|
| 2 |
-
|
| 3 |
-
import numpy as np
|
| 4 |
-
import pytest
|
| 5 |
-
|
| 6 |
-
from harness.A import frames as frame_sampling
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
def test_sample_frames_rejects_unknown_selection(tmp_path):
|
| 10 |
-
video = tmp_path / "scene.mp4"
|
| 11 |
-
video.write_bytes(b"not a real video")
|
| 12 |
-
with pytest.raises(ValueError):
|
| 13 |
-
frame_sampling.sample_frames(str(video), 8, "random")
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def test_sample_frames_rejects_nonpositive_frame_count(tmp_path):
|
| 17 |
-
video = tmp_path / "scene.mp4"
|
| 18 |
-
video.write_bytes(b"not a real video")
|
| 19 |
-
with pytest.raises(ValueError):
|
| 20 |
-
frame_sampling.sample_frames(str(video), 0, "uniform")
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def test_sample_frames_rejects_missing_video(tmp_path):
|
| 24 |
-
with pytest.raises(FileNotFoundError):
|
| 25 |
-
frame_sampling.sample_frames(str(tmp_path / "missing.mp4"), 8, "uniform")
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def test_sample_frames_returns_pil_images_in_order(tmp_path, monkeypatch):
|
| 29 |
-
video = tmp_path / "scene.mp4"
|
| 30 |
-
video.write_bytes(b"not a real video")
|
| 31 |
-
fake_frames = np.stack(
|
| 32 |
-
[np.full((4, 4, 3), value, dtype=np.uint8) for value in (10, 20, 30)]
|
| 33 |
-
)
|
| 34 |
-
monkeypatch.setattr(
|
| 35 |
-
frame_sampling,
|
| 36 |
-
"_sample_video_frames",
|
| 37 |
-
lambda path, count, selection: (fake_frames, np.array([0.0, 1.0, 2.0])),
|
| 38 |
-
)
|
| 39 |
-
|
| 40 |
-
class _UnreadableCapture:
|
| 41 |
-
def get(self, prop):
|
| 42 |
-
return 0.0
|
| 43 |
-
|
| 44 |
-
def release(self):
|
| 45 |
-
pass
|
| 46 |
-
|
| 47 |
-
monkeypatch.setattr(
|
| 48 |
-
frame_sampling.cv2, "VideoCapture", lambda path: _UnreadableCapture()
|
| 49 |
-
)
|
| 50 |
-
result, timestamps, indices = frame_sampling.sample_frames(str(video), 3, "uniform")
|
| 51 |
-
assert len(result) == 3
|
| 52 |
-
assert np.array(result[0])[0, 0, 0] == 10
|
| 53 |
-
assert np.array(result[2])[0, 0, 0] == 30
|
| 54 |
-
assert timestamps == [0.0, 1.0, 2.0]
|
| 55 |
-
# fps falls back to 1.0 for the fake (unreadable) video, so index == round(t * 1.0) == t.
|
| 56 |
-
assert indices == [0, 1, 2]
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
def test_sample_frames_derives_indices_from_real_fps(tmp_path, monkeypatch):
|
| 60 |
-
video = tmp_path / "scene.mp4"
|
| 61 |
-
video.write_bytes(b"not a real video")
|
| 62 |
-
fake_frames = np.stack([np.full((2, 2, 3), 1, dtype=np.uint8)] * 3)
|
| 63 |
-
monkeypatch.setattr(
|
| 64 |
-
frame_sampling,
|
| 65 |
-
"_sample_video_frames",
|
| 66 |
-
lambda path, count, selection: (fake_frames, np.array([0.0, 0.5, 1.0])),
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
class _FakeCapture:
|
| 70 |
-
def get(self, prop):
|
| 71 |
-
return 30.0
|
| 72 |
-
|
| 73 |
-
def release(self):
|
| 74 |
-
pass
|
| 75 |
-
|
| 76 |
-
monkeypatch.setattr(frame_sampling.cv2, "VideoCapture", lambda path: _FakeCapture())
|
| 77 |
-
_, timestamps, indices = frame_sampling.sample_frames(str(video), 3, "uniform")
|
| 78 |
-
assert timestamps == [0.0, 0.5, 1.0]
|
| 79 |
-
assert indices == [0, 15, 30]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_A/test_init.py
DELETED
|
@@ -1,60 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/A/__init__.py -- shared config constants."""
|
| 2 |
-
|
| 3 |
-
from harness import A
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def test_generation_protocol_matches_vsibench_yaml():
|
| 7 |
-
# thinking-in-space/lmms_eval/tasks/vsibench/vsibench.yaml generation_kwargs.
|
| 8 |
-
assert A.MAX_NEW_TOKENS == 16
|
| 9 |
-
assert A.TEMPERATURE == 0.0
|
| 10 |
-
assert A.DO_SAMPLE is False
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def test_thinking_generation_protocol():
|
| 14 |
-
assert A.EXTENDED_MAX_NEW_TOKENS == 2048
|
| 15 |
-
assert A.EXTENDED_MAX_NEW_TOKENS > A.MAX_NEW_TOKENS
|
| 16 |
-
assert isinstance(A.FORCE_ANSWER_PROMPT, str) and A.FORCE_ANSWER_PROMPT.strip()
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
def test_frame_selections_match_inference_vocabulary():
|
| 20 |
-
from inference import SAM3_FRAME_SELECTIONS
|
| 21 |
-
|
| 22 |
-
assert A.FRAME_SELECTIONS == SAM3_FRAME_SELECTIONS
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
def test_default_frame_selection_is_a_valid_selection():
|
| 26 |
-
assert A.DEFAULT_FRAME_SELECTION in A.FRAME_SELECTIONS
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
def test_model_paths_cover_every_registered_model():
|
| 30 |
-
assert set(A.MODEL_PATHS) == {
|
| 31 |
-
"qwen3.5-4b",
|
| 32 |
-
"qwen3.5-2b",
|
| 33 |
-
"internvl3.5-4b",
|
| 34 |
-
"internvl3.5-2b",
|
| 35 |
-
}
|
| 36 |
-
for path in A.MODEL_PATHS.values():
|
| 37 |
-
assert path.parent == A.MODELS_ROOT
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
def test_results_dir_defaults_under_workspace_results():
|
| 41 |
-
assert A.RESULTS_DIR == A.WORKSPACE_ROOT / "results" / "A"
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
def test_question_protocol_policy_is_hardcoded_by_group():
|
| 45 |
-
assert A.question_group("object_counting") == "numerical"
|
| 46 |
-
assert A.protocol_for_question("object_counting") == "base"
|
| 47 |
-
assert A.question_group("route_planning") == "multiple_choice"
|
| 48 |
-
assert A.protocol_for_question("route_planning") == "thinking"
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
def test_every_known_question_type_has_one_policy_group():
|
| 52 |
-
for question_type in A.NUMERICAL_QUESTION_TYPES:
|
| 53 |
-
assert (
|
| 54 |
-
A.protocol_for_question(question_type) == A.QUESTION_PROTOCOLS["numerical"]
|
| 55 |
-
)
|
| 56 |
-
for question_type in A.MULTIPLE_CHOICE_QUESTION_TYPES:
|
| 57 |
-
assert (
|
| 58 |
-
A.protocol_for_question(question_type)
|
| 59 |
-
== A.QUESTION_PROTOCOLS["multiple_choice"]
|
| 60 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_A/test_launch.py
DELETED
|
@@ -1,90 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/A/launch.py -- multi-GPU scene sharding across workers."""
|
| 2 |
-
|
| 3 |
-
import pytest
|
| 4 |
-
|
| 5 |
-
from harness.A import launch
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def test_launcher_imports():
|
| 9 |
-
assert callable(launch.main)
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
def test_scenes_dedups_and_preserves_order(tmp_path, monkeypatch):
|
| 13 |
-
manifest = tmp_path / "questions.jsonl"
|
| 14 |
-
rows = [
|
| 15 |
-
'{"scene_name": "scene-a"}',
|
| 16 |
-
'{"scene_name": "scene-b"}',
|
| 17 |
-
'{"scene_name": "scene-a"}',
|
| 18 |
-
]
|
| 19 |
-
manifest.write_text("\n".join(rows) + "\n")
|
| 20 |
-
monkeypatch.setattr(launch, "JSONL", manifest)
|
| 21 |
-
assert launch.scenes() == ["scene-a", "scene-b"]
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
class _FakeRun:
|
| 25 |
-
rows = [{"id": 1}, {"id": 2}]
|
| 26 |
-
|
| 27 |
-
@staticmethod
|
| 28 |
-
def results_dir_for(
|
| 29 |
-
model, protocol, frame_selection, frame_count, results_dir=None
|
| 30 |
-
):
|
| 31 |
-
return results_dir
|
| 32 |
-
|
| 33 |
-
@classmethod
|
| 34 |
-
def load_questions(cls, scene=None):
|
| 35 |
-
return list(cls.rows)
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
def test_launch_skips_scene_already_fully_answered(tmp_path, capsys, monkeypatch):
|
| 39 |
-
scene = "scene-a"
|
| 40 |
-
monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun)
|
| 41 |
-
|
| 42 |
-
scene_dir = tmp_path / scene
|
| 43 |
-
scene_dir.mkdir()
|
| 44 |
-
for row in _FakeRun.rows:
|
| 45 |
-
(scene_dir / f"{row['id']}.json").write_text("{}")
|
| 46 |
-
|
| 47 |
-
launch.launch("qwen3.5-2b", "uniform", 16, [scene], results_dir=tmp_path)
|
| 48 |
-
|
| 49 |
-
output = capsys.readouterr().out
|
| 50 |
-
assert "skipped" in output
|
| 51 |
-
assert "DONE: 1 ok, 0 failed" in output
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
def test_launch_rebuild_forces_pending_even_when_answered(tmp_path, monkeypatch):
|
| 55 |
-
scene = "scene-a"
|
| 56 |
-
monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun)
|
| 57 |
-
scene_dir = tmp_path / scene
|
| 58 |
-
scene_dir.mkdir()
|
| 59 |
-
for row in _FakeRun.rows:
|
| 60 |
-
(scene_dir / f"{row['id']}.json").write_text("{}")
|
| 61 |
-
|
| 62 |
-
monkeypatch.setattr(launch, "visible_gpus", lambda: [])
|
| 63 |
-
|
| 64 |
-
# Only assert it treats the scene as pending (doesn't take the all-skipped early
|
| 65 |
-
# return); actually spawning workers needs a real model/GPU, exercised by the live
|
| 66 |
-
# harness.A.launch smoke run instead of the unit suite.
|
| 67 |
-
monkeypatch.setattr(
|
| 68 |
-
launch.mp,
|
| 69 |
-
"get_context",
|
| 70 |
-
lambda *_: (_ for _ in ()).throw(
|
| 71 |
-
RuntimeError("rebuild correctly reached worker dispatch")
|
| 72 |
-
),
|
| 73 |
-
)
|
| 74 |
-
try:
|
| 75 |
-
launch.launch(
|
| 76 |
-
"qwen3.5-2b", "uniform", 16, [scene], results_dir=tmp_path, rebuild=True
|
| 77 |
-
)
|
| 78 |
-
except RuntimeError as exc:
|
| 79 |
-
assert "rebuild correctly reached worker dispatch" in str(exc)
|
| 80 |
-
else:
|
| 81 |
-
raise AssertionError("expected rebuild to force scene into the pending path")
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
def test_launch_rejects_scene_with_no_questions(monkeypatch, tmp_path):
|
| 85 |
-
class EmptyRun(_FakeRun):
|
| 86 |
-
rows = []
|
| 87 |
-
|
| 88 |
-
monkeypatch.setattr(launch, "_load_run_module", lambda: EmptyRun)
|
| 89 |
-
with pytest.raises(ValueError, match="no questions found"):
|
| 90 |
-
launch.launch("qwen3.5-2b", "uniform", 16, ["missing"], results_dir=tmp_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_A/test_models.py
DELETED
|
@@ -1,94 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/A/models.py -- VLM adapter registry and prompt assembly.
|
| 2 |
-
|
| 3 |
-
Deliberately excludes any test that loads real model weights or calls .generate() --
|
| 4 |
-
those require the GPU and downloaded checkpoints and are exercised via harness.A.run
|
| 5 |
-
smoke runs instead, not the unit suite.
|
| 6 |
-
"""
|
| 7 |
-
|
| 8 |
-
import pytest
|
| 9 |
-
|
| 10 |
-
from harness import A
|
| 11 |
-
from harness.A import models as vlm_models
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
def test_all_three_models_are_registered():
|
| 15 |
-
assert vlm_models.available_models() == (
|
| 16 |
-
"internvl3.5-2b",
|
| 17 |
-
"internvl3.5-4b",
|
| 18 |
-
"qwen3.5-2b",
|
| 19 |
-
"qwen3.5-4b",
|
| 20 |
-
)
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def test_get_adapter_binds_the_correct_checkpoint_path():
|
| 24 |
-
adapter = vlm_models.get_adapter("qwen3.5-4b")
|
| 25 |
-
assert adapter.model_path == A.MODEL_PATHS["qwen3.5-4b"]
|
| 26 |
-
assert isinstance(adapter, vlm_models.QwenVLAdapter)
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
def test_get_adapter_returns_the_right_class_per_model():
|
| 30 |
-
assert isinstance(vlm_models.get_adapter("qwen3.5-2b"), vlm_models.QwenVLAdapter)
|
| 31 |
-
assert isinstance(
|
| 32 |
-
vlm_models.get_adapter("internvl3.5-4b"), vlm_models.InternVLAdapter
|
| 33 |
-
)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
def test_get_adapter_rejects_unknown_model():
|
| 37 |
-
with pytest.raises(KeyError):
|
| 38 |
-
vlm_models.get_adapter("not-a-real-model")
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
def test_internvl_adapter_disables_per_frame_tiling():
|
| 42 |
-
# Otherwise InternVL's default per-image dynamic tiling (~3300 tokens/frame) blows
|
| 43 |
-
# past this checkpoint's 40960-token context window at just 16 frames.
|
| 44 |
-
assert vlm_models.InternVLAdapter.chat_template_kwargs == {"crop_to_patches": False}
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def test_numbered_content_labels_every_frame_in_order():
|
| 48 |
-
frames = ["frame0", "frame1", "frame2"]
|
| 49 |
-
content = vlm_models._numbered_content(frames, "What is in the room?")
|
| 50 |
-
assert content[0] == {"type": "text", "text": "Frame 1:"}
|
| 51 |
-
assert content[1] == {"type": "image", "image": "frame0"}
|
| 52 |
-
assert content[-1] == {"type": "text", "text": "What is in the room?"}
|
| 53 |
-
image_items = [item for item in content if item["type"] == "image"]
|
| 54 |
-
assert [item["image"] for item in image_items] == frames
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
def test_numbered_content_handles_zero_frames():
|
| 58 |
-
content = vlm_models._numbered_content([], "question only")
|
| 59 |
-
assert content == [{"type": "text", "text": "question only"}]
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
def test_adapter_answer_before_load_model_raises():
|
| 63 |
-
adapter = vlm_models.get_adapter("qwen3.5-2b")
|
| 64 |
-
with pytest.raises(RuntimeError):
|
| 65 |
-
adapter.answer(["frame"], "question")
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
def test_adapter_answer_extended_before_load_model_raises():
|
| 69 |
-
adapter = vlm_models.get_adapter("qwen3.5-2b")
|
| 70 |
-
with pytest.raises(RuntimeError):
|
| 71 |
-
adapter.answer_extended(["frame"], "question")
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
def test_every_adapter_implements_answer_extended():
|
| 75 |
-
for model in vlm_models.available_models():
|
| 76 |
-
adapter = vlm_models.get_adapter(model)
|
| 77 |
-
assert callable(adapter.answer_extended)
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
def test_unload_clears_model_and_processor():
|
| 81 |
-
adapter = vlm_models.get_adapter("qwen3.5-2b")
|
| 82 |
-
adapter.model = object()
|
| 83 |
-
adapter.processor = object()
|
| 84 |
-
adapter.unload()
|
| 85 |
-
assert adapter.model is None
|
| 86 |
-
assert adapter.processor is None
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
def test_native_video_content_uses_one_video_item():
|
| 90 |
-
content = vlm_models._numbered_content("/data/scene.mp4", "What is in the room?")
|
| 91 |
-
assert content == [
|
| 92 |
-
{"type": "video", "video": "/data/scene.mp4"},
|
| 93 |
-
{"type": "text", "text": "What is in the room?"},
|
| 94 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_A/test_prompts.py
DELETED
|
@@ -1,55 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/A/prompts.py -- VSI-Bench prompt construction."""
|
| 2 |
-
|
| 3 |
-
import pytest
|
| 4 |
-
|
| 5 |
-
from harness.A import prompts as vsi_prompts
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def test_na_question_prompt_matches_vsibench_protocol():
|
| 9 |
-
prompt = vsi_prompts.build_prompt("object_counting", "How many chairs?")
|
| 10 |
-
assert prompt == (
|
| 11 |
-
"These are frames of a video.\n"
|
| 12 |
-
"How many chairs?\n"
|
| 13 |
-
"Please answer the question using a single word or phrase."
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
def test_mca_question_prompt_matches_vsibench_protocol():
|
| 18 |
-
prompt = vsi_prompts.build_prompt(
|
| 19 |
-
"object_rel_distance", "Which is closest?", ["A. sofa", "B. table"]
|
| 20 |
-
)
|
| 21 |
-
assert prompt == (
|
| 22 |
-
"These are frames of a video.\n"
|
| 23 |
-
"Which is closest?\n"
|
| 24 |
-
"Options:\nA. sofa\nB. table\n"
|
| 25 |
-
"Answer with the option's letter from the given choices directly."
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
def test_mca_question_requires_options():
|
| 30 |
-
with pytest.raises(ValueError):
|
| 31 |
-
vsi_prompts.build_prompt("route_planning", "Which way?", None)
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
def test_unknown_question_type_rejected():
|
| 35 |
-
with pytest.raises(ValueError):
|
| 36 |
-
vsi_prompts.build_prompt("not_a_real_type", "?", None)
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
@pytest.mark.parametrize("question_type", vsi_prompts.NA_QUESTION_TYPES)
|
| 40 |
-
def test_every_na_question_type_builds_without_options(question_type):
|
| 41 |
-
prompt = vsi_prompts.build_prompt(question_type, "q?")
|
| 42 |
-
assert prompt.startswith(vsi_prompts.PRE_PROMPT)
|
| 43 |
-
assert prompt.endswith(vsi_prompts.NA_POST_PROMPT)
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
@pytest.mark.parametrize("question_type", vsi_prompts.MCA_QUESTION_TYPES)
|
| 47 |
-
def test_every_mca_question_type_builds_with_options(question_type):
|
| 48 |
-
prompt = vsi_prompts.build_prompt(question_type, "q?", ["A. x", "B. y"])
|
| 49 |
-
assert prompt.startswith(vsi_prompts.PRE_PROMPT)
|
| 50 |
-
assert prompt.endswith(vsi_prompts.MCA_POST_PROMPT)
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
def test_video_prompt_names_native_video():
|
| 54 |
-
prompt = vsi_prompts.build_prompt("object_counting", "How many chairs?", video=True)
|
| 55 |
-
assert prompt.startswith("This is a video.\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_A/test_run.py
DELETED
|
@@ -1,229 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/A/run.py -- question loading, scoring, and result-file writing."""
|
| 2 |
-
|
| 3 |
-
import json
|
| 4 |
-
|
| 5 |
-
import pytest
|
| 6 |
-
|
| 7 |
-
from harness import A
|
| 8 |
-
from harness.A import run as harness_run
|
| 9 |
-
|
| 10 |
-
_FAKE_ANSWER = {
|
| 11 |
-
"prompt_text": "<rendered chat template>",
|
| 12 |
-
"answer_text": "4",
|
| 13 |
-
"answer_raw": "<|im_start|>assistant\n4<|im_end|>",
|
| 14 |
-
"input_token_count": 123,
|
| 15 |
-
"vision_input_shapes": {"pixel_values": [512, 1536]},
|
| 16 |
-
"output_token_ids": [19, 151645],
|
| 17 |
-
"output_token_count": 2,
|
| 18 |
-
"hit_token_limit": False,
|
| 19 |
-
"eos_token_ids": [151645],
|
| 20 |
-
"generation_seconds": 1.234,
|
| 21 |
-
"device": "cuda",
|
| 22 |
-
"dtype": "bfloat16",
|
| 23 |
-
"library_versions": {"transformers": "5.14.1", "torch": "2.13.0+cu130"},
|
| 24 |
-
"generation_config": {
|
| 25 |
-
"max_new_tokens": 16,
|
| 26 |
-
"do_sample": False,
|
| 27 |
-
"temperature": 0.0,
|
| 28 |
-
"top_p": None,
|
| 29 |
-
"top_k": None,
|
| 30 |
-
},
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
_FAKE_ROW = {
|
| 34 |
-
"id": 7,
|
| 35 |
-
"scene_name": "scene0001_00",
|
| 36 |
-
"dataset": "scannet",
|
| 37 |
-
"question_type": "object_counting",
|
| 38 |
-
"question": "How many chairs?",
|
| 39 |
-
"options": None,
|
| 40 |
-
"ground_truth": "4",
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
_FAKE_FRAME_INFO = {
|
| 44 |
-
"protocol": "base",
|
| 45 |
-
"video_path": "/root/data/VSI-Bench/scannet/scene0001_00.mp4",
|
| 46 |
-
"frame_timestamps": [0.0, 1.0, 2.0],
|
| 47 |
-
"frame_indices": [0, 30, 60],
|
| 48 |
-
"frame_selection": "uniform",
|
| 49 |
-
"frame_count": 16,
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
def test_load_questions_reads_every_row(tmp_path):
|
| 54 |
-
jsonl = tmp_path / "test.jsonl"
|
| 55 |
-
jsonl.write_text(
|
| 56 |
-
"\n".join(
|
| 57 |
-
json.dumps({"id": i, "scene_name": f"scene{i}", "question": "q"})
|
| 58 |
-
for i in range(3)
|
| 59 |
-
)
|
| 60 |
-
)
|
| 61 |
-
rows = harness_run.load_questions(jsonl)
|
| 62 |
-
assert [r["id"] for r in rows] == [0, 1, 2]
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
def test_load_questions_filters_by_scene(tmp_path):
|
| 66 |
-
jsonl = tmp_path / "test.jsonl"
|
| 67 |
-
jsonl.write_text(
|
| 68 |
-
"\n".join(
|
| 69 |
-
json.dumps({"id": i, "scene_name": "a" if i < 2 else "b", "question": "q"})
|
| 70 |
-
for i in range(4)
|
| 71 |
-
)
|
| 72 |
-
)
|
| 73 |
-
rows = harness_run.load_questions(jsonl, scene="b")
|
| 74 |
-
assert [r["id"] for r in rows] == [2, 3]
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
def test_load_questions_respects_limit(tmp_path):
|
| 78 |
-
jsonl = tmp_path / "test.jsonl"
|
| 79 |
-
jsonl.write_text(
|
| 80 |
-
"\n".join(
|
| 81 |
-
json.dumps({"id": i, "scene_name": "a", "question": "q"}) for i in range(5)
|
| 82 |
-
)
|
| 83 |
-
)
|
| 84 |
-
rows = harness_run.load_questions(jsonl, limit=2)
|
| 85 |
-
assert [r["id"] for r in rows] == [0, 1]
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
def test_scalar_score_returns_metric_name_and_value():
|
| 89 |
-
doc = {"question_type": "object_counting", "ground_truth": "4"}
|
| 90 |
-
score_doc = harness_run.vsi_official_eval.vsibench_process_results(doc, ["4"])[
|
| 91 |
-
"vsibench_score"
|
| 92 |
-
]
|
| 93 |
-
metric_name, value = harness_run._scalar_score("object_counting", score_doc)
|
| 94 |
-
assert metric_name == "MRA:.5:.95:.05"
|
| 95 |
-
assert value == 1.0
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
def test_scalar_score_rejects_unknown_question_type():
|
| 99 |
-
with pytest.raises(ValueError):
|
| 100 |
-
harness_run._scalar_score("not_a_real_type", {})
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
def test_results_dir_for_matches_established_dimension_nesting():
|
| 104 |
-
root = harness_run.results_dir_for("qwen3.5-4b", "base", "selective", 32)
|
| 105 |
-
assert root == A.RESULTS_DIR / "qwen3.5-4b" / "selective" / "32"
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
def test_results_dir_for_keeps_protocols_together():
|
| 109 |
-
base = harness_run.results_dir_for("qwen3.5-4b", "base", "selective", 32)
|
| 110 |
-
extended = harness_run.results_dir_for("qwen3.5-4b", "thinking", "selective", 32)
|
| 111 |
-
assert base == extended
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
def test_results_dir_for_honors_explicit_override(tmp_path):
|
| 115 |
-
assert (
|
| 116 |
-
harness_run.results_dir_for("qwen3.5-4b", "base", "uniform", 16, tmp_path)
|
| 117 |
-
== tmp_path
|
| 118 |
-
)
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
def test_build_record_preserves_every_field_untruncated():
|
| 122 |
-
record = harness_run._build_record(
|
| 123 |
-
_FAKE_ROW,
|
| 124 |
-
"full prompt text",
|
| 125 |
-
_FAKE_ANSWER,
|
| 126 |
-
"MRA:.5:.95:.05",
|
| 127 |
-
1.0,
|
| 128 |
-
"qwen3.5-4b",
|
| 129 |
-
"/root/models/qwen3.5-4b",
|
| 130 |
-
_FAKE_FRAME_INFO,
|
| 131 |
-
)
|
| 132 |
-
assert record["question"] == "How many chairs?"
|
| 133 |
-
assert record["full_prompt"] == "full prompt text"
|
| 134 |
-
assert record["rendered_prompt"] == _FAKE_ANSWER["prompt_text"]
|
| 135 |
-
assert record["answer_given"] == "4"
|
| 136 |
-
assert record["answer_raw"] == _FAKE_ANSWER["answer_raw"]
|
| 137 |
-
assert record["output_token_ids"] == [19, 151645]
|
| 138 |
-
assert record["output_token_count"] == 2
|
| 139 |
-
assert record["hit_token_limit"] is False
|
| 140 |
-
assert record["generation_config"] == _FAKE_ANSWER["generation_config"]
|
| 141 |
-
assert record["frame_timestamps_seconds"] == [0.0, 1.0, 2.0]
|
| 142 |
-
assert record["frame_indices"] == [0, 30, 60]
|
| 143 |
-
assert record["video_path"] == _FAKE_FRAME_INFO["video_path"]
|
| 144 |
-
assert record["device"] == "cuda"
|
| 145 |
-
assert record["dtype"] == "bfloat16"
|
| 146 |
-
assert record["library_versions"] == _FAKE_ANSWER["library_versions"]
|
| 147 |
-
assert record["vision_input_shapes"] == {"pixel_values": [512, 1536]}
|
| 148 |
-
assert record["generation_seconds"] == 1.234
|
| 149 |
-
assert record["metric"] == "MRA:.5:.95:.05"
|
| 150 |
-
assert record["score"] == 1.0
|
| 151 |
-
assert record["scene"] == "scene0001_00"
|
| 152 |
-
assert record["question_id"] == 7
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
def test_write_question_result_writes_one_json_file_per_question(tmp_path):
|
| 156 |
-
path, record = harness_run.write_question_result(
|
| 157 |
-
_FAKE_ROW,
|
| 158 |
-
"full prompt text",
|
| 159 |
-
_FAKE_ANSWER,
|
| 160 |
-
"MRA:.5:.95:.05",
|
| 161 |
-
1.0,
|
| 162 |
-
"qwen3.5-4b",
|
| 163 |
-
"/root/models/qwen3.5-4b",
|
| 164 |
-
_FAKE_FRAME_INFO,
|
| 165 |
-
results_dir=tmp_path,
|
| 166 |
-
)
|
| 167 |
-
assert path == tmp_path / "scene0001_00" / "7.json"
|
| 168 |
-
on_disk = json.loads(path.read_text())
|
| 169 |
-
assert on_disk == record
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
def test_build_record_defaults_reasoning_fields_when_not_extended():
|
| 173 |
-
record = harness_run._build_record(
|
| 174 |
-
_FAKE_ROW,
|
| 175 |
-
"full prompt text",
|
| 176 |
-
_FAKE_ANSWER,
|
| 177 |
-
"MRA:.5:.95:.05",
|
| 178 |
-
1.0,
|
| 179 |
-
"qwen3.5-4b",
|
| 180 |
-
"/root/models/qwen3.5-4b",
|
| 181 |
-
_FAKE_FRAME_INFO,
|
| 182 |
-
)
|
| 183 |
-
assert record["reasoning_text"] is None
|
| 184 |
-
assert record["forced"] is False
|
| 185 |
-
assert record["forced_input_token_count"] is None
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
def test_build_record_carries_reasoning_fields_when_extended():
|
| 189 |
-
extended_answer = {
|
| 190 |
-
**_FAKE_ANSWER,
|
| 191 |
-
"reasoning_text": "long reasoning about the scene",
|
| 192 |
-
"reasoning_raw": "long reasoning about the scene<|im_end|>",
|
| 193 |
-
"reasoning_token_ids": list(range(50)),
|
| 194 |
-
"reasoning_token_count": 50,
|
| 195 |
-
"reasoning_hit_limit": True,
|
| 196 |
-
"forced": True,
|
| 197 |
-
"forced_input_token_count": 2510,
|
| 198 |
-
}
|
| 199 |
-
record = harness_run._build_record(
|
| 200 |
-
_FAKE_ROW,
|
| 201 |
-
"full prompt text",
|
| 202 |
-
extended_answer,
|
| 203 |
-
"MRA:.5:.95:.05",
|
| 204 |
-
1.0,
|
| 205 |
-
"qwen3.5-4b",
|
| 206 |
-
"/root/models/qwen3.5-4b",
|
| 207 |
-
_FAKE_FRAME_INFO,
|
| 208 |
-
)
|
| 209 |
-
assert record["reasoning_text"] == "long reasoning about the scene"
|
| 210 |
-
assert record["reasoning_token_count"] == 50
|
| 211 |
-
assert record["reasoning_hit_limit"] is True
|
| 212 |
-
assert record["forced"] is True
|
| 213 |
-
assert record["forced_input_token_count"] == 2510
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
def test_video_results_use_video_branch():
|
| 217 |
-
assert (
|
| 218 |
-
harness_run.results_dir_for("qwen3.5-4b", "thinking", "video", None)
|
| 219 |
-
== A.RESULTS_DIR / "qwen3.5-4b" / "video"
|
| 220 |
-
)
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
def test_video_record_has_no_frame_count_in_condition():
|
| 224 |
-
info = dict(_FAKE_FRAME_INFO, frame_selection="video", frame_count=None)
|
| 225 |
-
record = harness_run._build_record(
|
| 226 |
-
_FAKE_ROW, "prompt", _FAKE_ANSWER, "metric", 1.0, "qwen3.5-4b", "/model", info
|
| 227 |
-
)
|
| 228 |
-
assert record["condition"] == "base:video"
|
| 229 |
-
assert record["frame_count"] is None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_A/test_sweep.py
DELETED
|
@@ -1,69 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/A/sweep.py -- multi-config sweep planning."""
|
| 2 |
-
|
| 3 |
-
import pytest
|
| 4 |
-
|
| 5 |
-
from harness.A import models as vlm_models
|
| 6 |
-
from harness.A import sweep
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
def test_parse_csv_choice_splits_and_dedups():
|
| 10 |
-
result = sweep._parse_csv_choice(
|
| 11 |
-
"uniform,selective,uniform", ("uniform", "selective"), "--x"
|
| 12 |
-
)
|
| 13 |
-
assert result == ["uniform", "selective"]
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def test_parse_csv_choice_expands_all():
|
| 17 |
-
result = sweep._parse_csv_choice("all", ("uniform", "selective"), "--x")
|
| 18 |
-
assert result == ["uniform", "selective"]
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
def test_parse_csv_choice_rejects_unknown_value():
|
| 22 |
-
with pytest.raises(ValueError):
|
| 23 |
-
sweep._parse_csv_choice("uniform,bogus", ("uniform", "selective"), "--x")
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
def test_parse_csv_choice_rejects_empty():
|
| 27 |
-
with pytest.raises(ValueError):
|
| 28 |
-
sweep._parse_csv_choice("", ("uniform", "selective"), "--x")
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
def test_parse_frame_counts_splits_and_dedups():
|
| 32 |
-
assert sweep._parse_frame_counts("16,32,64,32") == [16, 32, 64]
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
def test_parse_frame_counts_rejects_nonpositive():
|
| 36 |
-
with pytest.raises(ValueError):
|
| 37 |
-
sweep._parse_frame_counts("16,0,64")
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
def test_parse_frame_counts_rejects_non_integer():
|
| 41 |
-
with pytest.raises(ValueError):
|
| 42 |
-
sweep._parse_frame_counts("16,abc")
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
def test_build_plan_covers_every_combination():
|
| 46 |
-
plan = sweep.build_plan(
|
| 47 |
-
["qwen3.5-2b", "qwen3.5-4b"], ["uniform", "selective"], [16, 32]
|
| 48 |
-
)
|
| 49 |
-
assert len(plan) == 2 * 2 * 2
|
| 50 |
-
assert set(plan) == {
|
| 51 |
-
("qwen3.5-2b", "uniform", 16),
|
| 52 |
-
("qwen3.5-2b", "uniform", 32),
|
| 53 |
-
("qwen3.5-2b", "selective", 16),
|
| 54 |
-
("qwen3.5-2b", "selective", 32),
|
| 55 |
-
("qwen3.5-4b", "uniform", 16),
|
| 56 |
-
("qwen3.5-4b", "uniform", 32),
|
| 57 |
-
("qwen3.5-4b", "selective", 16),
|
| 58 |
-
("qwen3.5-4b", "selective", 32),
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
def test_build_plan_orders_by_frame_count_first():
|
| 63 |
-
plan = sweep.build_plan(["qwen3.5-2b"], ["uniform"], [64, 16, 32])
|
| 64 |
-
assert [frame_count for _model, _selection, frame_count in plan] == [16, 32, 64]
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
def test_build_plan_with_all_registered_models():
|
| 68 |
-
plan = sweep.build_plan(list(vlm_models.available_models()), ["uniform"], [16])
|
| 69 |
-
assert len(plan) == len(vlm_models.available_models())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_B/__init__.py
DELETED
|
File without changes
|
tests/test_B/conftest.py
DELETED
|
@@ -1,12 +0,0 @@
|
|
| 1 |
-
"""Shared import setup for harness.B tests."""
|
| 2 |
-
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
import sys
|
| 5 |
-
|
| 6 |
-
ROOT = Path(__file__).resolve().parents[2]
|
| 7 |
-
if str(ROOT) not in sys.path:
|
| 8 |
-
sys.path.insert(0, str(ROOT))
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def pytest_configure(config):
|
| 12 |
-
config.option.importmode = "importlib"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_B/test_B.py
DELETED
|
@@ -1,35 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/B/__init__.py -- shared config constants."""
|
| 2 |
-
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
|
| 5 |
-
from harness import A, B
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def test_spatial_code_formats_is_explicit_only():
|
| 9 |
-
assert B.SPATIAL_CODE_FORMATS == ("explicit",)
|
| 10 |
-
assert B.DEFAULT_SPATIAL_CODE_FORMAT in B.SPATIAL_CODE_FORMATS
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def test_input_selections_match_harness_a_vocabulary():
|
| 14 |
-
assert B.INPUT_SELECTIONS == A.FRAME_SELECTIONS
|
| 15 |
-
assert B.DEFAULT_INPUT_SELECTION in B.INPUT_SELECTIONS
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def test_reuses_harness_a_model_paths_and_generation_protocol():
|
| 19 |
-
assert B.MODEL_PATHS is A.MODEL_PATHS
|
| 20 |
-
assert B.MAX_NEW_TOKENS == A.MAX_NEW_TOKENS
|
| 21 |
-
assert B.DO_SAMPLE == A.DO_SAMPLE
|
| 22 |
-
assert B.TEMPERATURE == A.TEMPERATURE
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
def test_results_dir_defaults_under_root_results():
|
| 26 |
-
assert B.RESULTS_DIR == Path("/root/results/B")
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
def test_depth_and_tracking_reuse_encoder_config_vocabulary():
|
| 30 |
-
from encoder.config import DEPTH_VARIANTS, TRACKING_MODES
|
| 31 |
-
|
| 32 |
-
assert B.DEPTH_VARIANTS == DEPTH_VARIANTS
|
| 33 |
-
assert B.TRACKING_MODES == TRACKING_MODES
|
| 34 |
-
assert B.DEFAULT_DEPTH in B.DEPTH_VARIANTS
|
| 35 |
-
assert B.DEFAULT_TRACKING in B.TRACKING_MODES
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_B/test_init.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/B/__init__.py -- shared config constants."""
|
| 2 |
-
|
| 3 |
-
from harness import A, B
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def test_spatial_code_formats_is_explicit_only():
|
| 7 |
-
assert B.SPATIAL_CODE_FORMATS == ("explicit",)
|
| 8 |
-
assert B.DEFAULT_SPATIAL_CODE_FORMAT in B.SPATIAL_CODE_FORMATS
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def test_input_selections_match_harness_a_vocabulary():
|
| 12 |
-
assert B.INPUT_SELECTIONS == A.FRAME_SELECTIONS
|
| 13 |
-
assert B.DEFAULT_INPUT_SELECTION in B.INPUT_SELECTIONS
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def test_reuses_harness_a_model_paths_and_generation_protocol():
|
| 17 |
-
assert B.MODEL_PATHS is A.MODEL_PATHS
|
| 18 |
-
assert B.MAX_NEW_TOKENS == A.MAX_NEW_TOKENS
|
| 19 |
-
assert B.DO_SAMPLE == A.DO_SAMPLE
|
| 20 |
-
assert B.TEMPERATURE == A.TEMPERATURE
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def test_results_dir_defaults_under_workspace_results():
|
| 24 |
-
assert B.RESULTS_DIR == B.WORKSPACE_ROOT / "results" / "B"
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
def test_depth_and_tracking_reuse_encoder_config_vocabulary():
|
| 28 |
-
from encoder.config import DEPTH_VARIANTS, TRACKING_MODES
|
| 29 |
-
|
| 30 |
-
assert B.DEPTH_VARIANTS == DEPTH_VARIANTS
|
| 31 |
-
assert B.TRACKING_MODES == TRACKING_MODES
|
| 32 |
-
assert B.DEFAULT_DEPTH in B.DEPTH_VARIANTS
|
| 33 |
-
assert B.DEFAULT_TRACKING in B.TRACKING_MODES
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_B/test_launch.py
DELETED
|
@@ -1,85 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/B/launch.py -- multi-GPU scene sharding across workers."""
|
| 2 |
-
|
| 3 |
-
import pytest
|
| 4 |
-
|
| 5 |
-
from harness.B import launch
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def test_launcher_imports():
|
| 9 |
-
assert callable(launch.main)
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
class _FakeRun:
|
| 13 |
-
rows = [{"id": 1}, {"id": 3}]
|
| 14 |
-
|
| 15 |
-
@staticmethod
|
| 16 |
-
def results_dir_for(*args, **kwargs):
|
| 17 |
-
return args[-1]
|
| 18 |
-
|
| 19 |
-
@classmethod
|
| 20 |
-
def load_questions(cls, scene=None):
|
| 21 |
-
return list(cls.rows)
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
def test_launch_skips_scene_already_fully_answered(tmp_path, capsys, monkeypatch):
|
| 25 |
-
scene = "scene-b"
|
| 26 |
-
monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun)
|
| 27 |
-
|
| 28 |
-
scene_dir = tmp_path / scene
|
| 29 |
-
scene_dir.mkdir()
|
| 30 |
-
for row in _FakeRun.rows:
|
| 31 |
-
(scene_dir / f"{row['id']}.json").write_text("{}")
|
| 32 |
-
|
| 33 |
-
launch.launch(
|
| 34 |
-
"qwen3.5-2b", "explicit", "selective", 64, [scene], results_dir=tmp_path
|
| 35 |
-
)
|
| 36 |
-
|
| 37 |
-
output = capsys.readouterr().out
|
| 38 |
-
assert "skipped" in output
|
| 39 |
-
assert "DONE: 1 ok, 0 failed" in output
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
def test_launch_rebuild_forces_pending_even_when_answered(tmp_path, monkeypatch):
|
| 43 |
-
scene = "scene-b"
|
| 44 |
-
monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun)
|
| 45 |
-
scene_dir = tmp_path / scene
|
| 46 |
-
scene_dir.mkdir()
|
| 47 |
-
for row in _FakeRun.rows:
|
| 48 |
-
(scene_dir / f"{row['id']}.json").write_text("{}")
|
| 49 |
-
|
| 50 |
-
monkeypatch.setattr(launch, "visible_gpus", lambda: [])
|
| 51 |
-
monkeypatch.setattr(
|
| 52 |
-
launch.mp,
|
| 53 |
-
"get_context",
|
| 54 |
-
lambda *_: (_ for _ in ()).throw(
|
| 55 |
-
RuntimeError("rebuild correctly reached worker dispatch")
|
| 56 |
-
),
|
| 57 |
-
)
|
| 58 |
-
try:
|
| 59 |
-
launch.launch(
|
| 60 |
-
"qwen3.5-2b",
|
| 61 |
-
"explicit",
|
| 62 |
-
"selective",
|
| 63 |
-
64,
|
| 64 |
-
[scene],
|
| 65 |
-
results_dir=tmp_path,
|
| 66 |
-
rebuild=True,
|
| 67 |
-
)
|
| 68 |
-
except RuntimeError as exc:
|
| 69 |
-
assert "rebuild correctly reached worker dispatch" in str(exc)
|
| 70 |
-
else:
|
| 71 |
-
raise AssertionError("expected rebuild to force scene into the pending path")
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
def test_launch_rejects_question_id_filter_that_matches_nothing(monkeypatch, tmp_path):
|
| 75 |
-
monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun)
|
| 76 |
-
with pytest.raises(ValueError, match="no questions found"):
|
| 77 |
-
launch.launch(
|
| 78 |
-
"qwen3.5-2b",
|
| 79 |
-
"explicit",
|
| 80 |
-
"selective",
|
| 81 |
-
64,
|
| 82 |
-
["scene-b"],
|
| 83 |
-
results_dir=tmp_path,
|
| 84 |
-
question_ids={999},
|
| 85 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_B/test_prompts.py
DELETED
|
@@ -1,103 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/B/prompts.py -- spatial-code-as-text prompt construction."""
|
| 2 |
-
|
| 3 |
-
import json
|
| 4 |
-
|
| 5 |
-
import pytest
|
| 6 |
-
|
| 7 |
-
from harness.A.prompts import MCA_QUESTION_TYPES, NA_QUESTION_TYPES
|
| 8 |
-
from harness.B import prompts as code_prompts
|
| 9 |
-
|
| 10 |
-
_CODE = {
|
| 11 |
-
"objects": {"chair": {"count": 1}},
|
| 12 |
-
"room": {"floor area": "10.0 square meters"},
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def test_na_question_prompt_embeds_the_spatial_code_as_text_and_a_post_prompt():
|
| 17 |
-
prompt = code_prompts.build_prompt(_CODE, "object_counting", "How many chairs?")
|
| 18 |
-
assert prompt.startswith(code_prompts.PRE_PROMPT)
|
| 19 |
-
assert json.dumps(_CODE, indent=1) in prompt
|
| 20 |
-
assert prompt.endswith(code_prompts.NA_POST_PROMPT)
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def test_mca_question_prompt_includes_options_and_matches_harness_a_post_prompt():
|
| 24 |
-
prompt = code_prompts.build_prompt(
|
| 25 |
-
_CODE, "object_rel_distance", "Which is closest?", ["A. sofa", "B. table"]
|
| 26 |
-
)
|
| 27 |
-
assert "Options:\nA. sofa\nB. table" in prompt
|
| 28 |
-
assert prompt.endswith(code_prompts.MCA_POST_PROMPT)
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
def test_mca_question_requires_options():
|
| 32 |
-
with pytest.raises(ValueError):
|
| 33 |
-
code_prompts.build_prompt(_CODE, "route_planning", "Which way?", None)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
def test_unknown_question_type_rejected():
|
| 37 |
-
with pytest.raises(ValueError):
|
| 38 |
-
code_prompts.build_prompt(_CODE, "not_a_real_type", "?", None)
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
def test_no_frames_language_in_pre_prompt():
|
| 42 |
-
# B has no video frames -- the context line must not claim otherwise.
|
| 43 |
-
assert "frame" not in code_prompts.PRE_PROMPT.lower()
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
@pytest.mark.parametrize("question_type", NA_QUESTION_TYPES)
|
| 47 |
-
def test_every_na_question_type_builds(question_type):
|
| 48 |
-
prompt = code_prompts.build_prompt(_CODE, question_type, "q?")
|
| 49 |
-
assert prompt.startswith(code_prompts.PRE_PROMPT)
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
@pytest.mark.parametrize("question_type", MCA_QUESTION_TYPES)
|
| 53 |
-
def test_every_mca_question_type_builds(question_type):
|
| 54 |
-
prompt = code_prompts.build_prompt(_CODE, question_type, "q?", ["A. x", "B. y"])
|
| 55 |
-
assert prompt.startswith(code_prompts.PRE_PROMPT)
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
def test_default_arguments_reproduce_the_standard_prompt_byte_for_byte():
|
| 59 |
-
standard = code_prompts.build_prompt(_CODE, "object_counting", "How many chairs?")
|
| 60 |
-
explicit_defaults = code_prompts.build_prompt(
|
| 61 |
-
_CODE,
|
| 62 |
-
"object_counting",
|
| 63 |
-
"How many chairs?",
|
| 64 |
-
serialization="json",
|
| 65 |
-
context_line=None,
|
| 66 |
-
)
|
| 67 |
-
assert standard == explicit_defaults
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
def test_yaml_serialization_renders_the_identical_dict():
|
| 71 |
-
import yaml
|
| 72 |
-
|
| 73 |
-
prompt = code_prompts.build_prompt(
|
| 74 |
-
_CODE, "object_counting", "How many chairs?", serialization="yaml"
|
| 75 |
-
)
|
| 76 |
-
rendered = prompt.split("\n", 1)[1].rsplit("How many chairs?", 1)[0]
|
| 77 |
-
assert yaml.safe_load(rendered) == _CODE
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
def test_yaml_arm_context_line_does_not_claim_json():
|
| 81 |
-
prompt = code_prompts.build_prompt(
|
| 82 |
-
_CODE, "object_counting", "How many chairs?", serialization="yaml"
|
| 83 |
-
)
|
| 84 |
-
context = prompt.split("\n", 1)[0]
|
| 85 |
-
assert "JSON" not in context
|
| 86 |
-
assert "YAML" in context
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
def test_paraphrase_context_line_swaps_only_the_first_line():
|
| 90 |
-
standard = code_prompts.build_prompt(_CODE, "object_counting", "How many chairs?")
|
| 91 |
-
paraphrased = code_prompts.build_prompt(
|
| 92 |
-
_CODE,
|
| 93 |
-
"object_counting",
|
| 94 |
-
"How many chairs?",
|
| 95 |
-
context_line=code_prompts.PARAPHRASE_PRE_PROMPT,
|
| 96 |
-
)
|
| 97 |
-
assert standard.split("\n", 1)[1] == paraphrased.split("\n", 1)[1]
|
| 98 |
-
assert standard.split("\n", 1)[0] != paraphrased.split("\n", 1)[0]
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
def test_unknown_serialization_rejected():
|
| 102 |
-
with pytest.raises(ValueError):
|
| 103 |
-
code_prompts.render_code(_CODE, "xml")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_B/test_run.py
DELETED
|
@@ -1,231 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/B/run.py -- result-record shape and result-file writing."""
|
| 2 |
-
|
| 3 |
-
import json
|
| 4 |
-
|
| 5 |
-
from harness import B
|
| 6 |
-
from harness.B import run as harness_run
|
| 7 |
-
|
| 8 |
-
_FAKE_ANSWER = {
|
| 9 |
-
"prompt_text": "<rendered chat template>",
|
| 10 |
-
"answer_text": "4",
|
| 11 |
-
"answer_raw": "<|im_start|>assistant\n4<|im_end|>",
|
| 12 |
-
"input_token_count": 2558,
|
| 13 |
-
"vision_input_shapes": {"mm_token_type_ids": [1, 2558]},
|
| 14 |
-
"output_token_ids": [19, 151645],
|
| 15 |
-
"output_token_count": 2,
|
| 16 |
-
"hit_token_limit": False,
|
| 17 |
-
"eos_token_ids": [151645],
|
| 18 |
-
"generation_seconds": 0.65,
|
| 19 |
-
"device": "cuda",
|
| 20 |
-
"dtype": "bfloat16",
|
| 21 |
-
"library_versions": {"transformers": "5.14.1", "torch": "2.13.0+cu130"},
|
| 22 |
-
"generation_config": {
|
| 23 |
-
"max_new_tokens": 16,
|
| 24 |
-
"do_sample": False,
|
| 25 |
-
"temperature": 0.0,
|
| 26 |
-
"top_p": None,
|
| 27 |
-
"top_k": None,
|
| 28 |
-
"enable_thinking": False,
|
| 29 |
-
},
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
_FAKE_ROW = {
|
| 33 |
-
"id": 7,
|
| 34 |
-
"scene_name": "scene0001_00",
|
| 35 |
-
"dataset": "scannet",
|
| 36 |
-
"question_type": "object_counting",
|
| 37 |
-
"question": "How many chairs?",
|
| 38 |
-
"options": None,
|
| 39 |
-
"ground_truth": "4",
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
_FAKE_CODE_INFO = {
|
| 43 |
-
"protocol": "thinking",
|
| 44 |
-
"spatial_code_format": "explicit",
|
| 45 |
-
"input_selection": "selective",
|
| 46 |
-
"frame_count": 64,
|
| 47 |
-
"depth": "metric",
|
| 48 |
-
"tracking": "tracking",
|
| 49 |
-
"spatial_code_path": "/workspace/data/spatial codes/.../scene0001_00.json",
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
def test_results_dir_for_matches_established_dimension_nesting():
|
| 54 |
-
root = harness_run.results_dir_for(
|
| 55 |
-
"qwen3.5-4b", "thinking", "explicit", "metric", "tracking", "uniform", 32
|
| 56 |
-
)
|
| 57 |
-
assert root == (
|
| 58 |
-
B.RESULTS_DIR
|
| 59 |
-
/ "qwen3.5-4b"
|
| 60 |
-
/ "explicit"
|
| 61 |
-
/ "metric"
|
| 62 |
-
/ "tracking"
|
| 63 |
-
/ "uniform"
|
| 64 |
-
/ "32"
|
| 65 |
-
)
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
def test_results_dir_for_keeps_protocols_together():
|
| 69 |
-
base = harness_run.results_dir_for(
|
| 70 |
-
"qwen3.5-4b", "base", "explicit", "metric", "tracking", "uniform", 32
|
| 71 |
-
)
|
| 72 |
-
extended = harness_run.results_dir_for(
|
| 73 |
-
"qwen3.5-4b", "thinking", "explicit", "metric", "tracking", "uniform", 32
|
| 74 |
-
)
|
| 75 |
-
assert base == extended
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
def test_results_dir_for_honors_explicit_override(tmp_path):
|
| 79 |
-
root = harness_run.results_dir_for(
|
| 80 |
-
"qwen3.5-4b",
|
| 81 |
-
"base",
|
| 82 |
-
"explicit",
|
| 83 |
-
"relative",
|
| 84 |
-
"no tracking",
|
| 85 |
-
"selective",
|
| 86 |
-
16,
|
| 87 |
-
tmp_path,
|
| 88 |
-
)
|
| 89 |
-
assert root == tmp_path
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
def test_build_record_preserves_every_field_untruncated():
|
| 93 |
-
record = harness_run._build_record(
|
| 94 |
-
_FAKE_ROW,
|
| 95 |
-
"full prompt text",
|
| 96 |
-
_FAKE_ANSWER,
|
| 97 |
-
"MRA:.5:.95:.05",
|
| 98 |
-
1.0,
|
| 99 |
-
"qwen3.5-4b",
|
| 100 |
-
"/root/models/qwen3.5-4b",
|
| 101 |
-
_FAKE_CODE_INFO,
|
| 102 |
-
)
|
| 103 |
-
assert record["question"] == "How many chairs?"
|
| 104 |
-
assert record["full_prompt"] == "full prompt text"
|
| 105 |
-
assert record["rendered_prompt"] == _FAKE_ANSWER["prompt_text"]
|
| 106 |
-
assert record["answer_given"] == "4"
|
| 107 |
-
assert record["answer_raw"] == _FAKE_ANSWER["answer_raw"]
|
| 108 |
-
assert record["spatial_code_format"] == "explicit"
|
| 109 |
-
assert record["input_selection"] == "selective"
|
| 110 |
-
assert record["frame_count"] == 64
|
| 111 |
-
assert record["depth"] == "metric"
|
| 112 |
-
assert record["tracking"] == "tracking"
|
| 113 |
-
assert record["spatial_code_path"] == _FAKE_CODE_INFO["spatial_code_path"]
|
| 114 |
-
assert record["condition"] == "extended:explicit:metric:tracking:selective:64"
|
| 115 |
-
assert record["protocol"] == "thinking"
|
| 116 |
-
assert record["vision_input_shapes"] == {"mm_token_type_ids": [1, 2558]}
|
| 117 |
-
assert record["generation_config"] == _FAKE_ANSWER["generation_config"]
|
| 118 |
-
assert record["metric"] == "MRA:.5:.95:.05"
|
| 119 |
-
assert record["score"] == 1.0
|
| 120 |
-
assert record["scene"] == "scene0001_00"
|
| 121 |
-
assert record["question_id"] == 7
|
| 122 |
-
# No frame-provenance fields -- B has no video frames.
|
| 123 |
-
assert "frame_selection" not in record
|
| 124 |
-
assert "video_path" not in record
|
| 125 |
-
assert "frame_indices" not in record
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
def test_write_question_result_writes_one_json_file_per_question(tmp_path):
|
| 129 |
-
path, record = harness_run.write_question_result(
|
| 130 |
-
_FAKE_ROW,
|
| 131 |
-
"full prompt text",
|
| 132 |
-
_FAKE_ANSWER,
|
| 133 |
-
"MRA:.5:.95:.05",
|
| 134 |
-
1.0,
|
| 135 |
-
"qwen3.5-4b",
|
| 136 |
-
"/root/models/qwen3.5-4b",
|
| 137 |
-
_FAKE_CODE_INFO,
|
| 138 |
-
results_dir=tmp_path,
|
| 139 |
-
)
|
| 140 |
-
assert path == tmp_path / "scene0001_00" / "7.json"
|
| 141 |
-
on_disk = json.loads(path.read_text())
|
| 142 |
-
assert on_disk == record
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
def test_build_record_carries_reasoning_fields_when_forced():
|
| 146 |
-
extended_answer = {
|
| 147 |
-
**_FAKE_ANSWER,
|
| 148 |
-
"reasoning_text": "long reasoning about the spatial code",
|
| 149 |
-
"reasoning_raw": "long reasoning about the spatial code<|im_end|>",
|
| 150 |
-
"reasoning_token_ids": list(range(50)),
|
| 151 |
-
"reasoning_token_count": 50,
|
| 152 |
-
"reasoning_hit_limit": True,
|
| 153 |
-
"forced": True,
|
| 154 |
-
"forced_input_token_count": 2510,
|
| 155 |
-
}
|
| 156 |
-
record = harness_run._build_record(
|
| 157 |
-
_FAKE_ROW,
|
| 158 |
-
"full prompt text",
|
| 159 |
-
extended_answer,
|
| 160 |
-
"MRA:.5:.95:.05",
|
| 161 |
-
1.0,
|
| 162 |
-
"qwen3.5-4b",
|
| 163 |
-
"/root/models/qwen3.5-4b",
|
| 164 |
-
_FAKE_CODE_INFO,
|
| 165 |
-
)
|
| 166 |
-
assert record["reasoning_text"] == "long reasoning about the spatial code"
|
| 167 |
-
assert record["forced"] is True
|
| 168 |
-
assert record["forced_input_token_count"] == 2510
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
def test_run_strip_schema_legend_removes_only_the_legend(monkeypatch):
|
| 172 |
-
seen = {}
|
| 173 |
-
|
| 174 |
-
def fake_load(scene_id, depth, input_selection, tracking, frame_count, fmt):
|
| 175 |
-
return {
|
| 176 |
-
"spatial code schema": {"doc": 1},
|
| 177 |
-
"objects": {"chair": {"count": 1}},
|
| 178 |
-
}, "/fake.json"
|
| 179 |
-
|
| 180 |
-
class FakeAdapter:
|
| 181 |
-
model_path = "/fake/model"
|
| 182 |
-
|
| 183 |
-
def answer_extended(self, frames, prompt, **kwargs):
|
| 184 |
-
seen["prompt"] = prompt
|
| 185 |
-
return {
|
| 186 |
-
"prompt_text": prompt,
|
| 187 |
-
"answer_text": "1",
|
| 188 |
-
"answer_raw": "1",
|
| 189 |
-
"input_token_count": 1,
|
| 190 |
-
"vision_input_shapes": {},
|
| 191 |
-
"output_token_ids": [1],
|
| 192 |
-
"output_token_count": 1,
|
| 193 |
-
"hit_token_limit": False,
|
| 194 |
-
"eos_token_ids": [1],
|
| 195 |
-
"generation_seconds": 0.0,
|
| 196 |
-
"device": "cpu",
|
| 197 |
-
"dtype": "float32",
|
| 198 |
-
"library_versions": {},
|
| 199 |
-
"generation_config": {},
|
| 200 |
-
}
|
| 201 |
-
|
| 202 |
-
monkeypatch.setattr(harness_run.spatial_codes, "load_spatial_code", fake_load)
|
| 203 |
-
results = harness_run.run(
|
| 204 |
-
"qwen3.5-2b",
|
| 205 |
-
scene="13c3e046d7",
|
| 206 |
-
adapter=FakeAdapter(),
|
| 207 |
-
write_results=False,
|
| 208 |
-
limit=1,
|
| 209 |
-
strip_schema_legend=True,
|
| 210 |
-
)
|
| 211 |
-
assert results
|
| 212 |
-
assert "spatial code schema" not in seen["prompt"]
|
| 213 |
-
assert '"chair"' in seen["prompt"]
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
def test_video_results_use_video_branch():
|
| 217 |
-
assert (
|
| 218 |
-
harness_run.results_dir_for(
|
| 219 |
-
"qwen3.5-4b", "thinking", "explicit", "metric", "tracking", "video", None
|
| 220 |
-
)
|
| 221 |
-
== B.RESULTS_DIR / "qwen3.5-4b" / "explicit" / "metric" / "tracking" / "video"
|
| 222 |
-
)
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
def test_video_record_has_no_frame_count_in_condition():
|
| 226 |
-
info = dict(_FAKE_CODE_INFO, input_selection="video", frame_count=None)
|
| 227 |
-
record = harness_run._build_record(
|
| 228 |
-
_FAKE_ROW, "prompt", _FAKE_ANSWER, "metric", 1.0, "qwen3.5-4b", "/model", info
|
| 229 |
-
)
|
| 230 |
-
assert record["condition"] == "thinking:explicit:metric:tracking:video"
|
| 231 |
-
assert record["frame_count"] is None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_B/test_spatial_codes.py
DELETED
|
@@ -1,48 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/B/spatial_codes.py -- loading on-disk spatial codes as plain JSON."""
|
| 2 |
-
|
| 3 |
-
import json
|
| 4 |
-
|
| 5 |
-
import pytest
|
| 6 |
-
|
| 7 |
-
from harness.B import spatial_codes
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def test_load_spatial_code_rejects_unknown_format():
|
| 11 |
-
with pytest.raises(ValueError):
|
| 12 |
-
spatial_codes.load_spatial_code(
|
| 13 |
-
"scene", "metric", "selective", "tracking", 64, "bogus"
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
def test_load_spatial_code_raises_clearly_when_missing(tmp_path, monkeypatch):
|
| 18 |
-
monkeypatch.setattr(
|
| 19 |
-
spatial_codes,
|
| 20 |
-
"spatial_code_path",
|
| 21 |
-
lambda *a, **k: str(tmp_path / "missing.json"),
|
| 22 |
-
)
|
| 23 |
-
with pytest.raises(FileNotFoundError):
|
| 24 |
-
spatial_codes.load_spatial_code(
|
| 25 |
-
"scene", "metric", "selective", "tracking", 64, "explicit"
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
def test_load_spatial_code_returns_dict_and_path(tmp_path, monkeypatch):
|
| 30 |
-
fixture = tmp_path / "13c3e046d7.json"
|
| 31 |
-
fixture.write_text(json.dumps({"objects": {}, "room": {}}))
|
| 32 |
-
monkeypatch.setattr(
|
| 33 |
-
spatial_codes, "spatial_code_path", lambda *a, **k: str(fixture)
|
| 34 |
-
)
|
| 35 |
-
code, path = spatial_codes.load_spatial_code(
|
| 36 |
-
"13c3e046d7", "metric", "selective", "tracking", 64, "explicit"
|
| 37 |
-
)
|
| 38 |
-
assert code == {"objects": {}, "room": {}}
|
| 39 |
-
assert path == str(fixture)
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
def test_spatial_code_path_uses_tracking_frames_hierarchy():
|
| 43 |
-
path = spatial_codes.spatial_code_path(
|
| 44 |
-
"scene-a", "metric", "selective", "tracking", 64, "explicit"
|
| 45 |
-
)
|
| 46 |
-
assert path.endswith(
|
| 47 |
-
"data/spatial codes/sam3+depth-anything-3/tracking/frames/selective/64/explicit/scene-a.json"
|
| 48 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_B/test_sweep.py
DELETED
|
@@ -1,67 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/B/sweep.py -- multi-config sweep planning."""
|
| 2 |
-
|
| 3 |
-
import pytest
|
| 4 |
-
|
| 5 |
-
from harness.A import models as vlm_models
|
| 6 |
-
from harness.B import sweep
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
def test_build_plan_covers_every_combination():
|
| 10 |
-
plan = sweep.build_plan(
|
| 11 |
-
["qwen3.5-2b", "qwen3.5-4b"],
|
| 12 |
-
["explicit"],
|
| 13 |
-
["uniform", "selective"],
|
| 14 |
-
[16, 32],
|
| 15 |
-
["metric"],
|
| 16 |
-
["tracking"],
|
| 17 |
-
)
|
| 18 |
-
assert len(plan) == 2 * 1 * 2 * 2
|
| 19 |
-
assert ("qwen3.5-2b", "explicit", "metric", "tracking", "uniform", 16) in plan
|
| 20 |
-
assert ("qwen3.5-4b", "explicit", "metric", "tracking", "selective", 32) in plan
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def test_build_plan_sweeps_depth_and_tracking_too():
|
| 24 |
-
plan = sweep.build_plan(
|
| 25 |
-
["qwen3.5-2b"],
|
| 26 |
-
["explicit"],
|
| 27 |
-
["uniform"],
|
| 28 |
-
[16],
|
| 29 |
-
["metric", "relative"],
|
| 30 |
-
["tracking", "no tracking"],
|
| 31 |
-
)
|
| 32 |
-
assert len(plan) == 4
|
| 33 |
-
assert ("qwen3.5-2b", "explicit", "relative", "no tracking", "uniform", 16) in plan
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
def test_build_plan_orders_by_frame_count_first():
|
| 37 |
-
plan = sweep.build_plan(
|
| 38 |
-
["qwen3.5-2b"],
|
| 39 |
-
["explicit"],
|
| 40 |
-
["uniform"],
|
| 41 |
-
[64, 16, 32],
|
| 42 |
-
["metric"],
|
| 43 |
-
["tracking"],
|
| 44 |
-
)
|
| 45 |
-
assert [frame_count for *_rest, frame_count in plan] == [16, 32, 64]
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
def test_build_plan_with_all_registered_models():
|
| 49 |
-
plan = sweep.build_plan(
|
| 50 |
-
list(vlm_models.available_models()),
|
| 51 |
-
["explicit"],
|
| 52 |
-
["uniform"],
|
| 53 |
-
[16],
|
| 54 |
-
["metric"],
|
| 55 |
-
["tracking"],
|
| 56 |
-
)
|
| 57 |
-
assert len(plan) == len(vlm_models.available_models())
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
def test_sweep_parser_rejects_unknown_depth():
|
| 61 |
-
with pytest.raises(ValueError):
|
| 62 |
-
sweep._parse_csv_choice("bogus", sweep.DEPTH_VARIANTS, "--depths")
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
def test_sweep_parser_rejects_unknown_tracking():
|
| 66 |
-
with pytest.raises(ValueError):
|
| 67 |
-
sweep._parse_csv_choice("bogus", sweep.TRACKING_MODES, "--trackings")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_C/__init__.py
DELETED
|
File without changes
|
tests/test_C/conftest.py
DELETED
|
@@ -1,12 +0,0 @@
|
|
| 1 |
-
"""Shared import setup for harness.C tests."""
|
| 2 |
-
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
import sys
|
| 5 |
-
|
| 6 |
-
ROOT = Path(__file__).resolve().parents[2]
|
| 7 |
-
if str(ROOT) not in sys.path:
|
| 8 |
-
sys.path.insert(0, str(ROOT))
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def pytest_configure(config):
|
| 12 |
-
config.option.importmode = "importlib"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_C/test_C.py
DELETED
|
@@ -1,27 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/C/__init__.py -- shared config constants."""
|
| 2 |
-
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
|
| 5 |
-
from harness import A, B, C
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def test_input_selections_are_one_shared_vocabulary_with_a_and_b():
|
| 9 |
-
assert B.INPUT_SELECTIONS == A.FRAME_SELECTIONS
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
def test_reuses_harness_a_model_paths_and_generation_protocol():
|
| 13 |
-
assert C.MODEL_PATHS is A.MODEL_PATHS
|
| 14 |
-
assert C.MAX_NEW_TOKENS == A.MAX_NEW_TOKENS
|
| 15 |
-
assert C.DO_SAMPLE == A.DO_SAMPLE
|
| 16 |
-
assert C.TEMPERATURE == A.TEMPERATURE
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
def test_results_dir_defaults_under_root_results():
|
| 20 |
-
assert C.RESULTS_DIR == Path("/root/results/C")
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def test_depth_and_tracking_reuse_encoder_config_vocabulary():
|
| 24 |
-
from encoder.config import DEPTH_VARIANTS, TRACKING_MODES
|
| 25 |
-
|
| 26 |
-
assert C.DEPTH_VARIANTS == DEPTH_VARIANTS
|
| 27 |
-
assert C.TRACKING_MODES == TRACKING_MODES
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_C/test_init.py
DELETED
|
@@ -1,25 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/C/__init__.py -- shared config constants."""
|
| 2 |
-
|
| 3 |
-
from harness import A, B, C
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def test_input_selections_are_one_shared_vocabulary_with_a_and_b():
|
| 7 |
-
assert B.INPUT_SELECTIONS == A.FRAME_SELECTIONS
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def test_reuses_harness_a_model_paths_and_generation_protocol():
|
| 11 |
-
assert C.MODEL_PATHS is A.MODEL_PATHS
|
| 12 |
-
assert C.MAX_NEW_TOKENS == A.MAX_NEW_TOKENS
|
| 13 |
-
assert C.DO_SAMPLE == A.DO_SAMPLE
|
| 14 |
-
assert C.TEMPERATURE == A.TEMPERATURE
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
def test_results_dir_defaults_under_workspace_results():
|
| 18 |
-
assert C.RESULTS_DIR == C.WORKSPACE_ROOT / "results" / "C"
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
def test_depth_and_tracking_reuse_encoder_config_vocabulary():
|
| 22 |
-
from encoder.config import DEPTH_VARIANTS, TRACKING_MODES
|
| 23 |
-
|
| 24 |
-
assert C.DEPTH_VARIANTS == DEPTH_VARIANTS
|
| 25 |
-
assert C.TRACKING_MODES == TRACKING_MODES
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_C/test_launch.py
DELETED
|
@@ -1,69 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/C/launch.py -- multi-GPU scene sharding across workers."""
|
| 2 |
-
|
| 3 |
-
from harness.C import launch
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def test_launcher_imports():
|
| 7 |
-
assert callable(launch.main)
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
class _FakeRun:
|
| 11 |
-
rows = [{"id": 1}, {"id": 2}]
|
| 12 |
-
|
| 13 |
-
@staticmethod
|
| 14 |
-
def results_dir_for(*args, **kwargs):
|
| 15 |
-
return args[-1]
|
| 16 |
-
|
| 17 |
-
@classmethod
|
| 18 |
-
def load_questions(cls, scene=None):
|
| 19 |
-
return list(cls.rows)
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
def test_launch_skips_scene_already_fully_answered(tmp_path, capsys, monkeypatch):
|
| 23 |
-
scene = "scene-c"
|
| 24 |
-
monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun)
|
| 25 |
-
|
| 26 |
-
scene_dir = tmp_path / scene
|
| 27 |
-
scene_dir.mkdir()
|
| 28 |
-
for row in _FakeRun.rows:
|
| 29 |
-
(scene_dir / f"{row['id']}.json").write_text("{}")
|
| 30 |
-
|
| 31 |
-
launch.launch(
|
| 32 |
-
"qwen3.5-2b", "explicit", "selective", 64, [scene], results_dir=tmp_path
|
| 33 |
-
)
|
| 34 |
-
|
| 35 |
-
output = capsys.readouterr().out
|
| 36 |
-
assert "skipped" in output
|
| 37 |
-
assert "DONE: 1 ok, 0 failed" in output
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
def test_launch_rebuild_forces_pending_even_when_answered(tmp_path, monkeypatch):
|
| 41 |
-
scene = "scene-c"
|
| 42 |
-
monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun)
|
| 43 |
-
scene_dir = tmp_path / scene
|
| 44 |
-
scene_dir.mkdir()
|
| 45 |
-
for row in _FakeRun.rows:
|
| 46 |
-
(scene_dir / f"{row['id']}.json").write_text("{}")
|
| 47 |
-
|
| 48 |
-
monkeypatch.setattr(launch, "visible_gpus", lambda: [])
|
| 49 |
-
monkeypatch.setattr(
|
| 50 |
-
launch.mp,
|
| 51 |
-
"get_context",
|
| 52 |
-
lambda *_: (_ for _ in ()).throw(
|
| 53 |
-
RuntimeError("rebuild correctly reached worker dispatch")
|
| 54 |
-
),
|
| 55 |
-
)
|
| 56 |
-
try:
|
| 57 |
-
launch.launch(
|
| 58 |
-
"qwen3.5-2b",
|
| 59 |
-
"explicit",
|
| 60 |
-
"selective",
|
| 61 |
-
64,
|
| 62 |
-
[scene],
|
| 63 |
-
results_dir=tmp_path,
|
| 64 |
-
rebuild=True,
|
| 65 |
-
)
|
| 66 |
-
except RuntimeError as exc:
|
| 67 |
-
assert "rebuild correctly reached worker dispatch" in str(exc)
|
| 68 |
-
else:
|
| 69 |
-
raise AssertionError("expected rebuild to force scene into the pending path")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_C/test_overlay.py
DELETED
|
@@ -1,209 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/C/overlay.py -- overlay labels, cache, and stamping."""
|
| 2 |
-
|
| 3 |
-
import json
|
| 4 |
-
from pathlib import Path
|
| 5 |
-
|
| 6 |
-
import pytest
|
| 7 |
-
from PIL import Image
|
| 8 |
-
|
| 9 |
-
from harness.C import overlay
|
| 10 |
-
|
| 11 |
-
_EXPLICIT_CODE = {
|
| 12 |
-
"objects": {
|
| 13 |
-
"chair": {
|
| 14 |
-
"instances": [
|
| 15 |
-
{
|
| 16 |
-
"position": {
|
| 17 |
-
"x coordinate": "1.5 m",
|
| 18 |
-
"y coordinate": "-2 m",
|
| 19 |
-
"height above floor": "0.25 m",
|
| 20 |
-
},
|
| 21 |
-
"longest dimension": "0.80 m",
|
| 22 |
-
}
|
| 23 |
-
]
|
| 24 |
-
},
|
| 25 |
-
"table": {
|
| 26 |
-
"instances": [
|
| 27 |
-
{
|
| 28 |
-
"position": {
|
| 29 |
-
"x coordinate": "3 m",
|
| 30 |
-
"y coordinate": "4 m",
|
| 31 |
-
"height above floor": "0 m",
|
| 32 |
-
},
|
| 33 |
-
"longest dimension": "1.20 m",
|
| 34 |
-
}
|
| 35 |
-
]
|
| 36 |
-
},
|
| 37 |
-
}
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
def test_instance_ids_adds_stable_one_based_labels_without_mutating_input():
|
| 42 |
-
original = {"objects": {"chair": {"instances": [{"position": {}}]}}}
|
| 43 |
-
|
| 44 |
-
labeled = overlay.instance_ids(original)
|
| 45 |
-
|
| 46 |
-
assert labeled["objects"]["chair"]["instances"][0]["instance id"] == "chair 1"
|
| 47 |
-
assert "instance id" not in original["objects"]["chair"]["instances"][0]
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
def test_overlay_spatial_code_path_lives_under_overlay_root(monkeypatch, tmp_path):
|
| 51 |
-
monkeypatch.setattr(
|
| 52 |
-
overlay.encoder_config, "CODES_ROOT", tmp_path / "data" / "spatial codes"
|
| 53 |
-
)
|
| 54 |
-
monkeypatch.setattr(overlay.encoder_config, "MODEL", "sam3+depth-anything-3")
|
| 55 |
-
|
| 56 |
-
path = overlay.overlay_spatial_code_path(
|
| 57 |
-
"scene", "metric", "uniform", "tracking", 32
|
| 58 |
-
)
|
| 59 |
-
|
| 60 |
-
assert path == (
|
| 61 |
-
tmp_path
|
| 62 |
-
/ "data"
|
| 63 |
-
/ "spatial codes"
|
| 64 |
-
/ "overlay"
|
| 65 |
-
/ "sam3+depth-anything-3"
|
| 66 |
-
/ "metric"
|
| 67 |
-
/ "tracking"
|
| 68 |
-
/ "uniform"
|
| 69 |
-
/ "32"
|
| 70 |
-
/ "explicit"
|
| 71 |
-
/ "scene.json"
|
| 72 |
-
)
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
def test_load_or_create_overlay_code_saves_missing_file(monkeypatch, tmp_path):
|
| 76 |
-
monkeypatch.setattr(overlay.encoder_config, "CODES_ROOT", tmp_path / "codes")
|
| 77 |
-
monkeypatch.setattr(overlay.encoder_config, "MODEL", "model")
|
| 78 |
-
|
| 79 |
-
code, path = overlay.load_or_create_overlay_code(
|
| 80 |
-
_EXPLICIT_CODE, "scene", "metric", "uniform", "tracking", 32
|
| 81 |
-
)
|
| 82 |
-
|
| 83 |
-
path = Path(path)
|
| 84 |
-
assert path.is_file()
|
| 85 |
-
assert json.loads(path.read_text()) == code
|
| 86 |
-
assert code["objects"]["chair"]["instances"][0]["instance id"] == "chair 1"
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
def test_load_or_create_overlay_code_reuses_existing_file(monkeypatch, tmp_path):
|
| 90 |
-
monkeypatch.setattr(overlay.encoder_config, "CODES_ROOT", tmp_path / "codes")
|
| 91 |
-
monkeypatch.setattr(overlay.encoder_config, "MODEL", "model")
|
| 92 |
-
path = overlay.overlay_spatial_code_path(
|
| 93 |
-
"scene", "metric", "uniform", "tracking", 32
|
| 94 |
-
)
|
| 95 |
-
path.parent.mkdir(parents=True)
|
| 96 |
-
existing = {"objects": {"saved": {"instances": []}}, "sentinel": True}
|
| 97 |
-
path.write_text(json.dumps(existing))
|
| 98 |
-
|
| 99 |
-
code, returned = overlay.load_or_create_overlay_code(
|
| 100 |
-
_EXPLICIT_CODE, "scene", "metric", "uniform", "tracking", 32
|
| 101 |
-
)
|
| 102 |
-
|
| 103 |
-
assert returned == str(path)
|
| 104 |
-
assert code == existing
|
| 105 |
-
assert json.loads(path.read_text()) == existing
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
def test_label_positions_parse_meter_strings_in_code_order():
|
| 109 |
-
assert overlay.label_positions(_EXPLICIT_CODE) == [
|
| 110 |
-
("chair 1", 1.5, -2.0, 0.25, 0.8),
|
| 111 |
-
("table 1", 3.0, 4.0, 0.0, 1.2),
|
| 112 |
-
]
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
def test_load_cached_frames_requires_complete_png_set_and_labels(tmp_path):
|
| 116 |
-
assert overlay._load_cached_frames(tmp_path, 2) is None
|
| 117 |
-
(tmp_path / "labels.json").write_text(json.dumps([["chair 1"], []]))
|
| 118 |
-
Image.new("RGB", (4, 4), "white").save(tmp_path / "0.png")
|
| 119 |
-
assert overlay._load_cached_frames(tmp_path, 2) is None
|
| 120 |
-
|
| 121 |
-
Image.new("RGB", (4, 4), "black").save(tmp_path / "1.png")
|
| 122 |
-
images, visible = overlay._load_cached_frames(tmp_path, 2)
|
| 123 |
-
|
| 124 |
-
assert [image.mode for image in images] == ["RGB", "RGB"]
|
| 125 |
-
assert visible == [["chair 1"], []]
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
def test_save_cached_frames_writes_pngs_and_labels(tmp_path):
|
| 129 |
-
frames = [Image.new("RGB", (2, 2), color) for color in ("white", "black")]
|
| 130 |
-
|
| 131 |
-
overlay._save_cached_frames(tmp_path, frames, [["a"], ["b"]])
|
| 132 |
-
|
| 133 |
-
assert (tmp_path / "0.png").is_file()
|
| 134 |
-
assert (tmp_path / "1.png").is_file()
|
| 135 |
-
assert json.loads((tmp_path / "labels.json").read_text()) == [["a"], ["b"]]
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
def test_stamp_frames_uses_raw_sam3_boxes_and_does_not_mutate_inputs(
|
| 139 |
-
monkeypatch, tmp_path
|
| 140 |
-
):
|
| 141 |
-
monkeypatch.setattr(
|
| 142 |
-
overlay, "overlay_frame_cache_dir", lambda *args: tmp_path / "cache"
|
| 143 |
-
)
|
| 144 |
-
monkeypatch.setattr(
|
| 145 |
-
overlay.perceive,
|
| 146 |
-
"cache_or_load",
|
| 147 |
-
lambda *args: ({"geometry": "fake"}, "cache"),
|
| 148 |
-
)
|
| 149 |
-
monkeypatch.setattr(
|
| 150 |
-
overlay.gm,
|
| 151 |
-
"instance_source_track_ids",
|
| 152 |
-
lambda geometry: {"chair": [[10]], "table": [[20]]},
|
| 153 |
-
)
|
| 154 |
-
monkeypatch.setattr(
|
| 155 |
-
overlay,
|
| 156 |
-
"_load_raw_sam3_boxes",
|
| 157 |
-
lambda *args: {
|
| 158 |
-
"chair": {0: {10: (0.10, 0.10, 0.30, 0.30)}},
|
| 159 |
-
"table": {1: {20: (0.50, 0.50, 0.25, 0.25)}},
|
| 160 |
-
},
|
| 161 |
-
)
|
| 162 |
-
frames = [Image.new("RGB", (40, 40), "white"), Image.new("RGB", (40, 40), "white")]
|
| 163 |
-
before = frames[0].copy()
|
| 164 |
-
|
| 165 |
-
stamped, visible = overlay.stamp_frames(
|
| 166 |
-
frames,
|
| 167 |
-
_EXPLICIT_CODE,
|
| 168 |
-
"scene",
|
| 169 |
-
"metric",
|
| 170 |
-
"uniform",
|
| 171 |
-
"tracking",
|
| 172 |
-
2,
|
| 173 |
-
use_cache=True,
|
| 174 |
-
)
|
| 175 |
-
|
| 176 |
-
assert visible == [["chair 1"], ["table 1"]]
|
| 177 |
-
assert stamped[0].getpixel((8, 8)) != before.getpixel((8, 8))
|
| 178 |
-
assert frames[0].tobytes() == before.tobytes()
|
| 179 |
-
cached = overlay._load_cached_frames(tmp_path / "cache", 2)
|
| 180 |
-
assert cached is not None
|
| 181 |
-
assert cached[1] == visible
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
def test_stamp_frames_serves_complete_cache_without_loading_dependencies(
|
| 185 |
-
monkeypatch, tmp_path
|
| 186 |
-
):
|
| 187 |
-
cache_dir = tmp_path / "cache"
|
| 188 |
-
overlay._save_cached_frames(
|
| 189 |
-
cache_dir, [Image.new("RGB", (2, 2), "red")], [["cached"]]
|
| 190 |
-
)
|
| 191 |
-
monkeypatch.setattr(overlay, "overlay_frame_cache_dir", lambda *args: cache_dir)
|
| 192 |
-
monkeypatch.setattr(
|
| 193 |
-
overlay.perceive,
|
| 194 |
-
"cache_or_load",
|
| 195 |
-
lambda *args: pytest.fail("cache hit should not touch perception"),
|
| 196 |
-
)
|
| 197 |
-
|
| 198 |
-
stamped, visible = overlay.stamp_frames(
|
| 199 |
-
[Image.new("RGB", (2, 2), "white")],
|
| 200 |
-
{},
|
| 201 |
-
"scene",
|
| 202 |
-
"metric",
|
| 203 |
-
"uniform",
|
| 204 |
-
"tracking",
|
| 205 |
-
1,
|
| 206 |
-
)
|
| 207 |
-
|
| 208 |
-
assert visible == [["cached"]]
|
| 209 |
-
assert stamped[0].getpixel((0, 0)) == (255, 0, 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_C/test_overlay_launch.py
DELETED
|
@@ -1,144 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/C/overlay_launch.py -- cache pregeneration orchestration."""
|
| 2 |
-
|
| 3 |
-
import pytest
|
| 4 |
-
|
| 5 |
-
from harness.C import overlay_launch
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def test_available_cpu_count_honors_positive_environment(monkeypatch):
|
| 9 |
-
monkeypatch.setenv("VSI_CPU_WORKERS", "3")
|
| 10 |
-
assert overlay_launch._available_cpu_count() == 3
|
| 11 |
-
monkeypatch.setenv("VSI_CPU_WORKERS", "0")
|
| 12 |
-
with pytest.raises(ValueError, match="positive"):
|
| 13 |
-
overlay_launch._available_cpu_count()
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def test_has_dependencies_requires_spatial_code_and_sam3_cache(monkeypatch, tmp_path):
|
| 17 |
-
cache = tmp_path / "sam3.pt"
|
| 18 |
-
monkeypatch.setattr(
|
| 19 |
-
overlay_launch.spatial_codes,
|
| 20 |
-
"load_spatial_code",
|
| 21 |
-
lambda *args: ({"objects": {}}, "code.json"),
|
| 22 |
-
)
|
| 23 |
-
monkeypatch.setattr(
|
| 24 |
-
"encoder.config.sam3_cache_file",
|
| 25 |
-
lambda *args: cache,
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
assert (
|
| 29 |
-
overlay_launch._has_dependencies("scene", "metric", "uniform", "tracking", 32)
|
| 30 |
-
is False
|
| 31 |
-
)
|
| 32 |
-
cache.write_text("cache")
|
| 33 |
-
assert (
|
| 34 |
-
overlay_launch._has_dependencies("scene", "metric", "uniform", "tracking", 32)
|
| 35 |
-
is True
|
| 36 |
-
)
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
def test_has_dependencies_treats_missing_code_as_ineligible(monkeypatch):
|
| 40 |
-
def missing(*args):
|
| 41 |
-
raise FileNotFoundError("missing code")
|
| 42 |
-
|
| 43 |
-
monkeypatch.setattr(overlay_launch.spatial_codes, "load_spatial_code", missing)
|
| 44 |
-
assert (
|
| 45 |
-
overlay_launch._has_dependencies("scene", "metric", "uniform", "tracking", 32)
|
| 46 |
-
is False
|
| 47 |
-
)
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
def test_launch_skips_missing_and_already_cached_without_pool(
|
| 51 |
-
monkeypatch, tmp_path, capsys
|
| 52 |
-
):
|
| 53 |
-
monkeypatch.setattr(
|
| 54 |
-
overlay_launch,
|
| 55 |
-
"_has_dependencies",
|
| 56 |
-
lambda scene, *args: scene != "missing",
|
| 57 |
-
)
|
| 58 |
-
monkeypatch.setattr(
|
| 59 |
-
overlay_launch.overlay,
|
| 60 |
-
"overlay_frame_cache_dir",
|
| 61 |
-
lambda scene, *args: tmp_path / scene,
|
| 62 |
-
)
|
| 63 |
-
monkeypatch.setattr(
|
| 64 |
-
overlay_launch.overlay,
|
| 65 |
-
"_load_cached_frames",
|
| 66 |
-
lambda cache_dir, frame_count: (
|
| 67 |
-
([object()], [[]]) if cache_dir.name == "cached" else None
|
| 68 |
-
),
|
| 69 |
-
)
|
| 70 |
-
monkeypatch.setattr(
|
| 71 |
-
overlay_launch.overlay,
|
| 72 |
-
"overlay_spatial_code_path",
|
| 73 |
-
lambda scene, *args: tmp_path / scene / "overlay-code.json",
|
| 74 |
-
)
|
| 75 |
-
(tmp_path / "cached").mkdir()
|
| 76 |
-
(tmp_path / "cached" / "overlay-code.json").write_text("{}")
|
| 77 |
-
monkeypatch.setattr(
|
| 78 |
-
overlay_launch.mp,
|
| 79 |
-
"get_context",
|
| 80 |
-
lambda *_: pytest.fail("no pending scenes should avoid multiprocessing"),
|
| 81 |
-
)
|
| 82 |
-
|
| 83 |
-
succeeded, failed, missing = overlay_launch.launch(
|
| 84 |
-
"metric", "uniform", "tracking", 32, ["missing", "cached"]
|
| 85 |
-
)
|
| 86 |
-
|
| 87 |
-
assert succeeded == []
|
| 88 |
-
assert failed == []
|
| 89 |
-
assert missing == ["missing"]
|
| 90 |
-
output = capsys.readouterr().out
|
| 91 |
-
assert "missing a code or SAM3 cache" in output
|
| 92 |
-
assert "already cached" in output
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
def test_launch_does_not_skip_frames_cache_when_overlay_code_is_missing(
|
| 96 |
-
monkeypatch, tmp_path
|
| 97 |
-
):
|
| 98 |
-
monkeypatch.setattr(overlay_launch, "_has_dependencies", lambda scene, *args: True)
|
| 99 |
-
monkeypatch.setattr(
|
| 100 |
-
overlay_launch.overlay,
|
| 101 |
-
"overlay_frame_cache_dir",
|
| 102 |
-
lambda scene, *args: tmp_path / scene,
|
| 103 |
-
)
|
| 104 |
-
monkeypatch.setattr(
|
| 105 |
-
overlay_launch.overlay,
|
| 106 |
-
"_load_cached_frames",
|
| 107 |
-
lambda cache_dir, frame_count: ([object()], [[]]),
|
| 108 |
-
)
|
| 109 |
-
monkeypatch.setattr(
|
| 110 |
-
overlay_launch.overlay,
|
| 111 |
-
"overlay_spatial_code_path",
|
| 112 |
-
lambda scene, *args: tmp_path / scene / "missing-overlay-code.json",
|
| 113 |
-
)
|
| 114 |
-
|
| 115 |
-
calls = []
|
| 116 |
-
|
| 117 |
-
class FakePool:
|
| 118 |
-
def __init__(self, workers):
|
| 119 |
-
self.workers = workers
|
| 120 |
-
|
| 121 |
-
def __enter__(self):
|
| 122 |
-
return self
|
| 123 |
-
|
| 124 |
-
def __exit__(self, *exc):
|
| 125 |
-
return False
|
| 126 |
-
|
| 127 |
-
def map(self, fn, tasks):
|
| 128 |
-
calls.extend(tasks)
|
| 129 |
-
return [(task[0], True, None) for task in tasks]
|
| 130 |
-
|
| 131 |
-
class FakeContext:
|
| 132 |
-
def Pool(self, workers):
|
| 133 |
-
return FakePool(workers)
|
| 134 |
-
|
| 135 |
-
monkeypatch.setattr(overlay_launch.mp, "get_context", lambda *_: FakeContext())
|
| 136 |
-
|
| 137 |
-
succeeded, failed, missing = overlay_launch.launch(
|
| 138 |
-
"metric", "uniform", "tracking", 32, ["frames_only"], workers=1
|
| 139 |
-
)
|
| 140 |
-
|
| 141 |
-
assert calls == [("frames_only", "metric", "uniform", "tracking", 32)]
|
| 142 |
-
assert succeeded == ["frames_only"]
|
| 143 |
-
assert failed == []
|
| 144 |
-
assert missing == []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_C/test_prompts.py
DELETED
|
@@ -1,66 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/C/prompts.py -- combined frames+spatial-code prompt construction."""
|
| 2 |
-
|
| 3 |
-
import json
|
| 4 |
-
|
| 5 |
-
import pytest
|
| 6 |
-
|
| 7 |
-
from harness.A.prompts import MCA_QUESTION_TYPES, NA_QUESTION_TYPES
|
| 8 |
-
from harness.C import prompts as combined_prompts
|
| 9 |
-
|
| 10 |
-
_CODE = {
|
| 11 |
-
"objects": {"chair": {"count": 1}},
|
| 12 |
-
"room": {"floor area": "10.0 square meters"},
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def test_pre_prompt_mentions_both_frames_and_spatial_code():
|
| 17 |
-
lowered = combined_prompts.PRE_PROMPT.lower()
|
| 18 |
-
assert "frame" in lowered
|
| 19 |
-
assert "spatial code" in lowered
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
def test_na_question_prompt_layout_is_context_then_code_then_question_then_post_prompt():
|
| 23 |
-
prompt = combined_prompts.build_prompt(_CODE, "object_counting", "How many chairs?")
|
| 24 |
-
context_pos = prompt.find(combined_prompts.PRE_PROMPT)
|
| 25 |
-
code_pos = prompt.find(json.dumps(_CODE, indent=1))
|
| 26 |
-
question_pos = prompt.find("How many chairs?")
|
| 27 |
-
post_pos = prompt.find(combined_prompts.NA_POST_PROMPT)
|
| 28 |
-
assert context_pos == 0
|
| 29 |
-
assert context_pos < code_pos < question_pos < post_pos
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
def test_mca_question_prompt_includes_options_and_post_prompt():
|
| 33 |
-
prompt = combined_prompts.build_prompt(
|
| 34 |
-
_CODE, "object_rel_distance", "Which is closest?", ["A. sofa", "B. table"]
|
| 35 |
-
)
|
| 36 |
-
assert "Options:\nA. sofa\nB. table" in prompt
|
| 37 |
-
assert prompt.endswith(combined_prompts.MCA_POST_PROMPT)
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
def test_mca_question_requires_options():
|
| 41 |
-
with pytest.raises(ValueError):
|
| 42 |
-
combined_prompts.build_prompt(_CODE, "route_planning", "Which way?", None)
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
def test_unknown_question_type_rejected():
|
| 46 |
-
with pytest.raises(ValueError):
|
| 47 |
-
combined_prompts.build_prompt(_CODE, "not_a_real_type", "?", None)
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
@pytest.mark.parametrize("question_type", NA_QUESTION_TYPES)
|
| 51 |
-
def test_every_na_question_type_builds(question_type):
|
| 52 |
-
prompt = combined_prompts.build_prompt(_CODE, question_type, "q?")
|
| 53 |
-
assert prompt.startswith(combined_prompts.PRE_PROMPT)
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
@pytest.mark.parametrize("question_type", MCA_QUESTION_TYPES)
|
| 57 |
-
def test_every_mca_question_type_builds(question_type):
|
| 58 |
-
prompt = combined_prompts.build_prompt(_CODE, question_type, "q?", ["A. x", "B. y"])
|
| 59 |
-
assert prompt.startswith(combined_prompts.PRE_PROMPT)
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
def test_video_prompt_names_native_video():
|
| 63 |
-
prompt = combined_prompts.build_prompt(
|
| 64 |
-
_CODE, "object_counting", "How many chairs?", video=True
|
| 65 |
-
)
|
| 66 |
-
assert prompt.startswith("This is a video.\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_C/test_run.py
DELETED
|
@@ -1,176 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/C/run.py -- result-record shape and result-file writing."""
|
| 2 |
-
|
| 3 |
-
import json
|
| 4 |
-
|
| 5 |
-
from harness import C
|
| 6 |
-
from harness.C import run as harness_run
|
| 7 |
-
|
| 8 |
-
_FAKE_ANSWER = {
|
| 9 |
-
"prompt_text": "<rendered chat template>",
|
| 10 |
-
"answer_text": "4",
|
| 11 |
-
"answer_raw": "<|im_start|>assistant\n4<|im_end|>",
|
| 12 |
-
"input_token_count": 22205,
|
| 13 |
-
"vision_input_shapes": {"pixel_values": [76800, 1536], "image_grid_thw": [64, 3]},
|
| 14 |
-
"output_token_ids": [19, 151645],
|
| 15 |
-
"output_token_count": 2,
|
| 16 |
-
"hit_token_limit": False,
|
| 17 |
-
"eos_token_ids": [151645],
|
| 18 |
-
"generation_seconds": 5.6,
|
| 19 |
-
"device": "cuda",
|
| 20 |
-
"dtype": "bfloat16",
|
| 21 |
-
"library_versions": {"transformers": "5.14.1", "torch": "2.13.0+cu130"},
|
| 22 |
-
"generation_config": {
|
| 23 |
-
"max_new_tokens": 16,
|
| 24 |
-
"do_sample": False,
|
| 25 |
-
"temperature": 0.0,
|
| 26 |
-
"top_p": None,
|
| 27 |
-
"top_k": None,
|
| 28 |
-
"enable_thinking": False,
|
| 29 |
-
},
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
_FAKE_ROW = {
|
| 33 |
-
"id": 7,
|
| 34 |
-
"scene_name": "scene0001_00",
|
| 35 |
-
"dataset": "scannet",
|
| 36 |
-
"question_type": "object_counting",
|
| 37 |
-
"question": "How many chairs?",
|
| 38 |
-
"options": None,
|
| 39 |
-
"ground_truth": "4",
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
_FAKE_SOURCE_INFO = {
|
| 43 |
-
"protocol": "thinking",
|
| 44 |
-
"spatial_code_format": "explicit",
|
| 45 |
-
"input_selection": "selective",
|
| 46 |
-
"frame_count": 64,
|
| 47 |
-
"depth": "metric",
|
| 48 |
-
"tracking": "tracking",
|
| 49 |
-
"spatial_code_path": "/workspace/data/spatial codes/.../scene0001_00.json",
|
| 50 |
-
"video_path": "/root/data/VSI-Bench/scannet/scene0001_00.mp4",
|
| 51 |
-
"frame_indices": [0, 30, 60],
|
| 52 |
-
"frame_timestamps": [0.0, 1.0, 2.0],
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
def test_results_dir_for_matches_established_dimension_nesting():
|
| 57 |
-
root = harness_run.results_dir_for(
|
| 58 |
-
"qwen3.5-4b", "thinking", "explicit", "metric", "tracking", "uniform", 32
|
| 59 |
-
)
|
| 60 |
-
assert root == (
|
| 61 |
-
C.RESULTS_DIR
|
| 62 |
-
/ "qwen3.5-4b"
|
| 63 |
-
/ "explicit"
|
| 64 |
-
/ "metric"
|
| 65 |
-
/ "tracking"
|
| 66 |
-
/ "uniform"
|
| 67 |
-
/ "32"
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
def test_results_dir_for_honors_explicit_override(tmp_path):
|
| 72 |
-
root = harness_run.results_dir_for(
|
| 73 |
-
"qwen3.5-4b",
|
| 74 |
-
"base",
|
| 75 |
-
"explicit",
|
| 76 |
-
"relative",
|
| 77 |
-
"no tracking",
|
| 78 |
-
"selective",
|
| 79 |
-
16,
|
| 80 |
-
tmp_path,
|
| 81 |
-
)
|
| 82 |
-
assert root == tmp_path
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
def test_build_record_carries_both_frame_and_spatial_code_provenance():
|
| 86 |
-
record = harness_run._build_record(
|
| 87 |
-
_FAKE_ROW,
|
| 88 |
-
"full prompt text",
|
| 89 |
-
_FAKE_ANSWER,
|
| 90 |
-
"MRA:.5:.95:.05",
|
| 91 |
-
1.0,
|
| 92 |
-
"qwen3.5-4b",
|
| 93 |
-
"/root/models/qwen3.5-4b",
|
| 94 |
-
_FAKE_SOURCE_INFO,
|
| 95 |
-
)
|
| 96 |
-
# Spatial-code provenance (shared with harness.B).
|
| 97 |
-
assert record["spatial_code_format"] == "explicit"
|
| 98 |
-
assert record["input_selection"] == "selective"
|
| 99 |
-
assert record["frame_count"] == 64
|
| 100 |
-
assert record["depth"] == "metric"
|
| 101 |
-
assert record["tracking"] == "tracking"
|
| 102 |
-
assert record["spatial_code_path"] == _FAKE_SOURCE_INFO["spatial_code_path"]
|
| 103 |
-
# Frame provenance (shared with harness.A).
|
| 104 |
-
assert record["video_path"] == _FAKE_SOURCE_INFO["video_path"]
|
| 105 |
-
assert record["frame_indices"] == [0, 30, 60]
|
| 106 |
-
assert record["frame_timestamps_seconds"] == [0.0, 1.0, 2.0]
|
| 107 |
-
# Question/answer fields, same shape as A and B.
|
| 108 |
-
assert record["question"] == "How many chairs?"
|
| 109 |
-
assert record["answer_given"] == "4"
|
| 110 |
-
assert record["vision_input_shapes"] == _FAKE_ANSWER["vision_input_shapes"]
|
| 111 |
-
assert record["condition"] == "extended:explicit:metric:tracking:selective:64"
|
| 112 |
-
assert record["protocol"] == "thinking"
|
| 113 |
-
assert record["score"] == 1.0
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
def test_write_question_result_writes_one_json_file_per_question(tmp_path):
|
| 117 |
-
path, record = harness_run.write_question_result(
|
| 118 |
-
_FAKE_ROW,
|
| 119 |
-
"full prompt text",
|
| 120 |
-
_FAKE_ANSWER,
|
| 121 |
-
"MRA:.5:.95:.05",
|
| 122 |
-
1.0,
|
| 123 |
-
"qwen3.5-4b",
|
| 124 |
-
"/root/models/qwen3.5-4b",
|
| 125 |
-
_FAKE_SOURCE_INFO,
|
| 126 |
-
results_dir=tmp_path,
|
| 127 |
-
)
|
| 128 |
-
assert path == tmp_path / "scene0001_00" / "7.json"
|
| 129 |
-
on_disk = json.loads(path.read_text())
|
| 130 |
-
assert on_disk == record
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
def test_build_record_carries_reasoning_fields_when_forced():
|
| 134 |
-
extended_answer = {
|
| 135 |
-
**_FAKE_ANSWER,
|
| 136 |
-
"reasoning_text": "long reasoning about the frames and spatial code",
|
| 137 |
-
"reasoning_raw": "long reasoning about the frames and spatial code<|im_end|>",
|
| 138 |
-
"reasoning_token_ids": list(range(50)),
|
| 139 |
-
"reasoning_token_count": 50,
|
| 140 |
-
"reasoning_hit_limit": True,
|
| 141 |
-
"forced": True,
|
| 142 |
-
"forced_input_token_count": 22300,
|
| 143 |
-
}
|
| 144 |
-
record = harness_run._build_record(
|
| 145 |
-
_FAKE_ROW,
|
| 146 |
-
"full prompt text",
|
| 147 |
-
extended_answer,
|
| 148 |
-
"MRA:.5:.95:.05",
|
| 149 |
-
1.0,
|
| 150 |
-
"qwen3.5-4b",
|
| 151 |
-
"/root/models/qwen3.5-4b",
|
| 152 |
-
_FAKE_SOURCE_INFO,
|
| 153 |
-
)
|
| 154 |
-
assert (
|
| 155 |
-
record["reasoning_text"] == "long reasoning about the frames and spatial code"
|
| 156 |
-
)
|
| 157 |
-
assert record["forced"] is True
|
| 158 |
-
assert record["forced_input_token_count"] == 22300
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
def test_video_results_use_video_branch():
|
| 162 |
-
assert (
|
| 163 |
-
harness_run.results_dir_for(
|
| 164 |
-
"qwen3.5-4b", "thinking", "explicit", "metric", "tracking", "video", None
|
| 165 |
-
)
|
| 166 |
-
== C.RESULTS_DIR / "qwen3.5-4b" / "explicit" / "metric" / "tracking" / "video"
|
| 167 |
-
)
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
def test_video_record_has_no_frame_count_in_condition():
|
| 171 |
-
info = dict(_FAKE_SOURCE_INFO, input_selection="video", frame_count=None)
|
| 172 |
-
record = harness_run._build_record(
|
| 173 |
-
_FAKE_ROW, "prompt", _FAKE_ANSWER, "metric", 1.0, "qwen3.5-4b", "/model", info
|
| 174 |
-
)
|
| 175 |
-
assert record["condition"] == "thinking:explicit:metric:tracking:video"
|
| 176 |
-
assert record["frame_count"] is None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_C/test_sweep.py
DELETED
|
@@ -1,67 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/C/sweep.py -- multi-config sweep planning."""
|
| 2 |
-
|
| 3 |
-
import pytest
|
| 4 |
-
|
| 5 |
-
from harness.A import models as vlm_models
|
| 6 |
-
from harness.C import sweep
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
def test_build_plan_covers_every_combination():
|
| 10 |
-
plan = sweep.build_plan(
|
| 11 |
-
["qwen3.5-2b", "qwen3.5-4b"],
|
| 12 |
-
["explicit"],
|
| 13 |
-
["uniform", "selective"],
|
| 14 |
-
[16, 32],
|
| 15 |
-
["metric"],
|
| 16 |
-
["tracking"],
|
| 17 |
-
)
|
| 18 |
-
assert len(plan) == 2 * 1 * 2 * 2
|
| 19 |
-
assert ("qwen3.5-2b", "explicit", "metric", "tracking", "uniform", 16) in plan
|
| 20 |
-
assert ("qwen3.5-4b", "explicit", "metric", "tracking", "selective", 32) in plan
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def test_build_plan_sweeps_depth_and_tracking_too():
|
| 24 |
-
plan = sweep.build_plan(
|
| 25 |
-
["qwen3.5-2b"],
|
| 26 |
-
["explicit"],
|
| 27 |
-
["uniform"],
|
| 28 |
-
[16],
|
| 29 |
-
["metric", "relative"],
|
| 30 |
-
["tracking", "no tracking"],
|
| 31 |
-
)
|
| 32 |
-
assert len(plan) == 4
|
| 33 |
-
assert ("qwen3.5-2b", "explicit", "relative", "no tracking", "uniform", 16) in plan
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
def test_build_plan_orders_by_frame_count_first():
|
| 37 |
-
plan = sweep.build_plan(
|
| 38 |
-
["qwen3.5-2b"],
|
| 39 |
-
["explicit"],
|
| 40 |
-
["uniform"],
|
| 41 |
-
[64, 16, 32],
|
| 42 |
-
["metric"],
|
| 43 |
-
["tracking"],
|
| 44 |
-
)
|
| 45 |
-
assert [frame_count for *_rest, frame_count in plan] == [16, 32, 64]
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
def test_build_plan_with_all_registered_models():
|
| 49 |
-
plan = sweep.build_plan(
|
| 50 |
-
list(vlm_models.available_models()),
|
| 51 |
-
["explicit"],
|
| 52 |
-
["uniform"],
|
| 53 |
-
[16],
|
| 54 |
-
["metric"],
|
| 55 |
-
["tracking"],
|
| 56 |
-
)
|
| 57 |
-
assert len(plan) == len(vlm_models.available_models())
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
def test_sweep_parser_rejects_unknown_depth():
|
| 61 |
-
with pytest.raises(ValueError):
|
| 62 |
-
sweep._parse_csv_choice("bogus", sweep.DEPTH_VARIANTS, "--depths")
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
def test_sweep_parser_rejects_unknown_tracking():
|
| 66 |
-
with pytest.raises(ValueError):
|
| 67 |
-
sweep._parse_csv_choice("bogus", sweep.TRACKING_MODES, "--trackings")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_D/__init__.py
DELETED
|
File without changes
|
tests/test_D/conftest.py
DELETED
|
@@ -1,45 +0,0 @@
|
|
| 1 |
-
"""Shared, self-contained import setup for harness.D tests."""
|
| 2 |
-
|
| 3 |
-
import os
|
| 4 |
-
from pathlib import Path
|
| 5 |
-
import sys
|
| 6 |
-
import tempfile
|
| 7 |
-
import types
|
| 8 |
-
|
| 9 |
-
ROOT = Path(__file__).resolve().parents[2]
|
| 10 |
-
if str(ROOT) not in sys.path:
|
| 11 |
-
sys.path.insert(0, str(ROOT))
|
| 12 |
-
|
| 13 |
-
# D imports the official VSI scorer eagerly. Provide a tiny interface-compatible scorer
|
| 14 |
-
# and manifest so unit tests do not depend on /root/data being mounted.
|
| 15 |
-
_FIXTURES = Path(tempfile.mkdtemp(prefix="test_D_"))
|
| 16 |
-
_SCORER = _FIXTURES / "utils.py"
|
| 17 |
-
_SCORER.write_text(
|
| 18 |
-
'MCA_QUESTION_TYPES = ("object_rel_direction_easy", "object_rel_direction_medium", "object_rel_direction_hard", "object_rel_distance", "route_planning", "obj_appearance_order")\n'
|
| 19 |
-
'NA_QUESTION_TYPES = ("object_abs_distance", "object_counting", "object_size_estimation", "room_size_estimation")\n'
|
| 20 |
-
'METRICS_FOR_MCA = {"exact_match": None}\n'
|
| 21 |
-
'METRICS_FOR_NA = {"MRA:.5:.95:.05": None}\n'
|
| 22 |
-
"def vsibench_process_results(doc, results):\n"
|
| 23 |
-
' metric = "exact_match" if doc["question_type"] in MCA_QUESTION_TYPES else "MRA:.5:.95:.05"\n'
|
| 24 |
-
' score = float(str(results[0]).strip() == str(doc["ground_truth"]).strip())\n'
|
| 25 |
-
' return {"vsibench_score": {metric: score}}\n'
|
| 26 |
-
)
|
| 27 |
-
_MANIFEST = _FIXTURES / "test.jsonl"
|
| 28 |
-
_MANIFEST.write_text(
|
| 29 |
-
'{"id": 7, "scene_name": "13c3e046d7", "dataset": "scannet", "question_type": "object_counting", "question": "How many chairs?", "options": null, "ground_truth": "1"}\n'
|
| 30 |
-
)
|
| 31 |
-
os.environ["HARNESS_OFFICIAL_EVAL"] = str(_SCORER)
|
| 32 |
-
os.environ["SYMBOLIC_OFFICIAL_EVAL"] = str(_SCORER)
|
| 33 |
-
sys.path.insert(0, str(_FIXTURES))
|
| 34 |
-
os.environ["VSI_JSONL"] = str(_MANIFEST)
|
| 35 |
-
|
| 36 |
-
# OpenCV is only needed when the optional frame arm actually decodes a video. Frame
|
| 37 |
-
# unit tests monkeypatch that boundary and never call this placeholder.
|
| 38 |
-
if "cv2" not in sys.modules:
|
| 39 |
-
cv2 = types.ModuleType("cv2")
|
| 40 |
-
cv2.CAP_PROP_FPS = 5
|
| 41 |
-
sys.modules["cv2"] = cv2
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
def pytest_configure(config):
|
| 45 |
-
config.option.importmode = "importlib"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_D/test_D.py
DELETED
|
@@ -1,21 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/D/__init__.py -- shared config constants."""
|
| 2 |
-
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
|
| 5 |
-
from harness import A, B, D
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def test_spatial_code_formats_reuse_harness_b_vocabulary():
|
| 9 |
-
assert D.SPATIAL_CODE_FORMATS == B.SPATIAL_CODE_FORMATS
|
| 10 |
-
assert D.DEFAULT_SPATIAL_CODE_FORMAT in D.SPATIAL_CODE_FORMATS
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def test_reuses_harness_a_model_paths_and_generation_protocol():
|
| 14 |
-
assert D.MODEL_PATHS is A.MODEL_PATHS
|
| 15 |
-
assert D.MAX_NEW_TOKENS == A.MAX_NEW_TOKENS
|
| 16 |
-
assert D.DO_SAMPLE == A.DO_SAMPLE
|
| 17 |
-
assert D.TEMPERATURE == A.TEMPERATURE
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
def test_results_dir_defaults_under_root_results():
|
| 21 |
-
assert D.RESULTS_DIR == Path("/root/results/D")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_D/test_init.py
DELETED
|
@@ -1,19 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/D/__init__.py -- shared config constants."""
|
| 2 |
-
|
| 3 |
-
from harness import A, B, D
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def test_spatial_code_formats_reuse_harness_b_vocabulary():
|
| 7 |
-
assert D.SPATIAL_CODE_FORMATS == B.SPATIAL_CODE_FORMATS
|
| 8 |
-
assert D.DEFAULT_SPATIAL_CODE_FORMAT in D.SPATIAL_CODE_FORMATS
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def test_reuses_harness_a_model_paths_and_generation_protocol():
|
| 12 |
-
assert D.MODEL_PATHS is A.MODEL_PATHS
|
| 13 |
-
assert D.MAX_NEW_TOKENS == A.MAX_NEW_TOKENS
|
| 14 |
-
assert D.DO_SAMPLE == A.DO_SAMPLE
|
| 15 |
-
assert D.TEMPERATURE == A.TEMPERATURE
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def test_results_dir_defaults_under_workspace_results():
|
| 19 |
-
assert D.RESULTS_DIR == D.WORKSPACE_ROOT / "results" / "D"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_D/test_launch.py
DELETED
|
@@ -1,67 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/D/launch.py -- multi-GPU scene sharding across workers."""
|
| 2 |
-
|
| 3 |
-
from harness.D import launch
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def test_launcher_imports():
|
| 7 |
-
assert callable(launch.main)
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
class _FakeRun:
|
| 11 |
-
rows = [{"id": 2}, {"id": 5}]
|
| 12 |
-
|
| 13 |
-
@staticmethod
|
| 14 |
-
def results_dir_for(*args, **kwargs):
|
| 15 |
-
return args[3]
|
| 16 |
-
|
| 17 |
-
@classmethod
|
| 18 |
-
def load_questions(cls, scene=None):
|
| 19 |
-
return list(cls.rows)
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
def test_launch_skips_scene_already_fully_answered(tmp_path, capsys, monkeypatch):
|
| 23 |
-
scene = "scene-d"
|
| 24 |
-
monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun)
|
| 25 |
-
|
| 26 |
-
scene_dir = tmp_path / scene
|
| 27 |
-
scene_dir.mkdir()
|
| 28 |
-
for row in _FakeRun.rows:
|
| 29 |
-
(scene_dir / f"{row['id']}.json").write_text("{}")
|
| 30 |
-
|
| 31 |
-
launch.launch("qwen3.5-2b", "explicit", [scene], results_dir=tmp_path)
|
| 32 |
-
|
| 33 |
-
output = capsys.readouterr().out
|
| 34 |
-
assert "skipped" in output
|
| 35 |
-
assert "DONE: 1 ok, 0 failed" in output
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
def test_launch_rebuild_forces_pending_even_when_answered(tmp_path, monkeypatch):
|
| 39 |
-
scene = "scene-d"
|
| 40 |
-
monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun)
|
| 41 |
-
scene_dir = tmp_path / scene
|
| 42 |
-
scene_dir.mkdir()
|
| 43 |
-
for row in _FakeRun.rows:
|
| 44 |
-
(scene_dir / f"{row['id']}.json").write_text("{}")
|
| 45 |
-
|
| 46 |
-
monkeypatch.setattr(launch, "visible_gpus", lambda: [])
|
| 47 |
-
monkeypatch.setattr(
|
| 48 |
-
launch.mp,
|
| 49 |
-
"get_context",
|
| 50 |
-
lambda *_: (_ for _ in ()).throw(
|
| 51 |
-
RuntimeError("rebuild correctly reached worker dispatch")
|
| 52 |
-
),
|
| 53 |
-
)
|
| 54 |
-
try:
|
| 55 |
-
launch.launch(
|
| 56 |
-
"qwen3.5-2b", "explicit", [scene], results_dir=tmp_path, rebuild=True
|
| 57 |
-
)
|
| 58 |
-
except RuntimeError as exc:
|
| 59 |
-
assert "rebuild correctly reached worker dispatch" in str(exc)
|
| 60 |
-
else:
|
| 61 |
-
raise AssertionError("expected rebuild to force scene into the pending path")
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
def test_scenes_is_subset_of_vsi_bench_scenes_with_ground_truth_coverage(monkeypatch):
|
| 65 |
-
monkeypatch.setattr("harness.A.launch.scenes", lambda: ["a", "b", "c"])
|
| 66 |
-
monkeypatch.setattr(launch, "ground_truth_scenes", lambda: ["b", "c", "z"])
|
| 67 |
-
assert launch.scenes() == ["b", "c"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_D/test_prompts.py
DELETED
|
@@ -1,55 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/D/prompts.py -- ground-truth spatial-code-as-text prompt construction."""
|
| 2 |
-
|
| 3 |
-
import json
|
| 4 |
-
|
| 5 |
-
import pytest
|
| 6 |
-
|
| 7 |
-
from harness.A.prompts import MCA_QUESTION_TYPES, NA_QUESTION_TYPES
|
| 8 |
-
from harness.D import prompts as code_prompts
|
| 9 |
-
|
| 10 |
-
_CODE = {
|
| 11 |
-
"objects": {"chair": {"count": 1}},
|
| 12 |
-
"room": {"floor area": "10.0 square meters"},
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def test_na_question_prompt_embeds_the_spatial_code_as_text_and_a_post_prompt():
|
| 17 |
-
prompt = code_prompts.build_prompt(_CODE, "object_counting", "How many chairs?")
|
| 18 |
-
assert prompt.startswith(code_prompts.PRE_PROMPT)
|
| 19 |
-
assert json.dumps(_CODE, indent=1) in prompt
|
| 20 |
-
assert prompt.endswith(code_prompts.NA_POST_PROMPT)
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def test_mca_question_prompt_includes_options_and_matches_harness_a_post_prompt():
|
| 24 |
-
prompt = code_prompts.build_prompt(
|
| 25 |
-
_CODE, "object_rel_distance", "Which is closest?", ["A. sofa", "B. table"]
|
| 26 |
-
)
|
| 27 |
-
assert "Options:\nA. sofa\nB. table" in prompt
|
| 28 |
-
assert prompt.endswith(code_prompts.MCA_POST_PROMPT)
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
def test_mca_question_requires_options():
|
| 32 |
-
with pytest.raises(ValueError):
|
| 33 |
-
code_prompts.build_prompt(_CODE, "route_planning", "Which way?", None)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
def test_unknown_question_type_rejected():
|
| 37 |
-
with pytest.raises(ValueError):
|
| 38 |
-
code_prompts.build_prompt(_CODE, "not_a_real_type", "?", None)
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
def test_no_frames_or_video_language_in_pre_prompt():
|
| 42 |
-
assert "frame" not in code_prompts.PRE_PROMPT.lower()
|
| 43 |
-
assert "video" not in code_prompts.PRE_PROMPT.lower()
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
@pytest.mark.parametrize("question_type", NA_QUESTION_TYPES)
|
| 47 |
-
def test_every_na_question_type_builds(question_type):
|
| 48 |
-
prompt = code_prompts.build_prompt(_CODE, question_type, "q?")
|
| 49 |
-
assert prompt.startswith(code_prompts.PRE_PROMPT)
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
@pytest.mark.parametrize("question_type", MCA_QUESTION_TYPES)
|
| 53 |
-
def test_every_mca_question_type_builds(question_type):
|
| 54 |
-
prompt = code_prompts.build_prompt(_CODE, question_type, "q?", ["A. x", "B. y"])
|
| 55 |
-
assert prompt.startswith(code_prompts.PRE_PROMPT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_D/test_run.py
DELETED
|
@@ -1,246 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/D/run.py -- result-record shape and result-file writing."""
|
| 2 |
-
|
| 3 |
-
import json
|
| 4 |
-
|
| 5 |
-
from harness import D
|
| 6 |
-
from harness.D import run as harness_run
|
| 7 |
-
|
| 8 |
-
_FAKE_ANSWER = {
|
| 9 |
-
"prompt_text": "<rendered chat template>",
|
| 10 |
-
"answer_text": "4",
|
| 11 |
-
"answer_raw": "<|im_start|>assistant\n4<|im_end|>",
|
| 12 |
-
"input_token_count": 2558,
|
| 13 |
-
"vision_input_shapes": {"mm_token_type_ids": [1, 2558]},
|
| 14 |
-
"output_token_ids": [19, 151645],
|
| 15 |
-
"output_token_count": 2,
|
| 16 |
-
"hit_token_limit": False,
|
| 17 |
-
"eos_token_ids": [151645],
|
| 18 |
-
"generation_seconds": 0.65,
|
| 19 |
-
"device": "cuda",
|
| 20 |
-
"dtype": "bfloat16",
|
| 21 |
-
"library_versions": {"transformers": "5.14.1", "torch": "2.13.0+cu130"},
|
| 22 |
-
"generation_config": {
|
| 23 |
-
"max_new_tokens": 16,
|
| 24 |
-
"do_sample": False,
|
| 25 |
-
"temperature": 0.0,
|
| 26 |
-
"top_p": None,
|
| 27 |
-
"top_k": None,
|
| 28 |
-
"enable_thinking": False,
|
| 29 |
-
},
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
_FAKE_ROW = {
|
| 33 |
-
"id": 7,
|
| 34 |
-
"scene_name": "scene0001_00",
|
| 35 |
-
"dataset": "scannet",
|
| 36 |
-
"question_type": "object_counting",
|
| 37 |
-
"question": "How many chairs?",
|
| 38 |
-
"options": None,
|
| 39 |
-
"ground_truth": "4",
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
_FAKE_CODE_INFO = {
|
| 43 |
-
"protocol": "extended",
|
| 44 |
-
"spatial_code_format": "explicit",
|
| 45 |
-
"spatial_code_path": "/workspace/data/spatial codes/ground truth/explicit/scene0001_00.json",
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
def test_results_dir_for_matches_model_protocol_and_format_only():
|
| 50 |
-
root = harness_run.results_dir_for("qwen3.5-4b", "extended", "compact")
|
| 51 |
-
assert root == D.RESULTS_DIR / "qwen3.5-4b" / "code" / "extended" / "compact"
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
def test_results_dir_for_isolates_frames_and_truncated_budget_arms():
|
| 55 |
-
root = harness_run.results_dir_for(
|
| 56 |
-
"qwen3.5-4b",
|
| 57 |
-
"truncated/64",
|
| 58 |
-
"explicit",
|
| 59 |
-
frames=True,
|
| 60 |
-
frame_selection="uniform",
|
| 61 |
-
frame_count=32,
|
| 62 |
-
)
|
| 63 |
-
assert root == (
|
| 64 |
-
D.RESULTS_DIR
|
| 65 |
-
/ "qwen3.5-4b"
|
| 66 |
-
/ "code + frames"
|
| 67 |
-
/ "truncated"
|
| 68 |
-
/ "64"
|
| 69 |
-
/ "explicit"
|
| 70 |
-
/ "uniform"
|
| 71 |
-
/ "32"
|
| 72 |
-
)
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
def test_build_record_describes_frames_plus_ground_truth_condition():
|
| 76 |
-
code_info = {
|
| 77 |
-
**_FAKE_CODE_INFO,
|
| 78 |
-
"protocol": "512",
|
| 79 |
-
"frames": True,
|
| 80 |
-
"frame_selection": "uniform",
|
| 81 |
-
"frame_count": 32,
|
| 82 |
-
"video_path": "/fake/scene.mp4",
|
| 83 |
-
"frame_indices": [0, 30],
|
| 84 |
-
"frame_timestamps": [0.0, 1.0],
|
| 85 |
-
}
|
| 86 |
-
record = harness_run._build_record(
|
| 87 |
-
_FAKE_ROW,
|
| 88 |
-
"full prompt text",
|
| 89 |
-
_FAKE_ANSWER,
|
| 90 |
-
"MRA:.5:.95:.05",
|
| 91 |
-
1.0,
|
| 92 |
-
"qwen3.5-4b",
|
| 93 |
-
"/root/models/qwen3.5-4b",
|
| 94 |
-
code_info,
|
| 95 |
-
)
|
| 96 |
-
assert record["condition"] == "512:explicit:frames:uniform:32"
|
| 97 |
-
assert record["frames"] is True
|
| 98 |
-
assert record["video_path"] == "/fake/scene.mp4"
|
| 99 |
-
assert record["frame_indices"] == [0, 30]
|
| 100 |
-
assert record["frame_timestamps_seconds"] == [0.0, 1.0]
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
def test_results_dir_for_honors_explicit_override(tmp_path):
|
| 104 |
-
root = harness_run.results_dir_for("qwen3.5-4b", "base", "explicit", tmp_path)
|
| 105 |
-
assert root == tmp_path
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
def test_build_record_preserves_every_field_untruncated():
|
| 109 |
-
record = harness_run._build_record(
|
| 110 |
-
_FAKE_ROW,
|
| 111 |
-
"full prompt text",
|
| 112 |
-
_FAKE_ANSWER,
|
| 113 |
-
"MRA:.5:.95:.05",
|
| 114 |
-
1.0,
|
| 115 |
-
"qwen3.5-4b",
|
| 116 |
-
"/root/models/qwen3.5-4b",
|
| 117 |
-
_FAKE_CODE_INFO,
|
| 118 |
-
)
|
| 119 |
-
assert record["question"] == "How many chairs?"
|
| 120 |
-
assert record["full_prompt"] == "full prompt text"
|
| 121 |
-
assert record["rendered_prompt"] == _FAKE_ANSWER["prompt_text"]
|
| 122 |
-
assert record["answer_given"] == "4"
|
| 123 |
-
assert record["spatial_code_format"] == "explicit"
|
| 124 |
-
assert record["spatial_code_path"] == _FAKE_CODE_INFO["spatial_code_path"]
|
| 125 |
-
# No depth/tracking/input_selection -- ground truth has no such axis. frames/
|
| 126 |
-
# frame_selection/frame_count/video_path/frame_indices/frame_timestamps_seconds DO
|
| 127 |
-
# exist on every record (the frames+ground-truth-code arm's fields), null here since
|
| 128 |
-
# _FAKE_CODE_INFO has no "frames" key -- same present-but-null pattern as
|
| 129 |
-
# reasoning_text on a base-protocol record.
|
| 130 |
-
assert record["condition"] == "extended:explicit"
|
| 131 |
-
assert record["protocol"] == "extended"
|
| 132 |
-
assert record["frames"] is False
|
| 133 |
-
assert record["frame_selection"] is None
|
| 134 |
-
assert record["frame_count"] is None
|
| 135 |
-
assert record["video_path"] is None
|
| 136 |
-
assert "input_selection" not in record
|
| 137 |
-
assert "depth" not in record
|
| 138 |
-
assert "tracking" not in record
|
| 139 |
-
assert record["metric"] == "MRA:.5:.95:.05"
|
| 140 |
-
assert record["score"] == 1.0
|
| 141 |
-
assert record["scene"] == "scene0001_00"
|
| 142 |
-
assert record["question_id"] == 7
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
def test_write_question_result_writes_one_json_file_per_question(tmp_path):
|
| 146 |
-
path, record = harness_run.write_question_result(
|
| 147 |
-
_FAKE_ROW,
|
| 148 |
-
"full prompt text",
|
| 149 |
-
_FAKE_ANSWER,
|
| 150 |
-
"MRA:.5:.95:.05",
|
| 151 |
-
1.0,
|
| 152 |
-
"qwen3.5-4b",
|
| 153 |
-
"/root/models/qwen3.5-4b",
|
| 154 |
-
_FAKE_CODE_INFO,
|
| 155 |
-
results_dir=tmp_path,
|
| 156 |
-
)
|
| 157 |
-
assert path == tmp_path / "scene0001_00" / "7.json"
|
| 158 |
-
on_disk = json.loads(path.read_text())
|
| 159 |
-
assert on_disk == record
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
def test_build_record_carries_reasoning_fields_when_forced():
|
| 163 |
-
extended_answer = {
|
| 164 |
-
**_FAKE_ANSWER,
|
| 165 |
-
"reasoning_text": "long reasoning about the spatial code",
|
| 166 |
-
"reasoning_raw": "long reasoning about the spatial code<|im_end|>",
|
| 167 |
-
"reasoning_token_ids": list(range(50)),
|
| 168 |
-
"reasoning_token_count": 50,
|
| 169 |
-
"reasoning_hit_limit": True,
|
| 170 |
-
"forced": True,
|
| 171 |
-
"forced_input_token_count": 2510,
|
| 172 |
-
}
|
| 173 |
-
record = harness_run._build_record(
|
| 174 |
-
_FAKE_ROW,
|
| 175 |
-
"full prompt text",
|
| 176 |
-
extended_answer,
|
| 177 |
-
"MRA:.5:.95:.05",
|
| 178 |
-
1.0,
|
| 179 |
-
"qwen3.5-4b",
|
| 180 |
-
"/root/models/qwen3.5-4b",
|
| 181 |
-
_FAKE_CODE_INFO,
|
| 182 |
-
)
|
| 183 |
-
assert record["reasoning_text"] == "long reasoning about the spatial code"
|
| 184 |
-
assert record["forced"] is True
|
| 185 |
-
assert record["forced_input_token_count"] == 2510
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
def test_build_record_defaults_reasoning_fields_when_absent():
|
| 189 |
-
record = harness_run._build_record(
|
| 190 |
-
_FAKE_ROW,
|
| 191 |
-
"full prompt text",
|
| 192 |
-
_FAKE_ANSWER,
|
| 193 |
-
"MRA:.5:.95:.05",
|
| 194 |
-
1.0,
|
| 195 |
-
"qwen3.5-4b",
|
| 196 |
-
"/root/models/qwen3.5-4b",
|
| 197 |
-
_FAKE_CODE_INFO,
|
| 198 |
-
)
|
| 199 |
-
assert record["reasoning_token_count"] is None
|
| 200 |
-
assert record["forced"] is False
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
def test_run_code_transform_hook_replaces_the_loaded_code(monkeypatch, tmp_path):
|
| 204 |
-
"""The corruption module's entry point: the hook's return value is what the
|
| 205 |
-
prompt is built from, and passing no hook keeps behavior identical."""
|
| 206 |
-
scene = "13c3e046d7"
|
| 207 |
-
seen = {}
|
| 208 |
-
|
| 209 |
-
def fake_load(scene_id, spatial_code_format):
|
| 210 |
-
return {"objects": {"chair": {"count": 1}}}, f"/fake/{scene_id}.json"
|
| 211 |
-
|
| 212 |
-
class FakeAdapter:
|
| 213 |
-
model_path = "/fake/model"
|
| 214 |
-
|
| 215 |
-
def answer_extended(self, frames, prompt, **kwargs):
|
| 216 |
-
seen["prompt"] = prompt
|
| 217 |
-
return {
|
| 218 |
-
"prompt_text": prompt,
|
| 219 |
-
"answer_text": "1",
|
| 220 |
-
"answer_raw": "1",
|
| 221 |
-
"input_token_count": 1,
|
| 222 |
-
"vision_input_shapes": {},
|
| 223 |
-
"output_token_ids": [1],
|
| 224 |
-
"output_token_count": 1,
|
| 225 |
-
"hit_token_limit": False,
|
| 226 |
-
"eos_token_ids": [1],
|
| 227 |
-
"generation_seconds": 0.0,
|
| 228 |
-
"device": "cpu",
|
| 229 |
-
"dtype": "float32",
|
| 230 |
-
"library_versions": {},
|
| 231 |
-
"generation_config": {},
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
monkeypatch.setattr(harness_run.spatial_codes, "load_spatial_code", fake_load)
|
| 235 |
-
replacement = {"objects": {"table": {"count": 9}}}
|
| 236 |
-
results = harness_run.run(
|
| 237 |
-
"qwen3.5-2b",
|
| 238 |
-
scene=scene,
|
| 239 |
-
adapter=FakeAdapter(),
|
| 240 |
-
write_results=False,
|
| 241 |
-
limit=1,
|
| 242 |
-
code_transform=lambda code, scene_id, fmt: replacement,
|
| 243 |
-
)
|
| 244 |
-
assert results
|
| 245 |
-
assert '"table"' in seen["prompt"]
|
| 246 |
-
assert '"chair"' not in seen["prompt"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_D/test_spatial_codes.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/D/spatial_codes.py -- loading on-disk ground-truth spatial codes."""
|
| 2 |
-
|
| 3 |
-
import json
|
| 4 |
-
|
| 5 |
-
import pytest
|
| 6 |
-
|
| 7 |
-
from harness.D import spatial_codes
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def test_load_spatial_code_rejects_unknown_format():
|
| 11 |
-
with pytest.raises(ValueError):
|
| 12 |
-
spatial_codes.load_spatial_code("scene", "bogus")
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
def test_load_spatial_code_raises_clearly_when_missing(tmp_path, monkeypatch):
|
| 16 |
-
monkeypatch.setattr(
|
| 17 |
-
spatial_codes,
|
| 18 |
-
"ground_truth_spatial_code_path",
|
| 19 |
-
lambda *a, **k: str(tmp_path / "missing.json"),
|
| 20 |
-
)
|
| 21 |
-
with pytest.raises(FileNotFoundError):
|
| 22 |
-
spatial_codes.load_spatial_code("scene", "explicit")
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
def test_load_spatial_code_returns_dict_and_path(tmp_path, monkeypatch):
|
| 26 |
-
fixture = tmp_path / "scene1.json"
|
| 27 |
-
fixture.write_text(json.dumps({"objects": {}, "room": {}}))
|
| 28 |
-
monkeypatch.setattr(
|
| 29 |
-
spatial_codes, "ground_truth_spatial_code_path", lambda *a, **k: str(fixture)
|
| 30 |
-
)
|
| 31 |
-
code, path = spatial_codes.load_spatial_code("scene1", "compact")
|
| 32 |
-
assert code == {"objects": {}, "room": {}}
|
| 33 |
-
assert path == str(fixture)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_D/test_sweep.py
DELETED
|
@@ -1,28 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/D/sweep.py -- multi-config sweep planning."""
|
| 2 |
-
|
| 3 |
-
from harness.A import models as vlm_models
|
| 4 |
-
from harness.D import sweep
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
def test_build_plan_covers_every_combination():
|
| 8 |
-
plan = sweep.build_plan(["qwen3.5-2b", "qwen3.5-4b"], ["explicit", "compact"])
|
| 9 |
-
assert len(plan) == 4
|
| 10 |
-
assert ("qwen3.5-2b", "explicit") in plan
|
| 11 |
-
assert ("qwen3.5-4b", "compact") in plan
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
def test_build_plan_with_all_registered_models():
|
| 15 |
-
plan = sweep.build_plan(list(vlm_models.available_models()), ["explicit"])
|
| 16 |
-
assert len(plan) == len(vlm_models.available_models())
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
def test_default_spatial_code_formats_cover_both_when_not_restricted():
|
| 20 |
-
# This session's execution-design decision: D sweeps both formats by default
|
| 21 |
-
# (unlike a hypothetical "winning cell only" design) since ground truth costs
|
| 22 |
-
# nothing extra to build across formats.
|
| 23 |
-
import argparse
|
| 24 |
-
|
| 25 |
-
parser = argparse.ArgumentParser()
|
| 26 |
-
parser.add_argument("--spatial-code-formats", default="all")
|
| 27 |
-
args = parser.parse_args([])
|
| 28 |
-
assert args.spatial_code_formats == "all"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_D/test_symbolic_eval.py
DELETED
|
@@ -1,116 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/D/symbolic_eval.py -- symbolic solver run directly on ground-truth
|
| 2 |
-
spatial codes, no VLM, written through symbolic.run's own writer into
|
| 3 |
-
results/symbolic/ground truth/<format>/... (not a separate results/D/... location)."""
|
| 4 |
-
|
| 5 |
-
import json
|
| 6 |
-
|
| 7 |
-
from harness.D import symbolic_eval
|
| 8 |
-
|
| 9 |
-
_FAKE_CODE = {
|
| 10 |
-
"spatial code schema": {},
|
| 11 |
-
"objects": {
|
| 12 |
-
"chair": [
|
| 13 |
-
{
|
| 14 |
-
"3D oriented bounding box": {
|
| 15 |
-
"3D oriented bounding box center coordinates": [0, 0, 0.5],
|
| 16 |
-
"3D oriented bounding box dimensions": [1, 1, 1],
|
| 17 |
-
"3D oriented bounding box orientation unit vectors": [
|
| 18 |
-
[1, 0, 0],
|
| 19 |
-
[0, 1, 0],
|
| 20 |
-
[0, 0, 1],
|
| 21 |
-
],
|
| 22 |
-
},
|
| 23 |
-
"first visible time": 0.0,
|
| 24 |
-
}
|
| 25 |
-
]
|
| 26 |
-
},
|
| 27 |
-
"room": {"floor boundary polygons": []},
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
def _fake_load(scene_id, spatial_code_format):
|
| 32 |
-
return _FAKE_CODE, f"/fake/{scene_id}.json"
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
def test_run_answers_real_questions_for_a_real_ground_truth_scene(
|
| 36 |
-
tmp_path, monkeypatch
|
| 37 |
-
):
|
| 38 |
-
scene = "13c3e046d7"
|
| 39 |
-
monkeypatch.setattr(symbolic_eval.spatial_codes, "load_spatial_code", _fake_load)
|
| 40 |
-
|
| 41 |
-
results = symbolic_eval.run(
|
| 42 |
-
spatial_code_format="compact",
|
| 43 |
-
scene=scene,
|
| 44 |
-
results_dir=tmp_path,
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
assert results
|
| 48 |
-
for record in results:
|
| 49 |
-
assert record["scene"] == scene
|
| 50 |
-
assert record["result_path"] is not None
|
| 51 |
-
|
| 52 |
-
written = list(tmp_path.rglob("*.json"))
|
| 53 |
-
assert len(written) == len(results)
|
| 54 |
-
native_record = json.loads(written[0].read_text())
|
| 55 |
-
assert native_record["model"] == "symbolic"
|
| 56 |
-
assert native_record["condition"] == "ground truth:compact"
|
| 57 |
-
assert native_record["scene"] == scene
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
def test_run_selects_ground_truth_spatial_codes_when_writing(tmp_path, monkeypatch):
|
| 61 |
-
scene = "13c3e046d7"
|
| 62 |
-
monkeypatch.setattr(symbolic_eval.spatial_codes, "load_spatial_code", _fake_load)
|
| 63 |
-
called = {"select": False, "format": None}
|
| 64 |
-
|
| 65 |
-
def fake_select(spatial_code_format):
|
| 66 |
-
called["select"] = True
|
| 67 |
-
called["format"] = spatial_code_format
|
| 68 |
-
|
| 69 |
-
monkeypatch.setattr(
|
| 70 |
-
symbolic_eval.symbolic_run, "select_ground_truth_spatial_codes", fake_select
|
| 71 |
-
)
|
| 72 |
-
|
| 73 |
-
symbolic_eval.run(spatial_code_format="explicit", scene=scene, results_dir=tmp_path)
|
| 74 |
-
|
| 75 |
-
assert called["select"] is True
|
| 76 |
-
assert called["format"] == "explicit"
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
def test_run_does_not_write_when_write_results_is_false(tmp_path, monkeypatch):
|
| 80 |
-
scene = "13c3e046d7"
|
| 81 |
-
monkeypatch.setattr(symbolic_eval.spatial_codes, "load_spatial_code", _fake_load)
|
| 82 |
-
called = {"select": False}
|
| 83 |
-
monkeypatch.setattr(
|
| 84 |
-
symbolic_eval.symbolic_run,
|
| 85 |
-
"select_ground_truth_spatial_codes",
|
| 86 |
-
lambda *a, **k: called.__setitem__("select", True),
|
| 87 |
-
)
|
| 88 |
-
|
| 89 |
-
results = symbolic_eval.run(
|
| 90 |
-
spatial_code_format="compact",
|
| 91 |
-
scene=scene,
|
| 92 |
-
results_dir=tmp_path,
|
| 93 |
-
write_results=False,
|
| 94 |
-
)
|
| 95 |
-
|
| 96 |
-
assert called["select"] is False
|
| 97 |
-
assert results
|
| 98 |
-
for record in results:
|
| 99 |
-
assert record["result_path"] is None
|
| 100 |
-
assert list(tmp_path.rglob("*.json")) == []
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
def test_run_forwards_results_dir_to_symbolic_writer(tmp_path, monkeypatch):
|
| 104 |
-
scene = "13c3e046d7"
|
| 105 |
-
monkeypatch.setattr(symbolic_eval.spatial_codes, "load_spatial_code", _fake_load)
|
| 106 |
-
seen = {}
|
| 107 |
-
|
| 108 |
-
def fake_write(scene_id, pq, code, results_dir=None):
|
| 109 |
-
seen["results_dir"] = results_dir
|
| 110 |
-
return tmp_path / "fake.json"
|
| 111 |
-
|
| 112 |
-
monkeypatch.setattr(symbolic_eval.symbolic_run, "write_question_result", fake_write)
|
| 113 |
-
|
| 114 |
-
symbolic_eval.run(spatial_code_format="compact", scene=scene, results_dir=tmp_path)
|
| 115 |
-
|
| 116 |
-
assert seen["results_dir"] == tmp_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_E/__init__.py
DELETED
|
File without changes
|
tests/test_E/conftest.py
DELETED
|
@@ -1,12 +0,0 @@
|
|
| 1 |
-
"""Shared import setup for this test package."""
|
| 2 |
-
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
import sys
|
| 5 |
-
|
| 6 |
-
ROOT = Path(__file__).resolve().parents[2]
|
| 7 |
-
if str(ROOT) not in sys.path:
|
| 8 |
-
sys.path.insert(0, str(ROOT))
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def pytest_configure(config):
|
| 12 |
-
config.option.importmode = "importlib"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_E/test_E.py
DELETED
|
@@ -1,20 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/E package configuration."""
|
| 2 |
-
|
| 3 |
-
import importlib
|
| 4 |
-
from pathlib import Path
|
| 5 |
-
|
| 6 |
-
from harness import E
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
def test_blind_floor_reuses_harness_a_public_config():
|
| 10 |
-
assert E.PROTOCOLS == ("base", "extended")
|
| 11 |
-
assert "qwen3.5-2b" in E.MODEL_PATHS
|
| 12 |
-
assert E.RESULTS_DIR == Path("/root/results/E")
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
def test_results_dir_can_be_overridden_by_environment(monkeypatch, tmp_path):
|
| 16 |
-
monkeypatch.setenv("VSI_HARNESS_E_RESULTS_DIR", str(tmp_path / "E"))
|
| 17 |
-
reloaded = importlib.reload(E)
|
| 18 |
-
assert reloaded.RESULTS_DIR == tmp_path / "E"
|
| 19 |
-
monkeypatch.delenv("VSI_HARNESS_E_RESULTS_DIR")
|
| 20 |
-
importlib.reload(E)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_E/test_launch.py
DELETED
|
@@ -1,66 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/E/launch.py -- multi-GPU scene sharding for the blind floor."""
|
| 2 |
-
|
| 3 |
-
from harness.E import launch
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def test_launcher_imports():
|
| 7 |
-
assert callable(launch.main)
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
class _FakeRun:
|
| 11 |
-
rows = [{"id": 4}, {"id": 9}]
|
| 12 |
-
|
| 13 |
-
@staticmethod
|
| 14 |
-
def results_dir_for(model, protocol, results_dir=None):
|
| 15 |
-
return results_dir
|
| 16 |
-
|
| 17 |
-
@classmethod
|
| 18 |
-
def load_questions(cls, scene=None):
|
| 19 |
-
return list(cls.rows)
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
def test_launch_skips_scene_already_fully_answered(tmp_path, capsys, monkeypatch):
|
| 23 |
-
scene = "scene-e"
|
| 24 |
-
monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun)
|
| 25 |
-
|
| 26 |
-
scene_dir = tmp_path / scene
|
| 27 |
-
scene_dir.mkdir()
|
| 28 |
-
for row in _FakeRun.rows:
|
| 29 |
-
(scene_dir / f"{row['id']}.json").write_text("{}")
|
| 30 |
-
|
| 31 |
-
launch.launch("qwen3.5-2b", [scene], results_dir=tmp_path)
|
| 32 |
-
|
| 33 |
-
output = capsys.readouterr().out
|
| 34 |
-
assert "skipped" in output
|
| 35 |
-
assert "DONE: 1 ok, 0 failed" in output
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
def test_launch_rebuild_forces_pending_even_when_answered(tmp_path, monkeypatch):
|
| 39 |
-
scene = "scene-e"
|
| 40 |
-
monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun)
|
| 41 |
-
scene_dir = tmp_path / scene
|
| 42 |
-
scene_dir.mkdir()
|
| 43 |
-
for row in _FakeRun.rows:
|
| 44 |
-
(scene_dir / f"{row['id']}.json").write_text("{}")
|
| 45 |
-
|
| 46 |
-
monkeypatch.setattr(launch, "visible_gpus", lambda: [])
|
| 47 |
-
monkeypatch.setattr(
|
| 48 |
-
launch.mp,
|
| 49 |
-
"get_context",
|
| 50 |
-
lambda *_: (_ for _ in ()).throw(
|
| 51 |
-
RuntimeError("rebuild correctly reached worker dispatch")
|
| 52 |
-
),
|
| 53 |
-
)
|
| 54 |
-
try:
|
| 55 |
-
launch.launch("qwen3.5-2b", [scene], results_dir=tmp_path, rebuild=True)
|
| 56 |
-
except RuntimeError as exc:
|
| 57 |
-
assert "rebuild correctly reached worker dispatch" in str(exc)
|
| 58 |
-
else:
|
| 59 |
-
raise AssertionError("expected rebuild to force scene into the pending path")
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
def test_launch_protocols_use_separate_result_roots():
|
| 63 |
-
run = launch._load_run_module()
|
| 64 |
-
base = run.results_dir_for("qwen3.5-2b", "base")
|
| 65 |
-
extended = run.results_dir_for("qwen3.5-2b", "extended")
|
| 66 |
-
assert base != extended
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_E/test_prompts.py
DELETED
|
@@ -1,48 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/E/prompts.py -- blind question-only prompt construction."""
|
| 2 |
-
|
| 3 |
-
import pytest
|
| 4 |
-
|
| 5 |
-
from harness.A.prompts import MCA_QUESTION_TYPES, NA_QUESTION_TYPES
|
| 6 |
-
from harness.E import prompts as blind_prompts
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
def test_na_question_prompt_is_question_plus_post_prompt_only():
|
| 10 |
-
prompt = blind_prompts.build_prompt("object_counting", "How many chairs?")
|
| 11 |
-
assert prompt == "How many chairs?\n" + blind_prompts.NA_POST_PROMPT
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
def test_mca_question_prompt_includes_options_and_post_prompt():
|
| 15 |
-
prompt = blind_prompts.build_prompt(
|
| 16 |
-
"object_rel_distance", "Which is closest?", ["A. sofa", "B. table"]
|
| 17 |
-
)
|
| 18 |
-
assert "Options:\nA. sofa\nB. table" in prompt
|
| 19 |
-
assert prompt.endswith(blind_prompts.MCA_POST_PROMPT)
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
def test_no_scene_language_anywhere():
|
| 23 |
-
# Blind means blind: no context line claiming frames, video, or a spatial code.
|
| 24 |
-
prompt = blind_prompts.build_prompt("object_counting", "How many chairs?")
|
| 25 |
-
lowered = prompt.lower()
|
| 26 |
-
assert "frame" not in lowered
|
| 27 |
-
assert "video" not in lowered
|
| 28 |
-
assert "spatial code" not in lowered
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
def test_mca_question_requires_options():
|
| 32 |
-
with pytest.raises(ValueError):
|
| 33 |
-
blind_prompts.build_prompt("route_planning", "Which way?", None)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
def test_unknown_question_type_rejected():
|
| 37 |
-
with pytest.raises(ValueError):
|
| 38 |
-
blind_prompts.build_prompt("not_a_real_type", "?", None)
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
@pytest.mark.parametrize("question_type", NA_QUESTION_TYPES)
|
| 42 |
-
def test_every_na_question_type_builds(question_type):
|
| 43 |
-
assert blind_prompts.build_prompt(question_type, "q?")
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
@pytest.mark.parametrize("question_type", MCA_QUESTION_TYPES)
|
| 47 |
-
def test_every_mca_question_type_builds(question_type):
|
| 48 |
-
assert blind_prompts.build_prompt(question_type, "q?", ["A. x", "B. y"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_E/test_run.py
DELETED
|
@@ -1,97 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/E/run.py -- result-record shape and result-file writing."""
|
| 2 |
-
|
| 3 |
-
import json
|
| 4 |
-
|
| 5 |
-
from harness import E
|
| 6 |
-
from harness.E import run as harness_run
|
| 7 |
-
|
| 8 |
-
_FAKE_ANSWER = {
|
| 9 |
-
"prompt_text": "<rendered chat template>",
|
| 10 |
-
"answer_text": "4",
|
| 11 |
-
"answer_raw": "<|im_start|>assistant\n4<|im_end|>",
|
| 12 |
-
"input_token_count": 42,
|
| 13 |
-
"vision_input_shapes": {},
|
| 14 |
-
"output_token_ids": [19, 151645],
|
| 15 |
-
"output_token_count": 2,
|
| 16 |
-
"hit_token_limit": False,
|
| 17 |
-
"eos_token_ids": [151645],
|
| 18 |
-
"generation_seconds": 0.2,
|
| 19 |
-
"device": "cuda",
|
| 20 |
-
"dtype": "bfloat16",
|
| 21 |
-
"library_versions": {"transformers": "5.14.1", "torch": "2.13.0+cu130"},
|
| 22 |
-
"generation_config": {
|
| 23 |
-
"max_new_tokens": 16,
|
| 24 |
-
"do_sample": False,
|
| 25 |
-
"temperature": 0.0,
|
| 26 |
-
"top_p": None,
|
| 27 |
-
"top_k": None,
|
| 28 |
-
"enable_thinking": False,
|
| 29 |
-
},
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
_FAKE_ROW = {
|
| 33 |
-
"id": 7,
|
| 34 |
-
"scene_name": "scene0001_00",
|
| 35 |
-
"dataset": "scannet",
|
| 36 |
-
"question_type": "object_counting",
|
| 37 |
-
"question": "How many chairs?",
|
| 38 |
-
"options": None,
|
| 39 |
-
"ground_truth": "4",
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
def test_results_dir_for_matches_model_and_protocol_only():
|
| 44 |
-
root = harness_run.results_dir_for("qwen3.5-4b", "base")
|
| 45 |
-
assert root == E.RESULTS_DIR / "qwen3.5-4b" / "base"
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
def test_results_dir_for_isolates_the_two_protocols():
|
| 49 |
-
assert harness_run.results_dir_for(
|
| 50 |
-
"qwen3.5-4b", "base"
|
| 51 |
-
) != harness_run.results_dir_for("qwen3.5-4b", "extended")
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
def test_results_dir_for_honors_explicit_override(tmp_path):
|
| 55 |
-
assert harness_run.results_dir_for("qwen3.5-4b", "base", tmp_path) == tmp_path
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
def test_build_record_has_no_scene_input_provenance():
|
| 59 |
-
record = harness_run._build_record(
|
| 60 |
-
_FAKE_ROW,
|
| 61 |
-
"full prompt text",
|
| 62 |
-
_FAKE_ANSWER,
|
| 63 |
-
"MRA:.5:.95:.05",
|
| 64 |
-
1.0,
|
| 65 |
-
"qwen3.5-4b",
|
| 66 |
-
"/root/models/qwen3.5-4b",
|
| 67 |
-
"base",
|
| 68 |
-
)
|
| 69 |
-
assert record["condition"] == "base"
|
| 70 |
-
assert record["protocol"] == "base"
|
| 71 |
-
assert record["question"] == "How many chairs?"
|
| 72 |
-
assert record["answer_given"] == "4"
|
| 73 |
-
assert record["metric"] == "MRA:.5:.95:.05"
|
| 74 |
-
assert record["score"] == 1.0
|
| 75 |
-
# Blind: no frame or spatial-code provenance of any kind.
|
| 76 |
-
assert "frame_selection" not in record
|
| 77 |
-
assert "video_path" not in record
|
| 78 |
-
assert "frame_indices" not in record
|
| 79 |
-
assert "spatial_code_format" not in record
|
| 80 |
-
assert "spatial_code_path" not in record
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
def test_write_question_result_writes_one_json_file_per_question(tmp_path):
|
| 84 |
-
path, record = harness_run.write_question_result(
|
| 85 |
-
_FAKE_ROW,
|
| 86 |
-
"full prompt text",
|
| 87 |
-
_FAKE_ANSWER,
|
| 88 |
-
"MRA:.5:.95:.05",
|
| 89 |
-
1.0,
|
| 90 |
-
"qwen3.5-4b",
|
| 91 |
-
"/root/models/qwen3.5-4b",
|
| 92 |
-
"base",
|
| 93 |
-
results_dir=tmp_path,
|
| 94 |
-
)
|
| 95 |
-
assert path == tmp_path / "scene0001_00" / "7.json"
|
| 96 |
-
on_disk = json.loads(path.read_text())
|
| 97 |
-
assert on_disk == record
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_E/test_sweep.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
"""Tests for harness/E/sweep.py -- per-model blind-floor sweeping."""
|
| 2 |
-
|
| 3 |
-
import pytest
|
| 4 |
-
|
| 5 |
-
from harness.E import sweep
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def test_sweep_imports():
|
| 9 |
-
assert callable(sweep.main)
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
def test_sweep_runs_every_model_through_launch(monkeypatch):
|
| 13 |
-
launched = []
|
| 14 |
-
monkeypatch.setattr(
|
| 15 |
-
sweep.harness_launch,
|
| 16 |
-
"launch",
|
| 17 |
-
lambda model, scenes, **kwargs: launched.append(
|
| 18 |
-
(model, kwargs.get("extended"))
|
| 19 |
-
),
|
| 20 |
-
)
|
| 21 |
-
sweep.sweep(["qwen3.5-2b", "qwen3.5-4b"], ["scene_a"], extended=True)
|
| 22 |
-
assert launched == [("qwen3.5-2b", True), ("qwen3.5-4b", True)]
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
def test_sweep_defaults_to_base_protocol(monkeypatch):
|
| 26 |
-
launched = []
|
| 27 |
-
monkeypatch.setattr(
|
| 28 |
-
sweep.harness_launch,
|
| 29 |
-
"launch",
|
| 30 |
-
lambda model, scenes, **kwargs: launched.append(kwargs.get("extended")),
|
| 31 |
-
)
|
| 32 |
-
sweep.sweep(["qwen3.5-2b"], ["scene_a"])
|
| 33 |
-
assert launched == [False]
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
def test_sweep_parser_rejects_unknown_model(monkeypatch, capsys):
|
| 37 |
-
monkeypatch.setattr("sys.argv", ["sweep", "--models", "not-a-model"])
|
| 38 |
-
with pytest.raises(SystemExit):
|
| 39 |
-
sweep.main()
|
| 40 |
-
assert "unknown" in capsys.readouterr().err
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_F/__init__.py
DELETED
|
File without changes
|
tests/test_F/conftest.py
DELETED
|
@@ -1,12 +0,0 @@
|
|
| 1 |
-
"""Shared import setup for this test package."""
|
| 2 |
-
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
import sys
|
| 5 |
-
|
| 6 |
-
ROOT = Path(__file__).resolve().parents[2]
|
| 7 |
-
if str(ROOT) not in sys.path:
|
| 8 |
-
sys.path.insert(0, str(ROOT))
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def pytest_configure(config):
|
| 12 |
-
config.option.importmode = "importlib"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|