code backup: harness
Browse files- harness/B/launch.py +18 -1
- harness/B/prompts.py +41 -5
- harness/B/run.py +17 -1
harness/B/launch.py
CHANGED
|
@@ -26,6 +26,7 @@ if str(WORKSPACE_ROOT) not in sys.path:
|
|
| 26 |
from harness.A import EXTENDED_MAX_NEW_TOKENS, MAX_NEW_TOKENS # noqa: E402
|
| 27 |
from harness.A import models as vlm_models # noqa: E402
|
| 28 |
from harness.A.launch import scenes # noqa: E402
|
|
|
|
| 29 |
from harness.B import ( # noqa: E402
|
| 30 |
DEFAULT_DEPTH,
|
| 31 |
DEFAULT_INPUT_SELECTION,
|
|
@@ -51,6 +52,7 @@ def _load_run_module():
|
|
| 51 |
def _worker(
|
| 52 |
tasks, results, model, spatial_code_format, input_selection, frame_count, depth, tracking,
|
| 53 |
results_dir, gpu, cpu_threads, extended, reasoning_budget, force_budget,
|
|
|
|
| 54 |
):
|
| 55 |
if gpu is not None:
|
| 56 |
os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu)
|
|
@@ -85,6 +87,8 @@ def _worker(
|
|
| 85 |
extended=extended,
|
| 86 |
reasoning_budget=reasoning_budget,
|
| 87 |
force_budget=force_budget,
|
|
|
|
|
|
|
| 88 |
)
|
| 89 |
mean_score = (
|
| 90 |
sum(r["score"] for r in answered) / len(answered) if answered else None
|
|
@@ -100,6 +104,7 @@ def launch(
|
|
| 100 |
model, spatial_code_format, input_selection, frame_count, selected,
|
| 101 |
depth=DEFAULT_DEPTH, tracking=DEFAULT_TRACKING, results_dir=None, rebuild=False,
|
| 102 |
extended=True, reasoning_budget=EXTENDED_MAX_NEW_TOKENS, force_budget=MAX_NEW_TOKENS,
|
|
|
|
| 103 |
):
|
| 104 |
"""Answer every question for ``selected`` scenes, sharded across every visible GPU."""
|
| 105 |
protocol = "extended" if extended else "base"
|
|
@@ -149,7 +154,7 @@ def launch(
|
|
| 149 |
args=(
|
| 150 |
tasks, results, model, spatial_code_format, input_selection, frame_count,
|
| 151 |
depth, tracking, results_dir, gpu, cpu_threads, extended, reasoning_budget,
|
| 152 |
-
force_budget,
|
| 153 |
),
|
| 154 |
)
|
| 155 |
for gpu in assignments
|
|
@@ -200,6 +205,16 @@ def main():
|
|
| 200 |
"--base-protocol", action="store_true",
|
| 201 |
help="run harness.A's exact fixed 16-token protocol instead of the extended default",
|
| 202 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
|
| 204 |
parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
|
| 205 |
args = parser.parse_args()
|
|
@@ -223,6 +238,8 @@ def main():
|
|
| 223 |
depth=args.depth, tracking=args.tracking, results_dir=args.results_dir, rebuild=args.rebuild,
|
| 224 |
extended=not args.base_protocol,
|
| 225 |
reasoning_budget=args.reasoning_budget, force_budget=args.force_budget,
|
|
|
|
|
|
|
| 226 |
)
|
| 227 |
|
| 228 |
|
|
|
|
| 26 |
from harness.A import EXTENDED_MAX_NEW_TOKENS, MAX_NEW_TOKENS # noqa: E402
|
| 27 |
from harness.A import models as vlm_models # noqa: E402
|
| 28 |
from harness.A.launch import scenes # noqa: E402
|
| 29 |
+
from harness.B.prompts import PARAPHRASE_PRE_PROMPT # noqa: E402
|
| 30 |
from harness.B import ( # noqa: E402
|
| 31 |
DEFAULT_DEPTH,
|
| 32 |
DEFAULT_INPUT_SELECTION,
|
|
|
|
| 52 |
def _worker(
|
| 53 |
tasks, results, model, spatial_code_format, input_selection, frame_count, depth, tracking,
|
| 54 |
results_dir, gpu, cpu_threads, extended, reasoning_budget, force_budget,
|
| 55 |
+
serialization, context_line,
|
| 56 |
):
|
| 57 |
if gpu is not None:
|
| 58 |
os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu)
|
|
|
|
| 87 |
extended=extended,
|
| 88 |
reasoning_budget=reasoning_budget,
|
| 89 |
force_budget=force_budget,
|
| 90 |
+
serialization=serialization,
|
| 91 |
+
context_line=context_line,
|
| 92 |
)
|
| 93 |
mean_score = (
|
| 94 |
sum(r["score"] for r in answered) / len(answered) if answered else None
|
|
|
|
| 104 |
model, spatial_code_format, input_selection, frame_count, selected,
|
| 105 |
depth=DEFAULT_DEPTH, tracking=DEFAULT_TRACKING, results_dir=None, rebuild=False,
|
| 106 |
extended=True, reasoning_budget=EXTENDED_MAX_NEW_TOKENS, force_budget=MAX_NEW_TOKENS,
|
| 107 |
+
serialization="json", context_line=None,
|
| 108 |
):
|
| 109 |
"""Answer every question for ``selected`` scenes, sharded across every visible GPU."""
|
| 110 |
protocol = "extended" if extended else "base"
|
|
|
|
| 154 |
args=(
|
| 155 |
tasks, results, model, spatial_code_format, input_selection, frame_count,
|
| 156 |
depth, tracking, results_dir, gpu, cpu_threads, extended, reasoning_budget,
|
| 157 |
+
force_budget, serialization, context_line,
|
| 158 |
),
|
| 159 |
)
|
| 160 |
for gpu in assignments
|
|
|
|
| 205 |
"--base-protocol", action="store_true",
|
| 206 |
help="run harness.A's exact fixed 16-token protocol instead of the extended default",
|
| 207 |
)
|
| 208 |
+
parser.add_argument(
|
| 209 |
+
"--serialization", default="json",
|
| 210 |
+
help="robustness arm only: 'yaml' renders the identical code dict as YAML "
|
| 211 |
+
"(pair with an explicit --results-dir)",
|
| 212 |
+
)
|
| 213 |
+
parser.add_argument(
|
| 214 |
+
"--paraphrase-context", action="store_true", dest="paraphrase_context",
|
| 215 |
+
help="robustness arm only: the pre-registered paraphrased context line "
|
| 216 |
+
"(pair with an explicit --results-dir)",
|
| 217 |
+
)
|
| 218 |
parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
|
| 219 |
parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
|
| 220 |
args = parser.parse_args()
|
|
|
|
| 238 |
depth=args.depth, tracking=args.tracking, results_dir=args.results_dir, rebuild=args.rebuild,
|
| 239 |
extended=not args.base_protocol,
|
| 240 |
reasoning_budget=args.reasoning_budget, force_budget=args.force_budget,
|
| 241 |
+
serialization=args.serialization,
|
| 242 |
+
context_line=PARAPHRASE_PRE_PROMPT if args.paraphrase_context else None,
|
| 243 |
)
|
| 244 |
|
| 245 |
|
harness/B/prompts.py
CHANGED
|
@@ -37,18 +37,54 @@ CODE_DESCRIPTION = (
|
|
| 37 |
)
|
| 38 |
PRE_PROMPT = "This is a spatial code: " + CODE_DESCRIPTION
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
def build_prompt(
|
|
|
|
|
|
|
|
|
|
| 42 |
"""Return the full text prompt: context line, the spatial code itself, the question,
|
| 43 |
-
and the same VSI-Bench post-prompt harness.A uses for the same question_type.
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
if question_type in NA_QUESTION_TYPES:
|
| 46 |
-
return "\n".join([
|
| 47 |
if question_type in MCA_QUESTION_TYPES:
|
| 48 |
if not options:
|
| 49 |
raise ValueError(f"question_type {question_type!r} requires options")
|
| 50 |
options_block = "Options:\n" + "\n".join(options)
|
| 51 |
-
return "\n".join([
|
| 52 |
raise ValueError(
|
| 53 |
f"unknown question_type {question_type!r}; "
|
| 54 |
f"expected one of {MCA_QUESTION_TYPES + NA_QUESTION_TYPES}"
|
|
|
|
| 37 |
)
|
| 38 |
PRE_PROMPT = "This is a spatial code: " + CODE_DESCRIPTION
|
| 39 |
|
| 40 |
+
# The robustness arm's alternates (analysis/preregistration.md): a semantically
|
| 41 |
+
# equivalent paraphrase of the context line, and a YAML rendering of the identical
|
| 42 |
+
# code dict. Each changes exactly one surface property, so a result that survives
|
| 43 |
+
# both cannot be an artifact of the specific wording or serialization chosen.
|
| 44 |
+
PARAPHRASE_PRE_PROMPT = (
|
| 45 |
+
"Below is a spatial code -- a structured description, in JSON, of a room and the "
|
| 46 |
+
"objects inside it. Every field is explained by the schema embedded in the code."
|
| 47 |
+
)
|
| 48 |
+
SERIALIZATIONS = ("json", "yaml")
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def render_code(spatial_code, serialization="json"):
|
| 52 |
+
"""Serialize one spatial-code dict for prompting. "json" is the standard arm;
|
| 53 |
+
"yaml" renders the IDENTICAL dict (key order preserved, nothing added or
|
| 54 |
+
dropped) for the serialization-robustness arm."""
|
| 55 |
+
if serialization == "json":
|
| 56 |
+
return json.dumps(spatial_code, indent=1)
|
| 57 |
+
if serialization == "yaml":
|
| 58 |
+
import yaml
|
| 59 |
+
|
| 60 |
+
return yaml.safe_dump(spatial_code, sort_keys=False, width=100)
|
| 61 |
+
raise ValueError(
|
| 62 |
+
f"unknown serialization {serialization!r}; expected one of {SERIALIZATIONS}"
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
|
| 66 |
+
def build_prompt(
|
| 67 |
+
spatial_code, question_type, question, options=None,
|
| 68 |
+
serialization="json", context_line=None,
|
| 69 |
+
):
|
| 70 |
"""Return the full text prompt: context line, the spatial code itself, the question,
|
| 71 |
+
and the same VSI-Bench post-prompt harness.A uses for the same question_type.
|
| 72 |
+
``serialization`` and ``context_line`` exist ONLY for the robustness arm -- the
|
| 73 |
+
defaults reproduce the standard prompt byte-for-byte."""
|
| 74 |
+
code_text = render_code(spatial_code, serialization)
|
| 75 |
+
pre_prompt = PRE_PROMPT if context_line is None else context_line
|
| 76 |
+
if serialization == "yaml" and context_line is None:
|
| 77 |
+
# The context line must not claim JSON when the code is rendered as YAML --
|
| 78 |
+
# otherwise the serialization arm would carry a false description as a
|
| 79 |
+
# second, unintended factor.
|
| 80 |
+
pre_prompt = pre_prompt.replace("JSON", "YAML")
|
| 81 |
if question_type in NA_QUESTION_TYPES:
|
| 82 |
+
return "\n".join([pre_prompt, code_text, question, NA_POST_PROMPT])
|
| 83 |
if question_type in MCA_QUESTION_TYPES:
|
| 84 |
if not options:
|
| 85 |
raise ValueError(f"question_type {question_type!r} requires options")
|
| 86 |
options_block = "Options:\n" + "\n".join(options)
|
| 87 |
+
return "\n".join([pre_prompt, code_text, question, options_block, MCA_POST_PROMPT])
|
| 88 |
raise ValueError(
|
| 89 |
f"unknown question_type {question_type!r}; "
|
| 90 |
f"expected one of {MCA_QUESTION_TYPES + NA_QUESTION_TYPES}"
|
harness/B/run.py
CHANGED
|
@@ -36,6 +36,7 @@ from harness.B import ( # noqa: E402
|
|
| 36 |
)
|
| 37 |
from harness.B import prompts as code_prompts # noqa: E402
|
| 38 |
from harness.B import spatial_codes # noqa: E402
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
def results_dir_for(
|
|
@@ -146,6 +147,8 @@ def run(
|
|
| 146 |
extended=True,
|
| 147 |
reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
|
| 148 |
force_budget=MAX_NEW_TOKENS,
|
|
|
|
|
|
|
| 149 |
):
|
| 150 |
"""Answer every matching question with one model, given its scene's spatial code as
|
| 151 |
text (no video frames). Each question's full record is written to its own JSON file
|
|
@@ -182,7 +185,8 @@ def run(
|
|
| 182 |
code_cache[scene_id] = {"code": code, "path": path}
|
| 183 |
cached = code_cache[scene_id]
|
| 184 |
prompt = code_prompts.build_prompt(
|
| 185 |
-
cached["code"], row["question_type"], row["question"], row.get("options")
|
|
|
|
| 186 |
)
|
| 187 |
answer = (
|
| 188 |
adapter.answer_extended(
|
|
@@ -249,6 +253,16 @@ def main():
|
|
| 249 |
"--no-write", action="store_true",
|
| 250 |
help="skip writing per-question JSON files; print/score only",
|
| 251 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
parser.add_argument(
|
| 253 |
"--base-protocol", action="store_true",
|
| 254 |
help="run harness.A's exact fixed 16-token protocol (plain answer()) instead of "
|
|
@@ -277,6 +291,8 @@ def main():
|
|
| 277 |
results_dir=args.results_dir,
|
| 278 |
write_results=not args.no_write,
|
| 279 |
extended=not args.base_protocol,
|
|
|
|
|
|
|
| 280 |
reasoning_budget=args.reasoning_budget,
|
| 281 |
force_budget=args.force_budget,
|
| 282 |
)
|
|
|
|
| 36 |
)
|
| 37 |
from harness.B import prompts as code_prompts # noqa: E402
|
| 38 |
from harness.B import spatial_codes # noqa: E402
|
| 39 |
+
from harness.B.prompts import PARAPHRASE_PRE_PROMPT, SERIALIZATIONS # noqa: E402
|
| 40 |
|
| 41 |
|
| 42 |
def results_dir_for(
|
|
|
|
| 147 |
extended=True,
|
| 148 |
reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
|
| 149 |
force_budget=MAX_NEW_TOKENS,
|
| 150 |
+
serialization="json",
|
| 151 |
+
context_line=None,
|
| 152 |
):
|
| 153 |
"""Answer every matching question with one model, given its scene's spatial code as
|
| 154 |
text (no video frames). Each question's full record is written to its own JSON file
|
|
|
|
| 185 |
code_cache[scene_id] = {"code": code, "path": path}
|
| 186 |
cached = code_cache[scene_id]
|
| 187 |
prompt = code_prompts.build_prompt(
|
| 188 |
+
cached["code"], row["question_type"], row["question"], row.get("options"),
|
| 189 |
+
serialization=serialization, context_line=context_line,
|
| 190 |
)
|
| 191 |
answer = (
|
| 192 |
adapter.answer_extended(
|
|
|
|
| 253 |
"--no-write", action="store_true",
|
| 254 |
help="skip writing per-question JSON files; print/score only",
|
| 255 |
)
|
| 256 |
+
parser.add_argument(
|
| 257 |
+
"--serialization", default="json", choices=SERIALIZATIONS,
|
| 258 |
+
help="robustness arm only: render the identical code dict as YAML instead of "
|
| 259 |
+
"JSON (pair with an explicit --results-dir so the arm stays isolated)",
|
| 260 |
+
)
|
| 261 |
+
parser.add_argument(
|
| 262 |
+
"--paraphrase-context", action="store_true", dest="paraphrase_context",
|
| 263 |
+
help="robustness arm only: use the pre-registered paraphrased context line "
|
| 264 |
+
"(pair with an explicit --results-dir)",
|
| 265 |
+
)
|
| 266 |
parser.add_argument(
|
| 267 |
"--base-protocol", action="store_true",
|
| 268 |
help="run harness.A's exact fixed 16-token protocol (plain answer()) instead of "
|
|
|
|
| 291 |
results_dir=args.results_dir,
|
| 292 |
write_results=not args.no_write,
|
| 293 |
extended=not args.base_protocol,
|
| 294 |
+
serialization=args.serialization,
|
| 295 |
+
context_line=PARAPHRASE_PRE_PROMPT if args.paraphrase_context else None,
|
| 296 |
reasoning_budget=args.reasoning_budget,
|
| 297 |
force_budget=args.force_budget,
|
| 298 |
)
|