AntonioJun commited on
Commit
74fb23e
·
verified ·
1 Parent(s): 092603a

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. encoder/__pycache__/ground_truth.cpython-311.pyc +0 -0
  2. harness/A/__pycache__/launch.cpython-311.pyc +0 -0
  3. harness/A/launch.py +69 -22
  4. harness/A/models.py +67 -27
  5. harness/A/sweep.py +53 -20
  6. harness/B/__init__.py +9 -4
  7. harness/B/__pycache__/__init__.cpython-311.pyc +0 -0
  8. harness/B/__pycache__/launch.cpython-311.pyc +0 -0
  9. harness/B/__pycache__/run.cpython-311.pyc +0 -0
  10. harness/B/prompts.py +81 -63
  11. harness/B/run.py +117 -37
  12. harness/C/__init__.py +1 -3
  13. harness/C/__pycache__/__init__.cpython-311.pyc +0 -0
  14. harness/C/__pycache__/launch.cpython-311.pyc +0 -0
  15. harness/C/__pycache__/overlay.cpython-311.pyc +0 -0
  16. harness/C/__pycache__/overlay_launch.cpython-311.pyc +0 -0
  17. harness/C/__pycache__/prompts.cpython-311.pyc +0 -0
  18. harness/C/__pycache__/run.cpython-311.pyc +0 -0
  19. harness/C/__pycache__/sweep.cpython-311.pyc +0 -0
  20. harness/C/launch.py +104 -29
  21. harness/C/overlay.py +102 -18
  22. harness/C/overlay_launch.py +44 -11
  23. harness/C/prompts.py +9 -3
  24. harness/C/run.py +135 -39
  25. harness/C/sweep.py +90 -32
  26. harness/D/__init__.py +9 -4
  27. harness/D/__pycache__/__init__.cpython-311.pyc +0 -0
  28. harness/D/__pycache__/launch.cpython-311.pyc +0 -0
  29. harness/D/__pycache__/prompts.cpython-311.pyc +0 -0
  30. harness/D/__pycache__/run.cpython-311.pyc +0 -0
  31. harness/D/__pycache__/sweep.cpython-311.pyc +0 -0
  32. harness/D/__pycache__/symbolic_eval.cpython-311.pyc +0 -0
  33. harness/D/launch.py +109 -32
  34. harness/D/prompts.py +12 -3
  35. harness/D/run.py +131 -41
  36. harness/D/sweep.py +81 -30
  37. harness/D/symbolic_eval.py +23 -8
  38. harness/E/__init__.py +1 -3
  39. harness/E/__pycache__/__init__.cpython-311.pyc +0 -0
  40. harness/E/__pycache__/launch.cpython-311.pyc +0 -0
  41. harness/E/__pycache__/prompts.cpython-311.pyc +0 -0
  42. harness/E/__pycache__/run.cpython-311.pyc +0 -0
  43. harness/E/__pycache__/sweep.cpython-311.pyc +0 -0
  44. harness/E/launch.py +45 -11
  45. harness/E/prompts.py +6 -1
  46. harness/E/run.py +46 -11
  47. harness/E/sweep.py +29 -10
  48. harness/F/__init__.py +1 -0
  49. harness/F/__pycache__/__init__.cpython-311.pyc +0 -0
  50. harness/F/__pycache__/launch.cpython-311.pyc +0 -0
encoder/__pycache__/ground_truth.cpython-311.pyc CHANGED
Binary files a/encoder/__pycache__/ground_truth.cpython-311.pyc and b/encoder/__pycache__/ground_truth.cpython-311.pyc differ
 
harness/A/__pycache__/launch.cpython-311.pyc CHANGED
Binary files a/harness/A/__pycache__/launch.cpython-311.pyc and b/harness/A/__pycache__/launch.cpython-311.pyc differ
 
harness/A/launch.py CHANGED
@@ -47,12 +47,24 @@ def _load_run_module():
47
  def scenes():
48
  """Return unique VSI-Bench scenes in their original manifest order."""
49
  with open(JSONL) as manifest:
50
- return list(dict.fromkeys(str(json.loads(line)["scene_name"]) for line in manifest))
 
 
51
 
52
 
53
  def _worker(
54
- tasks, results, model, frame_selection, frame_count, results_dir, gpu, cpu_threads,
55
- extended, reasoning_budget, force_budget, truncated_budget,
 
 
 
 
 
 
 
 
 
 
56
  ):
57
  if gpu is not None:
58
  os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu)
@@ -100,8 +112,15 @@ def _worker(
100
 
101
 
102
  def launch(
103
- model, frame_selection, frame_count, selected, results_dir=None, rebuild=False,
104
- extended=False, reasoning_budget=EXTENDED_MAX_NEW_TOKENS, force_budget=MAX_NEW_TOKENS,
 
 
 
 
 
 
 
105
  truncated_budget=None,
106
  ):
107
  """Answer every question for ``selected`` scenes, sharded across every visible GPU.
@@ -112,23 +131,30 @@ def launch(
112
  if extended and truncated_budget is not None:
113
  raise ValueError("extended and truncated_budget are mutually exclusive")
114
  protocol = (
115
- f"{reasoning_budget}" if extended
116
- else f"truncated/{truncated_budget}" if truncated_budget is not None
117
- else "base"
118
  )
119
  condition = f"{model}/{protocol}/{frame_selection}/{frame_count}"
120
  run = _load_run_module()
121
- root = run.results_dir_for(model, protocol, frame_selection, frame_count, results_dir)
 
 
122
  pending = []
123
  completed = 0
124
  for scene in selected:
125
  rows = run.load_questions(scene=scene)
126
- answered = all(
127
- (root / scene / f"{row['id']}.json").is_file() for row in rows
128
- )
 
 
129
  if answered and not rebuild:
130
  completed += 1
131
- print(f"[{condition} {completed}/{len(selected)}] {scene}: skipped", flush=True)
 
 
 
132
  else:
133
  pending.append(scene)
134
  if not pending:
@@ -156,8 +182,18 @@ def launch(
156
  context.Process(
157
  target=_worker,
158
  args=(
159
- tasks, results, model, frame_selection, frame_count, results_dir,
160
- gpu, cpu_threads, extended, reasoning_budget, force_budget, truncated_budget,
 
 
 
 
 
 
 
 
 
 
161
  ),
162
  )
163
  for gpu in assignments
@@ -188,11 +224,14 @@ def main():
188
  parser = argparse.ArgumentParser()
189
  parser.add_argument("scene", nargs="?")
190
  parser.add_argument(
191
- "--scenes", help="comma-separated scenes (cannot be combined with positional scene)"
 
192
  )
193
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
194
  parser.add_argument(
195
- "--frame-selection", default=DEFAULT_FRAME_SELECTION, choices=FRAME_SELECTIONS,
 
 
196
  dest="frame_selection",
197
  )
198
  parser.add_argument("--frames", type=int, default=FRAMES_PER_VIDEO)
@@ -210,7 +249,9 @@ def main():
210
  parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
211
  parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
212
  parser.add_argument(
213
- "--truncated-budget", type=int, default=None,
 
 
214
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
215
  "rescue) at this token cap, under its own truncated/<budget> path segment "
216
  "(mutually exclusive with --extended)",
@@ -236,10 +277,16 @@ def main():
236
  if args.extended and args.truncated_budget is not None:
237
  parser.error("--extended and --truncated-budget are mutually exclusive")
238
  launch(
239
- args.model, args.frame_selection, args.frames, selected,
240
- results_dir=args.results_dir, rebuild=args.rebuild,
241
- extended=args.extended, reasoning_budget=args.reasoning_budget,
242
- force_budget=args.force_budget, truncated_budget=args.truncated_budget,
 
 
 
 
 
 
243
  )
244
 
245
 
 
47
  def scenes():
48
  """Return unique VSI-Bench scenes in their original manifest order."""
49
  with open(JSONL) as manifest:
50
+ return list(
51
+ dict.fromkeys(str(json.loads(line)["scene_name"]) for line in manifest)
52
+ )
53
 
54
 
55
  def _worker(
56
+ tasks,
57
+ results,
58
+ model,
59
+ frame_selection,
60
+ frame_count,
61
+ results_dir,
62
+ gpu,
63
+ cpu_threads,
64
+ extended,
65
+ reasoning_budget,
66
+ force_budget,
67
+ truncated_budget,
68
  ):
69
  if gpu is not None:
70
  os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu)
 
112
 
113
 
114
  def launch(
115
+ model,
116
+ frame_selection,
117
+ frame_count,
118
+ selected,
119
+ results_dir=None,
120
+ rebuild=False,
121
+ extended=False,
122
+ reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
123
+ force_budget=MAX_NEW_TOKENS,
124
  truncated_budget=None,
125
  ):
126
  """Answer every question for ``selected`` scenes, sharded across every visible GPU.
 
131
  if extended and truncated_budget is not None:
132
  raise ValueError("extended and truncated_budget are mutually exclusive")
133
  protocol = (
134
+ f"{reasoning_budget}"
135
+ if extended
136
+ else f"truncated/{truncated_budget}" if truncated_budget is not None else "base"
137
  )
138
  condition = f"{model}/{protocol}/{frame_selection}/{frame_count}"
139
  run = _load_run_module()
140
+ root = run.results_dir_for(
141
+ model, protocol, frame_selection, frame_count, results_dir
142
+ )
143
  pending = []
144
  completed = 0
145
  for scene in selected:
146
  rows = run.load_questions(scene=scene)
147
+ if not rows:
148
+ raise ValueError(
149
+ f"no questions found for scene {scene!r}; check the manifest/scene selection"
150
+ )
151
+ answered = all((root / scene / f"{row['id']}.json").is_file() for row in rows)
152
  if answered and not rebuild:
153
  completed += 1
154
+ print(
155
+ f"[{condition} {completed}/{len(selected)}] {scene}: skipped",
156
+ flush=True,
157
+ )
158
  else:
159
  pending.append(scene)
160
  if not pending:
 
182
  context.Process(
183
  target=_worker,
184
  args=(
185
+ tasks,
186
+ results,
187
+ model,
188
+ frame_selection,
189
+ frame_count,
190
+ results_dir,
191
+ gpu,
192
+ cpu_threads,
193
+ extended,
194
+ reasoning_budget,
195
+ force_budget,
196
+ truncated_budget,
197
  ),
198
  )
199
  for gpu in assignments
 
224
  parser = argparse.ArgumentParser()
225
  parser.add_argument("scene", nargs="?")
226
  parser.add_argument(
227
+ "--scenes",
228
+ help="comma-separated scenes (cannot be combined with positional scene)",
229
  )
230
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
231
  parser.add_argument(
232
+ "--frame-selection",
233
+ default=DEFAULT_FRAME_SELECTION,
234
+ choices=FRAME_SELECTIONS,
235
  dest="frame_selection",
236
  )
237
  parser.add_argument("--frames", type=int, default=FRAMES_PER_VIDEO)
 
249
  parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
250
  parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
251
  parser.add_argument(
252
+ "--truncated-budget",
253
+ type=int,
254
+ default=None,
255
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
256
  "rescue) at this token cap, under its own truncated/<budget> path segment "
257
  "(mutually exclusive with --extended)",
 
277
  if args.extended and args.truncated_budget is not None:
278
  parser.error("--extended and --truncated-budget are mutually exclusive")
279
  launch(
280
+ args.model,
281
+ args.frame_selection,
282
+ args.frames,
283
+ selected,
284
+ results_dir=args.results_dir,
285
+ rebuild=args.rebuild,
286
+ extended=args.extended,
287
+ reasoning_budget=args.reasoning_budget,
288
+ force_budget=args.force_budget,
289
+ truncated_budget=args.truncated_budget,
290
  )
291
 
292
 
harness/A/models.py CHANGED
@@ -79,8 +79,13 @@ class VLMAdapter(ABC):
79
  """
80
 
81
  @abstractmethod
82
- def answer_extended(self, frames, question, reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
83
- force_budget=MAX_NEW_TOKENS):
 
 
 
 
 
84
  """Same record shape as ``answer``, but with a much larger first-pass budget to
85
  work through the input before answering. If the model does not conclude within
86
  that budget (hits it without emitting an end-of-sequence token), a short forced
@@ -97,8 +102,10 @@ class VLMAdapter(ABC):
97
  whether a silent no-op is acceptable for their arm."""
98
  if "enable_thinking" not in type(self).chat_template_kwargs:
99
  return False
100
- self.chat_template_kwargs = {**type(self).chat_template_kwargs,
101
- "enable_thinking": bool(enabled)}
 
 
102
  return True
103
 
104
  def unload(self):
@@ -138,11 +145,18 @@ class _TransformersVLMAdapter(VLMAdapter):
138
  """Render one chat turn to both plain text and tokenized model inputs."""
139
  messages = [{"role": "user", "content": _numbered_content(frames, question)}]
140
  prompt_text = self.processor.apply_chat_template(
141
- messages, add_generation_prompt=True, tokenize=False, **self.chat_template_kwargs,
 
 
 
142
  )
143
  inputs = self.processor.apply_chat_template(
144
- messages, add_generation_prompt=True, tokenize=True,
145
- return_dict=True, return_tensors="pt", **self.chat_template_kwargs,
 
 
 
 
146
  ).to(self.device)
147
  # Shapes of every non-text processor output (pixel_values, image_grid_thw, ...) --
148
  # generic across model families instead of hunting each one's own vision placeholder
@@ -169,8 +183,12 @@ class _TransformersVLMAdapter(VLMAdapter):
169
  start = time.monotonic()
170
  with torch.no_grad():
171
  generated = self.model.generate(
172
- **inputs, max_new_tokens=max_new_tokens, do_sample=DO_SAMPLE,
173
- temperature=None, top_p=None, top_k=None,
 
 
 
 
174
  )
175
  if self.device.startswith("cuda"):
176
  torch.cuda.synchronize()
@@ -179,11 +197,12 @@ class _TransformersVLMAdapter(VLMAdapter):
179
  def _decode_new_tokens(self, generated, input_token_count, max_new_tokens, eos_ids):
180
  """Split one generate() output into new-token ids + decoded text + hit-limit flag."""
181
  output_token_ids = generated[0][input_token_count:].tolist()
182
- hit_token_limit = (
183
- len(output_token_ids) >= max_new_tokens
184
- and (not output_token_ids or output_token_ids[-1] not in eos_ids)
185
  )
186
- answer_text = self.processor.decode(output_token_ids, skip_special_tokens=True).strip()
 
 
187
  answer_raw = self.processor.decode(output_token_ids, skip_special_tokens=False)
188
  return output_token_ids, hit_token_limit, answer_text, answer_raw
189
 
@@ -201,8 +220,8 @@ class _TransformersVLMAdapter(VLMAdapter):
201
  input_token_count = int(inputs["input_ids"].shape[1])
202
  generated, generation_seconds = self._generate(inputs, cap)
203
  eos_ids = self._eos_ids()
204
- output_token_ids, hit_token_limit, answer_text, answer_raw = self._decode_new_tokens(
205
- generated, input_token_count, cap, eos_ids
206
  )
207
 
208
  return {
@@ -229,8 +248,13 @@ class _TransformersVLMAdapter(VLMAdapter):
229
  },
230
  }
231
 
232
- def answer_extended(self, frames, question, reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
233
- force_budget=MAX_NEW_TOKENS):
 
 
 
 
 
234
  import torch
235
 
236
  if self.model is None or self.processor is None:
@@ -241,7 +265,9 @@ class _TransformersVLMAdapter(VLMAdapter):
241
 
242
  generated, reasoning_seconds = self._generate(inputs, reasoning_budget)
243
  reasoning_token_ids, reasoning_hit_limit, reasoning_text, reasoning_raw = (
244
- self._decode_new_tokens(generated, input_token_count, reasoning_budget, eos_ids)
 
 
245
  )
246
 
247
  thinking = bool(self.chat_template_kwargs.get("enable_thinking"))
@@ -257,9 +283,11 @@ class _TransformersVLMAdapter(VLMAdapter):
257
  # budget to extract that answer. Multimodal tensors (pixel_values, etc.) must
258
  # be resupplied -- the continued sequence still contains the original image
259
  # placeholder tokens, and generate() recomputes their embeddings from scratch.
260
- force_text = ("\n</think>\n" + FORCE_ANSWER_PROMPT) if (
261
- thinking and not think_closed
262
- ) else FORCE_ANSWER_PROMPT
 
 
263
  force_prompt_ids = self.processor.tokenizer(
264
  force_text, return_tensors="pt", add_special_tokens=False
265
  )["input_ids"].to(self.device)
@@ -276,17 +304,27 @@ class _TransformersVLMAdapter(VLMAdapter):
276
  # placeholder, so pad with zeros. Per-patch tensors (pixel_values,
277
  # image_grid_thw, ...) don't depend on sequence length at all and pass
278
  # through unchanged -- this check is what tells the two apart.
279
- if hasattr(value, "shape") and value.dim() >= 2 and value.shape[1] == input_token_count:
280
- pad = value.new_zeros((value.shape[0], added_length) + tuple(value.shape[2:]))
 
 
 
 
 
 
281
  value = torch.cat([value, pad], dim=1)
282
  continued_inputs[key] = value
283
  continued_inputs["input_ids"] = continued_ids
284
  continued_inputs["attention_mask"] = continued_mask
285
  forced_input_token_count = int(continued_ids.shape[1])
286
 
287
- forced_generated, forced_seconds = self._generate(continued_inputs, force_budget)
288
- output_token_ids, hit_token_limit, answer_text, answer_raw = self._decode_new_tokens(
289
- forced_generated, forced_input_token_count, force_budget, eos_ids
 
 
 
 
290
  )
291
  generation_seconds += forced_seconds
292
  else:
@@ -380,5 +418,7 @@ def get_adapter(model):
380
  """Create one unloaded adapter bound to a registered model's checkpoint path."""
381
  adapter_type = _ADAPTERS.get(model)
382
  if adapter_type is None:
383
- raise KeyError(f"unknown harness model {model!r}; expected one of {available_models()}")
 
 
384
  return adapter_type(MODEL_PATHS[model])
 
79
  """
80
 
81
  @abstractmethod
82
+ def answer_extended(
83
+ self,
84
+ frames,
85
+ question,
86
+ reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
87
+ force_budget=MAX_NEW_TOKENS,
88
+ ):
89
  """Same record shape as ``answer``, but with a much larger first-pass budget to
90
  work through the input before answering. If the model does not conclude within
91
  that budget (hits it without emitting an end-of-sequence token), a short forced
 
102
  whether a silent no-op is acceptable for their arm."""
103
  if "enable_thinking" not in type(self).chat_template_kwargs:
104
  return False
105
+ self.chat_template_kwargs = {
106
+ **type(self).chat_template_kwargs,
107
+ "enable_thinking": bool(enabled),
108
+ }
109
  return True
110
 
111
  def unload(self):
 
145
  """Render one chat turn to both plain text and tokenized model inputs."""
146
  messages = [{"role": "user", "content": _numbered_content(frames, question)}]
147
  prompt_text = self.processor.apply_chat_template(
148
+ messages,
149
+ add_generation_prompt=True,
150
+ tokenize=False,
151
+ **self.chat_template_kwargs,
152
  )
153
  inputs = self.processor.apply_chat_template(
154
+ messages,
155
+ add_generation_prompt=True,
156
+ tokenize=True,
157
+ return_dict=True,
158
+ return_tensors="pt",
159
+ **self.chat_template_kwargs,
160
  ).to(self.device)
161
  # Shapes of every non-text processor output (pixel_values, image_grid_thw, ...) --
162
  # generic across model families instead of hunting each one's own vision placeholder
 
183
  start = time.monotonic()
184
  with torch.no_grad():
185
  generated = self.model.generate(
186
+ **inputs,
187
+ max_new_tokens=max_new_tokens,
188
+ do_sample=DO_SAMPLE,
189
+ temperature=None,
190
+ top_p=None,
191
+ top_k=None,
192
  )
193
  if self.device.startswith("cuda"):
194
  torch.cuda.synchronize()
 
197
  def _decode_new_tokens(self, generated, input_token_count, max_new_tokens, eos_ids):
198
  """Split one generate() output into new-token ids + decoded text + hit-limit flag."""
199
  output_token_ids = generated[0][input_token_count:].tolist()
200
+ hit_token_limit = len(output_token_ids) >= max_new_tokens and (
201
+ not output_token_ids or output_token_ids[-1] not in eos_ids
 
202
  )
203
+ answer_text = self.processor.decode(
204
+ output_token_ids, skip_special_tokens=True
205
+ ).strip()
206
  answer_raw = self.processor.decode(output_token_ids, skip_special_tokens=False)
207
  return output_token_ids, hit_token_limit, answer_text, answer_raw
208
 
 
220
  input_token_count = int(inputs["input_ids"].shape[1])
221
  generated, generation_seconds = self._generate(inputs, cap)
222
  eos_ids = self._eos_ids()
223
+ output_token_ids, hit_token_limit, answer_text, answer_raw = (
224
+ self._decode_new_tokens(generated, input_token_count, cap, eos_ids)
225
  )
226
 
227
  return {
 
248
  },
249
  }
250
 
251
+ def answer_extended(
252
+ self,
253
+ frames,
254
+ question,
255
+ reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
256
+ force_budget=MAX_NEW_TOKENS,
257
+ ):
258
  import torch
259
 
260
  if self.model is None or self.processor is None:
 
265
 
266
  generated, reasoning_seconds = self._generate(inputs, reasoning_budget)
267
  reasoning_token_ids, reasoning_hit_limit, reasoning_text, reasoning_raw = (
268
+ self._decode_new_tokens(
269
+ generated, input_token_count, reasoning_budget, eos_ids
270
+ )
271
  )
272
 
273
  thinking = bool(self.chat_template_kwargs.get("enable_thinking"))
 
283
  # budget to extract that answer. Multimodal tensors (pixel_values, etc.) must
284
  # be resupplied -- the continued sequence still contains the original image
285
  # placeholder tokens, and generate() recomputes their embeddings from scratch.
286
+ force_text = (
287
+ ("\n</think>\n" + FORCE_ANSWER_PROMPT)
288
+ if (thinking and not think_closed)
289
+ else FORCE_ANSWER_PROMPT
290
+ )
291
  force_prompt_ids = self.processor.tokenizer(
292
  force_text, return_tensors="pt", add_special_tokens=False
293
  )["input_ids"].to(self.device)
 
304
  # placeholder, so pad with zeros. Per-patch tensors (pixel_values,
305
  # image_grid_thw, ...) don't depend on sequence length at all and pass
306
  # through unchanged -- this check is what tells the two apart.
307
+ if (
308
+ hasattr(value, "shape")
309
+ and value.dim() >= 2
310
+ and value.shape[1] == input_token_count
311
+ ):
312
+ pad = value.new_zeros(
313
+ (value.shape[0], added_length) + tuple(value.shape[2:])
314
+ )
315
  value = torch.cat([value, pad], dim=1)
316
  continued_inputs[key] = value
317
  continued_inputs["input_ids"] = continued_ids
318
  continued_inputs["attention_mask"] = continued_mask
319
  forced_input_token_count = int(continued_ids.shape[1])
320
 
321
+ forced_generated, forced_seconds = self._generate(
322
+ continued_inputs, force_budget
323
+ )
324
+ output_token_ids, hit_token_limit, answer_text, answer_raw = (
325
+ self._decode_new_tokens(
326
+ forced_generated, forced_input_token_count, force_budget, eos_ids
327
+ )
328
  )
329
  generation_seconds += forced_seconds
330
  else:
 
418
  """Create one unloaded adapter bound to a registered model's checkpoint path."""
419
  adapter_type = _ADAPTERS.get(model)
420
  if adapter_type is None:
421
+ raise KeyError(
422
+ f"unknown harness model {model!r}; expected one of {available_models()}"
423
+ )
424
  return adapter_type(MODEL_PATHS[model])
harness/A/sweep.py CHANGED
@@ -33,7 +33,9 @@ def _parse_csv_choice(value, valid, flag):
33
  return list(valid)
34
  unknown = [item for item in items if item not in valid]
35
  if unknown:
36
- raise ValueError(f"unknown {flag} value(s) {unknown}; expected one of {valid} (or 'all')")
 
 
37
  return list(dict.fromkeys(items))
38
 
39
 
@@ -66,15 +68,22 @@ def build_plan(models, frame_selections, frame_counts):
66
 
67
 
68
  def sweep(
69
- models, frame_selections, frame_counts, selected_scenes, results_dir=None, rebuild=False,
70
- extended=False, reasoning_budget=EXTENDED_MAX_NEW_TOKENS, truncated_budget=None,
 
 
 
 
 
 
 
71
  ):
72
  """Run every (model, frame_selection, frame_count) triple across all visible GPUs."""
73
  plan = build_plan(models, frame_selections, frame_counts)
74
  protocol = (
75
- f"{reasoning_budget}" if extended
76
- else f"truncated/{truncated_budget}" if truncated_budget is not None
77
- else "base"
78
  )
79
  for index, (model, frame_selection, frame_count) in enumerate(plan, start=1):
80
  print(
@@ -82,9 +91,15 @@ def sweep(
82
  flush=True,
83
  )
84
  harness_launch.launch(
85
- model, frame_selection, frame_count, selected_scenes,
86
- results_dir=results_dir, rebuild=rebuild, extended=extended,
87
- reasoning_budget=reasoning_budget, truncated_budget=truncated_budget,
 
 
 
 
 
 
88
  )
89
 
90
 
@@ -92,35 +107,45 @@ def main():
92
  parser = argparse.ArgumentParser()
93
  parser.add_argument("scene", nargs="?")
94
  parser.add_argument(
95
- "--scenes", help="comma-separated scenes (cannot be combined with positional scene)"
 
96
  )
97
  parser.add_argument(
98
- "--models", required=True,
 
99
  help=f"comma-separated models (or 'all'); one of {vlm_models.available_models()}",
100
  )
101
  parser.add_argument(
102
- "--frame-selections", required=True, dest="frame_selections",
 
 
103
  help=f"comma-separated selections (or 'all'); one of {FRAME_SELECTIONS}",
104
  )
105
  parser.add_argument(
106
- "--frames", required=True,
 
107
  help="comma-separated frame counts, e.g. 16,32,64",
108
  )
109
  parser.add_argument("--results-dir", default=None)
110
  parser.add_argument("--rebuild", action="store_true")
111
  parser.add_argument(
112
- "--extended", action="store_true",
 
113
  help="run the whole sweep under the extended protocol instead of the fixed "
114
  "16-token VSI-Bench protocol (the same flag harness.A.run/launch take)",
115
  )
116
  parser.add_argument(
117
- "--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS,
 
 
118
  dest="reasoning_budget",
119
  help="extended-protocol first-pass budget (the calibrated value from "
120
  "analysis/preregistration.md, e.g. 512)",
121
  )
122
  parser.add_argument(
123
- "--truncated-budget", type=int, default=None,
 
 
124
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
125
  "rescue) at this token cap (mutually exclusive with --extended)",
126
  )
@@ -131,7 +156,9 @@ def main():
131
  parser.error("--extended and --truncated-budget are mutually exclusive")
132
 
133
  try:
134
- models = _parse_csv_choice(args.models, vlm_models.available_models(), "--models")
 
 
135
  frame_selections = _parse_csv_choice(
136
  args.frame_selections, FRAME_SELECTIONS, "--frame-selections"
137
  )
@@ -148,9 +175,15 @@ def main():
148
  selected = [args.scene] if args.scene else harness_launch.scenes()
149
 
150
  sweep(
151
- models, frame_selections, frame_counts, selected,
152
- results_dir=args.results_dir, rebuild=args.rebuild, extended=args.extended,
153
- reasoning_budget=args.reasoning_budget, truncated_budget=args.truncated_budget,
 
 
 
 
 
 
154
  )
155
 
156
 
 
33
  return list(valid)
34
  unknown = [item for item in items if item not in valid]
35
  if unknown:
36
+ raise ValueError(
37
+ f"unknown {flag} value(s) {unknown}; expected one of {valid} (or 'all')"
38
+ )
39
  return list(dict.fromkeys(items))
40
 
41
 
 
68
 
69
 
70
  def sweep(
71
+ models,
72
+ frame_selections,
73
+ frame_counts,
74
+ selected_scenes,
75
+ results_dir=None,
76
+ rebuild=False,
77
+ extended=False,
78
+ reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
79
+ truncated_budget=None,
80
  ):
81
  """Run every (model, frame_selection, frame_count) triple across all visible GPUs."""
82
  plan = build_plan(models, frame_selections, frame_counts)
83
  protocol = (
84
+ f"{reasoning_budget}"
85
+ if extended
86
+ else f"truncated/{truncated_budget}" if truncated_budget is not None else "base"
87
  )
88
  for index, (model, frame_selection, frame_count) in enumerate(plan, start=1):
89
  print(
 
91
  flush=True,
92
  )
93
  harness_launch.launch(
94
+ model,
95
+ frame_selection,
96
+ frame_count,
97
+ selected_scenes,
98
+ results_dir=results_dir,
99
+ rebuild=rebuild,
100
+ extended=extended,
101
+ reasoning_budget=reasoning_budget,
102
+ truncated_budget=truncated_budget,
103
  )
104
 
105
 
 
107
  parser = argparse.ArgumentParser()
108
  parser.add_argument("scene", nargs="?")
109
  parser.add_argument(
110
+ "--scenes",
111
+ help="comma-separated scenes (cannot be combined with positional scene)",
112
  )
113
  parser.add_argument(
114
+ "--models",
115
+ required=True,
116
  help=f"comma-separated models (or 'all'); one of {vlm_models.available_models()}",
117
  )
118
  parser.add_argument(
119
+ "--frame-selections",
120
+ required=True,
121
+ dest="frame_selections",
122
  help=f"comma-separated selections (or 'all'); one of {FRAME_SELECTIONS}",
123
  )
124
  parser.add_argument(
125
+ "--frames",
126
+ required=True,
127
  help="comma-separated frame counts, e.g. 16,32,64",
128
  )
129
  parser.add_argument("--results-dir", default=None)
130
  parser.add_argument("--rebuild", action="store_true")
131
  parser.add_argument(
132
+ "--extended",
133
+ action="store_true",
134
  help="run the whole sweep under the extended protocol instead of the fixed "
135
  "16-token VSI-Bench protocol (the same flag harness.A.run/launch take)",
136
  )
137
  parser.add_argument(
138
+ "--reasoning-budget",
139
+ type=int,
140
+ default=EXTENDED_MAX_NEW_TOKENS,
141
  dest="reasoning_budget",
142
  help="extended-protocol first-pass budget (the calibrated value from "
143
  "analysis/preregistration.md, e.g. 512)",
144
  )
145
  parser.add_argument(
146
+ "--truncated-budget",
147
+ type=int,
148
+ default=None,
149
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
150
  "rescue) at this token cap (mutually exclusive with --extended)",
151
  )
 
156
  parser.error("--extended and --truncated-budget are mutually exclusive")
157
 
158
  try:
159
+ models = _parse_csv_choice(
160
+ args.models, vlm_models.available_models(), "--models"
161
+ )
162
  frame_selections = _parse_csv_choice(
163
  args.frame_selections, FRAME_SELECTIONS, "--frame-selections"
164
  )
 
175
  selected = [args.scene] if args.scene else harness_launch.scenes()
176
 
177
  sweep(
178
+ models,
179
+ frame_selections,
180
+ frame_counts,
181
+ selected,
182
+ results_dir=args.results_dir,
183
+ rebuild=args.rebuild,
184
+ extended=args.extended,
185
+ reasoning_budget=args.reasoning_budget,
186
+ truncated_budget=args.truncated_budget,
187
  )
188
 
189
 
harness/B/__init__.py CHANGED
@@ -15,7 +15,14 @@ from pathlib import Path
15
 
16
  from encoder.config import DEPTH_VARIANTS, TRACKING_MODES
17
 
18
- from harness.A import DO_SAMPLE, JSONL, MAX_NEW_TOKENS, MODEL_PATHS, TEMPERATURE, WORKSPACE_ROOT
 
 
 
 
 
 
 
19
 
20
  # Same two on-disk spatial-code schemas encoder/geometric.py can build.
21
  SPATIAL_CODE_FORMATS = ("explicit", "compact")
@@ -37,6 +44,4 @@ FRAMES_PER_VIDEO = int(os.environ.get("VSI_HARNESS_B_FRAMES_PER_VIDEO", "32"))
37
 
38
  # One JSON per question, matching harness.A's layout:
39
  # results/B/<model>/<spatial_code_format>/<depth>/<tracking>/<input_selection>/<frame_count>/<scene>/<question_id>.json
40
- RESULTS_DIR = Path(
41
- os.environ.get("VSI_HARNESS_B_RESULTS_DIR", "/root/results/B")
42
- )
 
15
 
16
  from encoder.config import DEPTH_VARIANTS, TRACKING_MODES
17
 
18
+ from harness.A import (
19
+ DO_SAMPLE,
20
+ JSONL,
21
+ MAX_NEW_TOKENS,
22
+ MODEL_PATHS,
23
+ TEMPERATURE,
24
+ WORKSPACE_ROOT,
25
+ )
26
 
27
  # Same two on-disk spatial-code schemas encoder/geometric.py can build.
28
  SPATIAL_CODE_FORMATS = ("explicit", "compact")
 
44
 
45
  # One JSON per question, matching harness.A's layout:
46
  # results/B/<model>/<spatial_code_format>/<depth>/<tracking>/<input_selection>/<frame_count>/<scene>/<question_id>.json
47
+ RESULTS_DIR = Path(os.environ.get("VSI_HARNESS_B_RESULTS_DIR", "/root/results/B"))
 
 
harness/B/__pycache__/__init__.cpython-311.pyc CHANGED
Binary files a/harness/B/__pycache__/__init__.cpython-311.pyc and b/harness/B/__pycache__/__init__.cpython-311.pyc differ
 
harness/B/__pycache__/launch.cpython-311.pyc CHANGED
Binary files a/harness/B/__pycache__/launch.cpython-311.pyc and b/harness/B/__pycache__/launch.cpython-311.pyc differ
 
harness/B/__pycache__/run.cpython-311.pyc CHANGED
Binary files a/harness/B/__pycache__/run.cpython-311.pyc and b/harness/B/__pycache__/run.cpython-311.pyc differ
 
harness/B/prompts.py CHANGED
@@ -16,7 +16,12 @@ from __future__ import annotations
16
 
17
  import json
18
 
19
- from harness.A.prompts import MCA_POST_PROMPT, MCA_QUESTION_TYPES, NA_POST_PROMPT, NA_QUESTION_TYPES
 
 
 
 
 
20
 
21
  # Deliberately vague about which fields are present -- compact and explicit carry
22
  # different fields (e.g. only explicit has a distance table and appearance order; only
@@ -66,61 +71,63 @@ REASONING_BREVITY_NOTE = (
66
  "or re-derive values you have already found."
67
  )
68
 
69
- PROSE_LEGEND = "\n\n".join([
70
- (
71
- "You are a multimodal reasoning model that interprets structured scene inputs. "
72
- "You will be provided with the spatial code of a scanned room."
73
- ),
74
- (
75
- "Below is the spatial code of a scanned room. "
76
- "It is a JSON description of the room. "
77
- "It is built automatically from a video walkthrough."
78
- ),
79
- (
80
- "Every value below that is a physical measurement is written as a STRING. "
81
- "It already names its own unit, such as \"1.46 meters\", \"3.0 seconds\", or "
82
- "\"91 degrees\"."
83
- ),
84
- (
85
- "The objects section lists object classes that were detected in the room. "
86
- "An object class is a category of object, such as \"chair\" or \"table\". "
87
- "Each object class has a count, the number of objects of that class that are in "
88
- "the room. "
89
- "Each object class has a list of instances, the individual objects of that class "
90
- "that were detected in the room. "
91
- "Each instance has a position given as \"x coordinate\", \"y coordinate\" and "
92
- "\"height above floor\". "
93
- "X coordinate is the instance's distance in meters along one fixed horizontal "
94
- "direction of the room. "
95
- "Y coordinate is the instance's distance in meters along a second fixed horizontal "
96
- "direction perpendicular to the first. "
97
- "Height above floor is the instance's vertical distance in meters above the floor. "
98
- "These directions are the same for everything in the room. "
99
- "Each instance also has a \"longest dimension\", the length in meters of that "
100
- "instance's single longest side."
101
- ),
102
- (
103
- "The room section describes the room as a whole. "
104
- "The room also has a \"floor area\", the total floor area of the room in square "
105
- "meters."
106
- ),
107
- (
108
- "The \"closest classes distance meters from\" section has, for every object class, "
109
- "the distance to each other class and the closeness rank of each other class. "
110
- "Distance is the minimum distance in meters between an instance of the class and an "
111
- "instance of the other class. "
112
- "Closeness rank orders the other classes by nearness to the class. "
113
- "Rank 1 is the nearest class. The largest rank is the farthest class. "
114
- "The larger the rank, the farther the class."
115
- ),
116
- (
117
- "The \"appearance order\" section lists every object class in the order it "
118
- "appeared in the video. "
119
- "The leftmost class in the list is the class that appeared earliest. "
120
- "The rightmost class in the list is the class that appeared last. "
121
- "The further right a class is in the list, the later it appeared."
122
- ),
123
- ])
 
 
124
 
125
 
126
  def distance_only_table(spatial_code):
@@ -132,9 +139,7 @@ def distance_only_table(spatial_code):
132
  table = code.get("closest classes distance meters from")
133
  if table:
134
  code["closest classes distance meters from"] = {
135
- class_name: {
136
- other: entry["distance"] for other, entry in neighbors.items()
137
- }
138
  for class_name, neighbors in table.items()
139
  }
140
  return code
@@ -178,8 +183,13 @@ def render_code(spatial_code, serialization="json"):
178
 
179
 
180
  def build_prompt(
181
- spatial_code, question_type, question, options=None,
182
- serialization="json", context_line=None, reasoning_note=False,
 
 
 
 
 
183
  ):
184
  """Return the full text prompt: context line, the spatial code itself, the question,
185
  and the same VSI-Bench post-prompt harness.A uses for the same question_type.
@@ -187,8 +197,16 @@ def build_prompt(
187
  defaults reproduce the standard prompt byte-for-byte."""
188
  code_text = render_code(spatial_code, serialization)
189
  pre_prompt = PRE_PROMPT if context_line is None else context_line
190
- na_post = (REASONING_BREVITY_NOTE + "\n" + NA_POST_PROMPT) if reasoning_note else NA_POST_PROMPT
191
- mca_post = (REASONING_BREVITY_NOTE + "\n" + MCA_POST_PROMPT) if reasoning_note else MCA_POST_PROMPT
 
 
 
 
 
 
 
 
192
  if serialization == "yaml" and context_line is None:
193
  # The context line must not claim JSON when the code is rendered as YAML --
194
  # otherwise the serialization arm would carry a false description as a
 
16
 
17
  import json
18
 
19
+ from harness.A.prompts import (
20
+ MCA_POST_PROMPT,
21
+ MCA_QUESTION_TYPES,
22
+ NA_POST_PROMPT,
23
+ NA_QUESTION_TYPES,
24
+ )
25
 
26
  # Deliberately vague about which fields are present -- compact and explicit carry
27
  # different fields (e.g. only explicit has a distance table and appearance order; only
 
71
  "or re-derive values you have already found."
72
  )
73
 
74
+ PROSE_LEGEND = "\n\n".join(
75
+ [
76
+ (
77
+ "You are a multimodal reasoning model that interprets structured scene inputs. "
78
+ "You will be provided with the spatial code of a scanned room."
79
+ ),
80
+ (
81
+ "Below is the spatial code of a scanned room. "
82
+ "It is a JSON description of the room. "
83
+ "It is built automatically from a video walkthrough."
84
+ ),
85
+ (
86
+ "Every value below that is a physical measurement is written as a STRING. "
87
+ 'It already names its own unit, such as "1.46 meters", "3.0 seconds", or '
88
+ '"91 degrees".'
89
+ ),
90
+ (
91
+ "The objects section lists object classes that were detected in the room. "
92
+ 'An object class is a category of object, such as "chair" or "table". '
93
+ "Each object class has a count, the number of objects of that class that are in "
94
+ "the room. "
95
+ "Each object class has a list of instances, the individual objects of that class "
96
+ "that were detected in the room. "
97
+ 'Each instance has a position given as "x coordinate", "y coordinate" and '
98
+ '"height above floor". '
99
+ "X coordinate is the instance's distance in meters along one fixed horizontal "
100
+ "direction of the room. "
101
+ "Y coordinate is the instance's distance in meters along a second fixed horizontal "
102
+ "direction perpendicular to the first. "
103
+ "Height above floor is the instance's vertical distance in meters above the floor. "
104
+ "These directions are the same for everything in the room. "
105
+ 'Each instance also has a "longest dimension", the length in meters of that '
106
+ "instance's single longest side."
107
+ ),
108
+ (
109
+ "The room section describes the room as a whole. "
110
+ 'The room also has a "floor area", the total floor area of the room in square '
111
+ "meters."
112
+ ),
113
+ (
114
+ 'The "closest classes distance meters from" section has, for every object class, '
115
+ "the distance to each other class and the closeness rank of each other class. "
116
+ "Distance is the minimum distance in meters between an instance of the class and an "
117
+ "instance of the other class. "
118
+ "Closeness rank orders the other classes by nearness to the class. "
119
+ "Rank 1 is the nearest class. The largest rank is the farthest class. "
120
+ "The larger the rank, the farther the class."
121
+ ),
122
+ (
123
+ 'The "appearance order" section lists every object class in the order it '
124
+ "appeared in the video. "
125
+ "The leftmost class in the list is the class that appeared earliest. "
126
+ "The rightmost class in the list is the class that appeared last. "
127
+ "The further right a class is in the list, the later it appeared."
128
+ ),
129
+ ]
130
+ )
131
 
132
 
133
  def distance_only_table(spatial_code):
 
139
  table = code.get("closest classes distance meters from")
140
  if table:
141
  code["closest classes distance meters from"] = {
142
+ class_name: {other: entry["distance"] for other, entry in neighbors.items()}
 
 
143
  for class_name, neighbors in table.items()
144
  }
145
  return code
 
183
 
184
 
185
  def build_prompt(
186
+ spatial_code,
187
+ question_type,
188
+ question,
189
+ options=None,
190
+ serialization="json",
191
+ context_line=None,
192
+ reasoning_note=False,
193
  ):
194
  """Return the full text prompt: context line, the spatial code itself, the question,
195
  and the same VSI-Bench post-prompt harness.A uses for the same question_type.
 
197
  defaults reproduce the standard prompt byte-for-byte."""
198
  code_text = render_code(spatial_code, serialization)
199
  pre_prompt = PRE_PROMPT if context_line is None else context_line
200
+ na_post = (
201
+ (REASONING_BREVITY_NOTE + "\n" + NA_POST_PROMPT)
202
+ if reasoning_note
203
+ else NA_POST_PROMPT
204
+ )
205
+ mca_post = (
206
+ (REASONING_BREVITY_NOTE + "\n" + MCA_POST_PROMPT)
207
+ if reasoning_note
208
+ else MCA_POST_PROMPT
209
+ )
210
  if serialization == "yaml" and context_line is None:
211
  # The context line must not claim JSON when the code is rendered as YAML --
212
  # otherwise the serialization arm would carry a false description as a
harness/B/run.py CHANGED
@@ -45,7 +45,13 @@ from harness.B.prompts import ( # noqa: E402
45
 
46
 
47
  def results_dir_for(
48
- model, protocol, spatial_code_format, depth, tracking, input_selection, frame_count,
 
 
 
 
 
 
49
  results_dir=None,
50
  ):
51
  """Return the result root isolated by model + protocol + spatial-code-format +
@@ -56,12 +62,20 @@ def results_dir_for(
56
  if results_dir is not None:
57
  return Path(results_dir)
58
  return (
59
- RESULTS_DIR / model / protocol / spatial_code_format / depth / tracking
60
- / input_selection / str(frame_count)
 
 
 
 
 
 
61
  )
62
 
63
 
64
- def _build_record(row, prompt, answer, metric_name, score, model, model_path, code_info):
 
 
65
  """Assemble one question's full, untruncated result record (nothing summarized)."""
66
  return {
67
  "model": model,
@@ -113,10 +127,20 @@ def _build_record(row, prompt, answer, metric_name, score, model, model_path, co
113
 
114
 
115
  def write_question_result(
116
- row, prompt, answer, metric_name, score, model, model_path, code_info, results_dir=None
 
 
 
 
 
 
 
 
117
  ):
118
  """Write one question's full, untruncated result record. Return (path, record)."""
119
- record = _build_record(row, prompt, answer, metric_name, score, model, model_path, code_info)
 
 
120
  root = results_dir_for(
121
  model,
122
  code_info["protocol"],
@@ -211,7 +235,12 @@ def run(
211
  scene_id = row["scene_name"]
212
  if scene_id not in code_cache:
213
  code, path = spatial_codes.load_spatial_code(
214
- scene_id, depth, input_selection, tracking, frame_count, spatial_code_format
 
 
 
 
 
215
  )
216
  if strip_schema_legend:
217
  # Legend-ablation arm: identical data, no embedded field legend.
@@ -221,27 +250,37 @@ def run(
221
  code_cache[scene_id] = {"code": code, "path": path}
222
  cached = code_cache[scene_id]
223
  prompt = code_prompts.build_prompt(
224
- cached["code"], row["question_type"], row["question"], row.get("options"),
225
- serialization=serialization, context_line=context_line,
 
 
 
 
226
  reasoning_note=reasoning_note,
227
  )
228
  answer = (
229
  adapter.answer_extended(
230
- [], prompt, reasoning_budget=reasoning_budget, force_budget=force_budget
 
 
 
231
  )
232
  if extended
233
  else adapter.answer([], prompt, max_new_tokens=raw_budget)
234
  )
235
- doc = {"question_type": row["question_type"], "ground_truth": row["ground_truth"]}
 
 
 
236
  score_doc = vsi_official_eval.vsibench_process_results(
237
  doc, [answer["answer_text"]]
238
  )["vsibench_score"]
239
  metric_name, score = _scalar_score(row["question_type"], score_doc)
240
  code_info = {
241
  "protocol": (
242
- f"{reasoning_budget}" if extended
243
- else f"truncated/{raw_budget}" if raw_budget is not None
244
- else "base"
245
  ),
246
  "spatial_code_format": spatial_code_format,
247
  "input_selection": input_selection,
@@ -252,13 +291,27 @@ def run(
252
  }
253
  if write_results:
254
  path, record = write_question_result(
255
- row, prompt, answer, metric_name, score, model, adapter.model_path,
256
- code_info, results_dir,
 
 
 
 
 
 
 
257
  )
258
  else:
259
  path = None
260
  record = _build_record(
261
- row, prompt, answer, metric_name, score, model, adapter.model_path, code_info
 
 
 
 
 
 
 
262
  )
263
  record["result_path"] = str(path) if path else None
264
  results.append(record)
@@ -273,73 +326,97 @@ def main():
273
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
274
  parser.add_argument("--scene", default=None, help="restrict to one VSI-Bench scene")
275
  parser.add_argument(
276
- "--spatial-code-format", default=DEFAULT_SPATIAL_CODE_FORMAT,
277
- choices=SPATIAL_CODE_FORMATS, dest="spatial_code_format",
 
 
278
  )
279
  parser.add_argument(
280
- "--input-selection", default=DEFAULT_INPUT_SELECTION,
281
- choices=INPUT_SELECTIONS, dest="input_selection",
 
 
282
  )
283
  parser.add_argument("--frames", type=int, default=FRAMES_PER_VIDEO)
284
  parser.add_argument("--depth", default=DEFAULT_DEPTH, choices=DEPTH_VARIANTS)
285
  parser.add_argument("--tracking", default=DEFAULT_TRACKING, choices=TRACKING_MODES)
286
- parser.add_argument("--limit", type=int, default=None, help="cap the number of questions")
 
 
287
  parser.add_argument("--device", default="cuda")
288
  parser.add_argument(
289
- "--results-dir", default=None,
 
290
  help="override the default results/B/<model>/<protocol>/<format>/"
291
  "<depth>/<tracking>/<input>/<frames> root",
292
  )
293
  parser.add_argument(
294
- "--no-write", action="store_true",
 
295
  help="skip writing per-question JSON files; print/score only",
296
  )
297
  parser.add_argument(
298
- "--serialization", default="json", choices=SERIALIZATIONS,
 
 
299
  help="robustness arm only: render the identical code dict as YAML instead of "
300
  "JSON (pair with an explicit --results-dir so the arm stays isolated)",
301
  )
302
  parser.add_argument(
303
- "--paraphrase-context", action="store_true", dest="paraphrase_context",
 
 
304
  help="robustness arm only: use the pre-registered paraphrased context line "
305
  "(pair with an explicit --results-dir)",
306
  )
307
  parser.add_argument(
308
- "--no-schema-legend", action="store_true", dest="strip_schema_legend",
 
 
309
  help="legend-ablation arm: drop the embedded 'spatial code schema' block from "
310
  "the code before prompting (identical data, no legend; pair with an explicit "
311
  "--results-dir)",
312
  )
313
  parser.add_argument(
314
- "--prose-legend", action="store_true", dest="prose_legend",
 
 
315
  help="legacy-legend arm: drop the embedded schema block AND use the legacy "
316
  "prose legend as the context block (pair with an explicit --results-dir)",
317
  )
318
  parser.add_argument(
319
- "--reasoning-note", action="store_true", dest="reasoning_note",
 
 
320
  help="prefix the Thinking-with-Spatial-Code step-by-step note to the "
321
  "post-prompt (pair with an explicit --results-dir)",
322
  )
323
  parser.add_argument(
324
- "--thinking", action="store_true",
 
325
  help="enable the model's native thinking mode (Qwen only; errors on models "
326
  "without the switch; pair with an explicit --results-dir)",
327
  )
328
  parser.add_argument(
329
- "--base-protocol", action="store_true",
 
330
  help="run harness.A's exact fixed 16-token protocol (plain answer()) instead of "
331
  "the extended 2048-token default",
332
  )
333
  parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
334
  parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
335
  parser.add_argument(
336
- "--truncated-budget", type=int, default=None,
 
 
337
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
338
  "rescue) at this token cap instead of the hardcoded 16 (mutually exclusive "
339
  "with --base-protocol)",
340
  )
341
  parser.add_argument(
342
- "--flat-distance-table", action="store_true", dest="flat_distance_table",
 
 
343
  help="flat-table arm: flatten the distance table's two-level nesting into "
344
  "single-level '<class> to <other>' keys, identical information (pair with "
345
  "an explicit --results-dir)",
@@ -372,10 +449,13 @@ def main():
372
  raw_budget=args.truncated_budget,
373
  serialization=args.serialization,
374
  context_line=(
375
- PROSE_LEGEND if args.prose_legend
376
- else PARAPHRASE_PRE_PROMPT if args.paraphrase_context
377
- else NO_LEGEND_PRE_PROMPT if args.strip_schema_legend
378
- else None
 
 
 
379
  ),
380
  strip_schema_legend=args.strip_schema_legend or args.prose_legend,
381
  reasoning_note=args.reasoning_note,
 
45
 
46
 
47
  def results_dir_for(
48
+ model,
49
+ protocol,
50
+ spatial_code_format,
51
+ depth,
52
+ tracking,
53
+ input_selection,
54
+ frame_count,
55
  results_dir=None,
56
  ):
57
  """Return the result root isolated by model + protocol + spatial-code-format +
 
62
  if results_dir is not None:
63
  return Path(results_dir)
64
  return (
65
+ RESULTS_DIR
66
+ / model
67
+ / protocol
68
+ / spatial_code_format
69
+ / depth
70
+ / tracking
71
+ / input_selection
72
+ / str(frame_count)
73
  )
74
 
75
 
76
+ def _build_record(
77
+ row, prompt, answer, metric_name, score, model, model_path, code_info
78
+ ):
79
  """Assemble one question's full, untruncated result record (nothing summarized)."""
80
  return {
81
  "model": model,
 
127
 
128
 
129
  def write_question_result(
130
+ row,
131
+ prompt,
132
+ answer,
133
+ metric_name,
134
+ score,
135
+ model,
136
+ model_path,
137
+ code_info,
138
+ results_dir=None,
139
  ):
140
  """Write one question's full, untruncated result record. Return (path, record)."""
141
+ record = _build_record(
142
+ row, prompt, answer, metric_name, score, model, model_path, code_info
143
+ )
144
  root = results_dir_for(
145
  model,
146
  code_info["protocol"],
 
235
  scene_id = row["scene_name"]
236
  if scene_id not in code_cache:
237
  code, path = spatial_codes.load_spatial_code(
238
+ scene_id,
239
+ depth,
240
+ input_selection,
241
+ tracking,
242
+ frame_count,
243
+ spatial_code_format,
244
  )
245
  if strip_schema_legend:
246
  # Legend-ablation arm: identical data, no embedded field legend.
 
250
  code_cache[scene_id] = {"code": code, "path": path}
251
  cached = code_cache[scene_id]
252
  prompt = code_prompts.build_prompt(
253
+ cached["code"],
254
+ row["question_type"],
255
+ row["question"],
256
+ row.get("options"),
257
+ serialization=serialization,
258
+ context_line=context_line,
259
  reasoning_note=reasoning_note,
260
  )
261
  answer = (
262
  adapter.answer_extended(
263
+ [],
264
+ prompt,
265
+ reasoning_budget=reasoning_budget,
266
+ force_budget=force_budget,
267
  )
268
  if extended
269
  else adapter.answer([], prompt, max_new_tokens=raw_budget)
270
  )
271
+ doc = {
272
+ "question_type": row["question_type"],
273
+ "ground_truth": row["ground_truth"],
274
+ }
275
  score_doc = vsi_official_eval.vsibench_process_results(
276
  doc, [answer["answer_text"]]
277
  )["vsibench_score"]
278
  metric_name, score = _scalar_score(row["question_type"], score_doc)
279
  code_info = {
280
  "protocol": (
281
+ f"{reasoning_budget}"
282
+ if extended
283
+ else f"truncated/{raw_budget}" if raw_budget is not None else "base"
284
  ),
285
  "spatial_code_format": spatial_code_format,
286
  "input_selection": input_selection,
 
291
  }
292
  if write_results:
293
  path, record = write_question_result(
294
+ row,
295
+ prompt,
296
+ answer,
297
+ metric_name,
298
+ score,
299
+ model,
300
+ adapter.model_path,
301
+ code_info,
302
+ results_dir,
303
  )
304
  else:
305
  path = None
306
  record = _build_record(
307
+ row,
308
+ prompt,
309
+ answer,
310
+ metric_name,
311
+ score,
312
+ model,
313
+ adapter.model_path,
314
+ code_info,
315
  )
316
  record["result_path"] = str(path) if path else None
317
  results.append(record)
 
326
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
327
  parser.add_argument("--scene", default=None, help="restrict to one VSI-Bench scene")
328
  parser.add_argument(
329
+ "--spatial-code-format",
330
+ default=DEFAULT_SPATIAL_CODE_FORMAT,
331
+ choices=SPATIAL_CODE_FORMATS,
332
+ dest="spatial_code_format",
333
  )
334
  parser.add_argument(
335
+ "--input-selection",
336
+ default=DEFAULT_INPUT_SELECTION,
337
+ choices=INPUT_SELECTIONS,
338
+ dest="input_selection",
339
  )
340
  parser.add_argument("--frames", type=int, default=FRAMES_PER_VIDEO)
341
  parser.add_argument("--depth", default=DEFAULT_DEPTH, choices=DEPTH_VARIANTS)
342
  parser.add_argument("--tracking", default=DEFAULT_TRACKING, choices=TRACKING_MODES)
343
+ parser.add_argument(
344
+ "--limit", type=int, default=None, help="cap the number of questions"
345
+ )
346
  parser.add_argument("--device", default="cuda")
347
  parser.add_argument(
348
+ "--results-dir",
349
+ default=None,
350
  help="override the default results/B/<model>/<protocol>/<format>/"
351
  "<depth>/<tracking>/<input>/<frames> root",
352
  )
353
  parser.add_argument(
354
+ "--no-write",
355
+ action="store_true",
356
  help="skip writing per-question JSON files; print/score only",
357
  )
358
  parser.add_argument(
359
+ "--serialization",
360
+ default="json",
361
+ choices=SERIALIZATIONS,
362
  help="robustness arm only: render the identical code dict as YAML instead of "
363
  "JSON (pair with an explicit --results-dir so the arm stays isolated)",
364
  )
365
  parser.add_argument(
366
+ "--paraphrase-context",
367
+ action="store_true",
368
+ dest="paraphrase_context",
369
  help="robustness arm only: use the pre-registered paraphrased context line "
370
  "(pair with an explicit --results-dir)",
371
  )
372
  parser.add_argument(
373
+ "--no-schema-legend",
374
+ action="store_true",
375
+ dest="strip_schema_legend",
376
  help="legend-ablation arm: drop the embedded 'spatial code schema' block from "
377
  "the code before prompting (identical data, no legend; pair with an explicit "
378
  "--results-dir)",
379
  )
380
  parser.add_argument(
381
+ "--prose-legend",
382
+ action="store_true",
383
+ dest="prose_legend",
384
  help="legacy-legend arm: drop the embedded schema block AND use the legacy "
385
  "prose legend as the context block (pair with an explicit --results-dir)",
386
  )
387
  parser.add_argument(
388
+ "--reasoning-note",
389
+ action="store_true",
390
+ dest="reasoning_note",
391
  help="prefix the Thinking-with-Spatial-Code step-by-step note to the "
392
  "post-prompt (pair with an explicit --results-dir)",
393
  )
394
  parser.add_argument(
395
+ "--thinking",
396
+ action="store_true",
397
  help="enable the model's native thinking mode (Qwen only; errors on models "
398
  "without the switch; pair with an explicit --results-dir)",
399
  )
400
  parser.add_argument(
401
+ "--base-protocol",
402
+ action="store_true",
403
  help="run harness.A's exact fixed 16-token protocol (plain answer()) instead of "
404
  "the extended 2048-token default",
405
  )
406
  parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
407
  parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
408
  parser.add_argument(
409
+ "--truncated-budget",
410
+ type=int,
411
+ default=None,
412
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
413
  "rescue) at this token cap instead of the hardcoded 16 (mutually exclusive "
414
  "with --base-protocol)",
415
  )
416
  parser.add_argument(
417
+ "--flat-distance-table",
418
+ action="store_true",
419
+ dest="flat_distance_table",
420
  help="flat-table arm: flatten the distance table's two-level nesting into "
421
  "single-level '<class> to <other>' keys, identical information (pair with "
422
  "an explicit --results-dir)",
 
449
  raw_budget=args.truncated_budget,
450
  serialization=args.serialization,
451
  context_line=(
452
+ PROSE_LEGEND
453
+ if args.prose_legend
454
+ else (
455
+ PARAPHRASE_PRE_PROMPT
456
+ if args.paraphrase_context
457
+ else NO_LEGEND_PRE_PROMPT if args.strip_schema_legend else None
458
+ )
459
  ),
460
  strip_schema_legend=args.strip_schema_legend or args.prose_legend,
461
  reasoning_note=args.reasoning_note,
harness/C/__init__.py CHANGED
@@ -45,6 +45,4 @@ FRAMES_PER_VIDEO = int(os.environ.get("VSI_HARNESS_C_FRAMES_PER_VIDEO", "32"))
45
 
46
  # One JSON per question, matching harness.A/B's layout:
47
  # results/C/<model>/<spatial_code_format>/<depth>/<tracking>/<input_selection>/<frame_count>/<scene>/<question_id>.json
48
- RESULTS_DIR = Path(
49
- os.environ.get("VSI_HARNESS_C_RESULTS_DIR", "/root/results/C")
50
- )
 
45
 
46
  # One JSON per question, matching harness.A/B's layout:
47
  # results/C/<model>/<spatial_code_format>/<depth>/<tracking>/<input_selection>/<frame_count>/<scene>/<question_id>.json
48
+ RESULTS_DIR = Path(os.environ.get("VSI_HARNESS_C_RESULTS_DIR", "/root/results/C"))
 
 
harness/C/__pycache__/__init__.cpython-311.pyc CHANGED
Binary files a/harness/C/__pycache__/__init__.cpython-311.pyc and b/harness/C/__pycache__/__init__.cpython-311.pyc differ
 
harness/C/__pycache__/launch.cpython-311.pyc CHANGED
Binary files a/harness/C/__pycache__/launch.cpython-311.pyc and b/harness/C/__pycache__/launch.cpython-311.pyc differ
 
harness/C/__pycache__/overlay.cpython-311.pyc CHANGED
Binary files a/harness/C/__pycache__/overlay.cpython-311.pyc and b/harness/C/__pycache__/overlay.cpython-311.pyc differ
 
harness/C/__pycache__/overlay_launch.cpython-311.pyc CHANGED
Binary files a/harness/C/__pycache__/overlay_launch.cpython-311.pyc and b/harness/C/__pycache__/overlay_launch.cpython-311.pyc differ
 
harness/C/__pycache__/prompts.cpython-311.pyc CHANGED
Binary files a/harness/C/__pycache__/prompts.cpython-311.pyc and b/harness/C/__pycache__/prompts.cpython-311.pyc differ
 
harness/C/__pycache__/run.cpython-311.pyc CHANGED
Binary files a/harness/C/__pycache__/run.cpython-311.pyc and b/harness/C/__pycache__/run.cpython-311.pyc differ
 
harness/C/__pycache__/sweep.cpython-311.pyc CHANGED
Binary files a/harness/C/__pycache__/sweep.cpython-311.pyc and b/harness/C/__pycache__/sweep.cpython-311.pyc differ
 
harness/C/launch.py CHANGED
@@ -49,12 +49,25 @@ def _load_run_module():
49
 
50
 
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
  strip_schema_legend,
55
  frame_linked,
56
  overlay,
57
- raw_budget, flat_distance_table,
 
58
  ):
59
  if gpu is not None:
60
  os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu)
@@ -109,13 +122,23 @@ def _worker(
109
 
110
 
111
  def launch(
112
- model, spatial_code_format, input_selection, frame_count, selected,
113
- depth=DEFAULT_DEPTH, tracking=DEFAULT_TRACKING, results_dir=None, rebuild=False,
114
- extended=True, reasoning_budget=EXTENDED_MAX_NEW_TOKENS, force_budget=MAX_NEW_TOKENS,
 
 
 
 
 
 
 
 
 
115
  strip_schema_legend=False,
116
  frame_linked=False,
117
  overlay=False,
118
- raw_budget=None, flat_distance_table=False,
 
119
  ):
120
  """Answer every question for ``selected`` scenes, sharded across every visible GPU.
121
 
@@ -125,9 +148,9 @@ def launch(
125
  if extended and raw_budget is not None:
126
  raise ValueError("extended and raw_budget are mutually exclusive")
127
  protocol = (
128
- f"{reasoning_budget}" if extended
129
- else f"truncated/{raw_budget}" if raw_budget is not None
130
- else "base"
131
  )
132
  condition = (
133
  f"{model}/{protocol}/{spatial_code_format}/{depth}/{tracking}"
@@ -135,7 +158,13 @@ def launch(
135
  )
136
  run = _load_run_module()
137
  root = run.results_dir_for(
138
- model, protocol, spatial_code_format, depth, tracking, input_selection, frame_count,
 
 
 
 
 
 
139
  results_dir,
140
  overlay=overlay,
141
  )
@@ -143,10 +172,17 @@ def launch(
143
  completed = 0
144
  for scene in selected:
145
  rows = run.load_questions(scene=scene)
 
 
 
 
146
  answered = all((root / scene / f"{row['id']}.json").is_file() for row in rows)
147
  if answered and not rebuild:
148
  completed += 1
149
- print(f"[{condition} {completed}/{len(selected)}] {scene}: skipped", flush=True)
 
 
 
150
  else:
151
  pending.append(scene)
152
  if not pending:
@@ -174,9 +210,24 @@ def launch(
174
  context.Process(
175
  target=_worker,
176
  args=(
177
- tasks, results, model, spatial_code_format, input_selection, frame_count,
178
- depth, tracking, results_dir, gpu, cpu_threads, extended, reasoning_budget,
179
- force_budget, strip_schema_legend, frame_linked, overlay, raw_budget,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  flat_distance_table,
181
  ),
182
  )
@@ -208,16 +259,21 @@ def main():
208
  parser = argparse.ArgumentParser()
209
  parser.add_argument("scene", nargs="?")
210
  parser.add_argument(
211
- "--scenes", help="comma-separated scenes (cannot be combined with positional scene)"
 
212
  )
213
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
214
  parser.add_argument(
215
- "--spatial-code-format", default=DEFAULT_SPATIAL_CODE_FORMAT,
216
- choices=SPATIAL_CODE_FORMATS, dest="spatial_code_format",
 
 
217
  )
218
  parser.add_argument(
219
- "--input-selection", default=DEFAULT_INPUT_SELECTION,
220
- choices=INPUT_SELECTIONS, dest="input_selection",
 
 
221
  )
222
  parser.add_argument("--frames", type=int, default=FRAMES_PER_VIDEO)
223
  parser.add_argument("--depth", default=DEFAULT_DEPTH, choices=DEPTH_VARIANTS)
@@ -225,34 +281,45 @@ def main():
225
  parser.add_argument("--results-dir", default=None)
226
  parser.add_argument("--rebuild", action="store_true")
227
  parser.add_argument(
228
- "--base-protocol", action="store_true",
 
229
  help="run harness.A's exact fixed 16-token protocol instead of the extended default",
230
  )
231
  parser.add_argument(
232
- "--overlay-ids", action="store_true", dest="overlay",
 
 
233
  help="strong correspondence arm: stamp instance ids onto the frames at each "
234
  "instance's projected position and add matching ids to the code (defaults to "
235
  "/root/results/C/overlay; pair with --no-schema-legend)",
236
  )
237
  parser.add_argument(
238
- "--frame-linked-code", action="store_true", dest="frame_linked",
 
 
239
  help="correspondence arm: add per-instance 'first visible in: frame N' pointers "
240
  "(pair with an explicit --results-dir)",
241
  )
242
  parser.add_argument(
243
- "--no-schema-legend", action="store_true", dest="strip_schema_legend",
 
 
244
  help="drop the embedded schema legend (the amended main-run design)",
245
  )
246
  parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
247
  parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
248
  parser.add_argument(
249
- "--truncated-budget", type=int, default=None,
 
 
250
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
251
  "rescue) at this token cap instead of the hardcoded 16 (mutually exclusive "
252
  "with --base-protocol)",
253
  )
254
  parser.add_argument(
255
- "--flat-distance-table", action="store_true", dest="flat_distance_table",
 
 
256
  help="flat-table arm: flatten the distance table's two-level nesting into "
257
  "single-level '<class> to <other>' keys, identical information (pair with "
258
  "an explicit --results-dir)",
@@ -278,11 +345,19 @@ def main():
278
  if args.base_protocol and args.truncated_budget is not None:
279
  parser.error("--base-protocol and --truncated-budget are mutually exclusive")
280
  launch(
281
- args.model, args.spatial_code_format, args.input_selection, args.frames, selected,
282
- depth=args.depth, tracking=args.tracking, results_dir=args.results_dir, rebuild=args.rebuild,
 
 
 
 
 
 
 
283
  extended=not args.base_protocol and args.truncated_budget is None,
284
  raw_budget=args.truncated_budget,
285
- reasoning_budget=args.reasoning_budget, force_budget=args.force_budget,
 
286
  strip_schema_legend=args.strip_schema_legend,
287
  frame_linked=args.frame_linked,
288
  overlay=args.overlay,
 
49
 
50
 
51
  def _worker(
52
+ tasks,
53
+ results,
54
+ model,
55
+ spatial_code_format,
56
+ input_selection,
57
+ frame_count,
58
+ depth,
59
+ tracking,
60
+ results_dir,
61
+ gpu,
62
+ cpu_threads,
63
+ extended,
64
+ reasoning_budget,
65
+ force_budget,
66
  strip_schema_legend,
67
  frame_linked,
68
  overlay,
69
+ raw_budget,
70
+ flat_distance_table,
71
  ):
72
  if gpu is not None:
73
  os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu)
 
122
 
123
 
124
  def launch(
125
+ model,
126
+ spatial_code_format,
127
+ input_selection,
128
+ frame_count,
129
+ selected,
130
+ depth=DEFAULT_DEPTH,
131
+ tracking=DEFAULT_TRACKING,
132
+ results_dir=None,
133
+ rebuild=False,
134
+ extended=True,
135
+ reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
136
+ force_budget=MAX_NEW_TOKENS,
137
  strip_schema_legend=False,
138
  frame_linked=False,
139
  overlay=False,
140
+ raw_budget=None,
141
+ flat_distance_table=False,
142
  ):
143
  """Answer every question for ``selected`` scenes, sharded across every visible GPU.
144
 
 
148
  if extended and raw_budget is not None:
149
  raise ValueError("extended and raw_budget are mutually exclusive")
150
  protocol = (
151
+ f"{reasoning_budget}"
152
+ if extended
153
+ else f"truncated/{raw_budget}" if raw_budget is not None else "base"
154
  )
155
  condition = (
156
  f"{model}/{protocol}/{spatial_code_format}/{depth}/{tracking}"
 
158
  )
159
  run = _load_run_module()
160
  root = run.results_dir_for(
161
+ model,
162
+ protocol,
163
+ spatial_code_format,
164
+ depth,
165
+ tracking,
166
+ input_selection,
167
+ frame_count,
168
  results_dir,
169
  overlay=overlay,
170
  )
 
172
  completed = 0
173
  for scene in selected:
174
  rows = run.load_questions(scene=scene)
175
+ if not rows:
176
+ raise ValueError(
177
+ f"no questions found for scene {scene!r}; check the manifest/scene selection"
178
+ )
179
  answered = all((root / scene / f"{row['id']}.json").is_file() for row in rows)
180
  if answered and not rebuild:
181
  completed += 1
182
+ print(
183
+ f"[{condition} {completed}/{len(selected)}] {scene}: skipped",
184
+ flush=True,
185
+ )
186
  else:
187
  pending.append(scene)
188
  if not pending:
 
210
  context.Process(
211
  target=_worker,
212
  args=(
213
+ tasks,
214
+ results,
215
+ model,
216
+ spatial_code_format,
217
+ input_selection,
218
+ frame_count,
219
+ depth,
220
+ tracking,
221
+ results_dir,
222
+ gpu,
223
+ cpu_threads,
224
+ extended,
225
+ reasoning_budget,
226
+ force_budget,
227
+ strip_schema_legend,
228
+ frame_linked,
229
+ overlay,
230
+ raw_budget,
231
  flat_distance_table,
232
  ),
233
  )
 
259
  parser = argparse.ArgumentParser()
260
  parser.add_argument("scene", nargs="?")
261
  parser.add_argument(
262
+ "--scenes",
263
+ help="comma-separated scenes (cannot be combined with positional scene)",
264
  )
265
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
266
  parser.add_argument(
267
+ "--spatial-code-format",
268
+ default=DEFAULT_SPATIAL_CODE_FORMAT,
269
+ choices=SPATIAL_CODE_FORMATS,
270
+ dest="spatial_code_format",
271
  )
272
  parser.add_argument(
273
+ "--input-selection",
274
+ default=DEFAULT_INPUT_SELECTION,
275
+ choices=INPUT_SELECTIONS,
276
+ dest="input_selection",
277
  )
278
  parser.add_argument("--frames", type=int, default=FRAMES_PER_VIDEO)
279
  parser.add_argument("--depth", default=DEFAULT_DEPTH, choices=DEPTH_VARIANTS)
 
281
  parser.add_argument("--results-dir", default=None)
282
  parser.add_argument("--rebuild", action="store_true")
283
  parser.add_argument(
284
+ "--base-protocol",
285
+ action="store_true",
286
  help="run harness.A's exact fixed 16-token protocol instead of the extended default",
287
  )
288
  parser.add_argument(
289
+ "--overlay-ids",
290
+ action="store_true",
291
+ dest="overlay",
292
  help="strong correspondence arm: stamp instance ids onto the frames at each "
293
  "instance's projected position and add matching ids to the code (defaults to "
294
  "/root/results/C/overlay; pair with --no-schema-legend)",
295
  )
296
  parser.add_argument(
297
+ "--frame-linked-code",
298
+ action="store_true",
299
+ dest="frame_linked",
300
  help="correspondence arm: add per-instance 'first visible in: frame N' pointers "
301
  "(pair with an explicit --results-dir)",
302
  )
303
  parser.add_argument(
304
+ "--no-schema-legend",
305
+ action="store_true",
306
+ dest="strip_schema_legend",
307
  help="drop the embedded schema legend (the amended main-run design)",
308
  )
309
  parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
310
  parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
311
  parser.add_argument(
312
+ "--truncated-budget",
313
+ type=int,
314
+ default=None,
315
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
316
  "rescue) at this token cap instead of the hardcoded 16 (mutually exclusive "
317
  "with --base-protocol)",
318
  )
319
  parser.add_argument(
320
+ "--flat-distance-table",
321
+ action="store_true",
322
+ dest="flat_distance_table",
323
  help="flat-table arm: flatten the distance table's two-level nesting into "
324
  "single-level '<class> to <other>' keys, identical information (pair with "
325
  "an explicit --results-dir)",
 
345
  if args.base_protocol and args.truncated_budget is not None:
346
  parser.error("--base-protocol and --truncated-budget are mutually exclusive")
347
  launch(
348
+ args.model,
349
+ args.spatial_code_format,
350
+ args.input_selection,
351
+ args.frames,
352
+ selected,
353
+ depth=args.depth,
354
+ tracking=args.tracking,
355
+ results_dir=args.results_dir,
356
+ rebuild=args.rebuild,
357
  extended=not args.base_protocol and args.truncated_budget is None,
358
  raw_budget=args.truncated_budget,
359
+ reasoning_budget=args.reasoning_budget,
360
+ force_budget=args.force_budget,
361
  strip_schema_legend=args.strip_schema_legend,
362
  frame_linked=args.frame_linked,
363
  overlay=args.overlay,
harness/C/overlay.py CHANGED
@@ -85,7 +85,11 @@ def _place_label_box(anchor_x, anchor_y, width, height, placed, frame_h, step):
85
  offset = direction * step * ((attempt + 1) // 2)
86
  top = anchor_y + offset
87
  box = (anchor_x, top, anchor_x + width, top + height)
88
- if 0 <= box[1] and box[3] <= frame_h and not any(_boxes_overlap(box, p) for p in placed):
 
 
 
 
89
  return box, attempt > 0
90
  return box, True
91
 
@@ -136,7 +140,9 @@ def _load_raw_sam3_boxes(scene_id, input_selection, tracking, frame_count):
136
  per frame, per masklet."""
137
  import torch
138
 
139
- path = encoder_config.sam3_cache_file(scene_id, input_selection, tracking, frame_count)
 
 
140
  if not Path(path).is_file():
141
  raise FileNotFoundError(
142
  f"no raw SAM3 cache found for scene {scene_id!r} at {path} -- the strong "
@@ -152,7 +158,8 @@ def _load_raw_sam3_boxes(scene_id, input_selection, tracking, frame_count):
152
  obj_ids = outputs.get("out_obj_ids", [])
153
  boxes = outputs.get("out_boxes_xywh", [])
154
  frames[int(entry["frame_index"])] = {
155
- int(oid): tuple(float(v) for v in box) for oid, box in zip(obj_ids, boxes)
 
156
  }
157
  out[str(class_name)] = frames
158
  return out
@@ -166,11 +173,57 @@ def overlay_frame_cache_dir(scene_id, depth, input_selection, tracking, frame_co
166
  room_gravity on the depth-specific geometry cache). Format is always explicit
167
  (the only format the correspondence arms support), so it isn't part of the path."""
168
  return (
169
- encoder_config.CACHE_ROOT / "overlay-frames" / depth / tracking / input_selection
170
- / str(frame_count) / scene_id
 
 
 
 
 
171
  )
172
 
173
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  def _load_cached_frames(cache_dir, frame_count):
175
  """Return (stamped_frame_copies, per_frame_visible_labels) if a complete cache
176
  exists at ``cache_dir`` (every frame PNG plus the labels sidecar present), else
@@ -195,7 +248,13 @@ def _save_cached_frames(cache_dir, stamped, visible):
195
 
196
 
197
  def stamp_frames(
198
- frame_images, explicit_code, scene_id, depth, input_selection, tracking, frame_count,
 
 
 
 
 
 
199
  use_cache=True,
200
  ):
201
  """Return (stamped_frame_copies, per_frame_visible_labels). For every code
@@ -213,7 +272,9 @@ def stamp_frames(
213
  it across every model/run that touches this scene/config is a pure speed win.
214
  Pass False to force a fresh computation (e.g. after a code or overlay-logic
215
  change, before the cache is known to be stale and worth clearing)."""
216
- cache_dir = overlay_frame_cache_dir(scene_id, depth, input_selection, tracking, frame_count)
 
 
217
  if use_cache:
218
  cached = _load_cached_frames(cache_dir, frame_count)
219
  if cached is not None:
@@ -246,19 +307,24 @@ def stamp_frames(
246
  frame_labels = []
247
  for label, class_name, oids in labels:
248
  frame_detections = raw_boxes.get(class_name, {}).get(frame_index, {})
249
- box = next((frame_detections[oid] for oid in oids if oid in frame_detections), None)
 
 
250
  if box is None:
251
  continue # SAM3's own tracker did not report this instance in this frame
252
  nx, ny, nw, nh = box # normalized [0,1] -- SAM3's own box, verbatim
253
  bx0, by0 = nx * hi_res_size[0], ny * hi_res_size[1]
254
  bw, bh = nw * hi_res_size[0], nh * hi_res_size[1]
255
  draw.rectangle(
256
- [bx0, by0, bx0 + bw, by0 + bh], outline="red", width=max(2, _SUPERSAMPLE)
 
 
257
  )
258
  px, py = bx0 + bw / 2, by0 + bh / 2
259
  draw.ellipse(
260
  [px - marker_r, py - marker_r, px + marker_r, py + marker_r],
261
- outline="red", width=max(2, _SUPERSAMPLE),
 
262
  )
263
  # Flip the label to the opposite side of the marker whenever its default
264
  # placement would run off the frame -- a label clipped at the image edge is
@@ -267,15 +333,26 @@ def stamp_frames(
267
  text_height = _FONT_SIZE * _SUPERSAMPLE * 1.3
268
  gap = 8 * _SUPERSAMPLE
269
  text_x = (
270
- px - gap - text_width if px + gap + text_width > hi_res_size[0] else px + gap
 
 
 
 
 
 
 
271
  )
272
- anchor_y = py + 4 * _SUPERSAMPLE if py - 10 * _SUPERSAMPLE < 0 else py - 10 * _SUPERSAMPLE
273
  # Nudge this label's box away from every label already placed in this
274
  # frame -- a crowded cluster fans its labels out instead of stacking them
275
  # into an unreadable smear (see _place_label_box's docstring).
276
  label_box, was_nudged = _place_label_box(
277
- text_x, anchor_y, text_width, text_height, placed_boxes,
278
- hi_res_size[1], step=text_height + 2 * _SUPERSAMPLE,
 
 
 
 
 
279
  )
280
  placed_boxes.append(label_box)
281
  if was_nudged:
@@ -289,17 +366,24 @@ def stamp_frames(
289
  anchor_y_mid = (label_box[1] + label_box[3]) / 2
290
  draw.line(
291
  [(px, py), (anchor_x, anchor_y_mid)],
292
- fill=(255, 70, 55, 210), width=max(2, _SUPERSAMPLE),
 
293
  )
294
  # A thin dark stroke (not a solid fill box) keeps the label legible
295
  # against any background without blotting out the photo underneath it.
296
  draw.text(
297
- (label_box[0], label_box[1]), label, font=_LABEL_FONT, fill="#ff4030",
298
- stroke_width=max(2, _SUPERSAMPLE), stroke_fill=(0, 0, 0, 235),
 
 
 
 
299
  )
300
  frame_labels.append(label)
301
  overlay_layer = overlay_layer.resize(image.size, Image.LANCZOS)
302
- composited = Image.alpha_composite(image.convert("RGBA"), overlay_layer).convert("RGB")
 
 
303
  stamped.append(composited)
304
  visible.append(frame_labels)
305
  if use_cache:
 
85
  offset = direction * step * ((attempt + 1) // 2)
86
  top = anchor_y + offset
87
  box = (anchor_x, top, anchor_x + width, top + height)
88
+ if (
89
+ 0 <= box[1]
90
+ and box[3] <= frame_h
91
+ and not any(_boxes_overlap(box, p) for p in placed)
92
+ ):
93
  return box, attempt > 0
94
  return box, True
95
 
 
140
  per frame, per masklet."""
141
  import torch
142
 
143
+ path = encoder_config.sam3_cache_file(
144
+ scene_id, input_selection, tracking, frame_count
145
+ )
146
  if not Path(path).is_file():
147
  raise FileNotFoundError(
148
  f"no raw SAM3 cache found for scene {scene_id!r} at {path} -- the strong "
 
158
  obj_ids = outputs.get("out_obj_ids", [])
159
  boxes = outputs.get("out_boxes_xywh", [])
160
  frames[int(entry["frame_index"])] = {
161
+ int(oid): tuple(float(v) for v in box)
162
+ for oid, box in zip(obj_ids, boxes)
163
  }
164
  out[str(class_name)] = frames
165
  return out
 
173
  room_gravity on the depth-specific geometry cache). Format is always explicit
174
  (the only format the correspondence arms support), so it isn't part of the path."""
175
  return (
176
+ encoder_config.CACHE_ROOT
177
+ / "overlay-frames"
178
+ / depth
179
+ / tracking
180
+ / input_selection
181
+ / str(frame_count)
182
+ / scene_id
183
  )
184
 
185
 
186
+ def overlay_spatial_code_path(scene_id, depth, input_selection, tracking, frame_count):
187
+ """Return the durable overlay-code JSON path for one scene/config.
188
+
189
+ Overlay codes are stored under the configured spatial-code root's top-level
190
+ ``overlay`` directory so an overlay run has a browsable code artifact matching
191
+ the stamped frames, instead of only an in-memory prompt transform.
192
+ """
193
+ encoder_config._validate_dimensions(depth, input_selection, tracking, frame_count)
194
+ return (
195
+ encoder_config.CODES_ROOT
196
+ / "overlay"
197
+ / encoder_config.MODEL
198
+ / depth
199
+ / tracking
200
+ / input_selection
201
+ / str(frame_count)
202
+ / "explicit"
203
+ / f"{scene_id}.json"
204
+ )
205
+
206
+
207
+ def load_or_create_overlay_code(
208
+ explicit_code, scene_id, depth, input_selection, tracking, frame_count
209
+ ):
210
+ """Load an existing overlay code, or create and save it from ``explicit_code``.
211
+
212
+ The saved code is exactly ``instance_ids(explicit_code)``. Existing files are
213
+ trusted as the durable artifact for that scene/config and are not rewritten.
214
+ Returns ``(code, path)``.
215
+ """
216
+ path = overlay_spatial_code_path(
217
+ scene_id, depth, input_selection, tracking, frame_count
218
+ )
219
+ if path.is_file():
220
+ return json.loads(path.read_text(encoding="utf-8")), str(path)
221
+ code = instance_ids(explicit_code)
222
+ path.parent.mkdir(parents=True, exist_ok=True)
223
+ path.write_text(json.dumps(code, indent=1) + "\n", encoding="utf-8")
224
+ return code, str(path)
225
+
226
+
227
  def _load_cached_frames(cache_dir, frame_count):
228
  """Return (stamped_frame_copies, per_frame_visible_labels) if a complete cache
229
  exists at ``cache_dir`` (every frame PNG plus the labels sidecar present), else
 
248
 
249
 
250
  def stamp_frames(
251
+ frame_images,
252
+ explicit_code,
253
+ scene_id,
254
+ depth,
255
+ input_selection,
256
+ tracking,
257
+ frame_count,
258
  use_cache=True,
259
  ):
260
  """Return (stamped_frame_copies, per_frame_visible_labels). For every code
 
272
  it across every model/run that touches this scene/config is a pure speed win.
273
  Pass False to force a fresh computation (e.g. after a code or overlay-logic
274
  change, before the cache is known to be stale and worth clearing)."""
275
+ cache_dir = overlay_frame_cache_dir(
276
+ scene_id, depth, input_selection, tracking, frame_count
277
+ )
278
  if use_cache:
279
  cached = _load_cached_frames(cache_dir, frame_count)
280
  if cached is not None:
 
307
  frame_labels = []
308
  for label, class_name, oids in labels:
309
  frame_detections = raw_boxes.get(class_name, {}).get(frame_index, {})
310
+ box = next(
311
+ (frame_detections[oid] for oid in oids if oid in frame_detections), None
312
+ )
313
  if box is None:
314
  continue # SAM3's own tracker did not report this instance in this frame
315
  nx, ny, nw, nh = box # normalized [0,1] -- SAM3's own box, verbatim
316
  bx0, by0 = nx * hi_res_size[0], ny * hi_res_size[1]
317
  bw, bh = nw * hi_res_size[0], nh * hi_res_size[1]
318
  draw.rectangle(
319
+ [bx0, by0, bx0 + bw, by0 + bh],
320
+ outline="red",
321
+ width=max(2, _SUPERSAMPLE),
322
  )
323
  px, py = bx0 + bw / 2, by0 + bh / 2
324
  draw.ellipse(
325
  [px - marker_r, py - marker_r, px + marker_r, py + marker_r],
326
+ outline="red",
327
+ width=max(2, _SUPERSAMPLE),
328
  )
329
  # Flip the label to the opposite side of the marker whenever its default
330
  # placement would run off the frame -- a label clipped at the image edge is
 
333
  text_height = _FONT_SIZE * _SUPERSAMPLE * 1.3
334
  gap = 8 * _SUPERSAMPLE
335
  text_x = (
336
+ px - gap - text_width
337
+ if px + gap + text_width > hi_res_size[0]
338
+ else px + gap
339
+ )
340
+ anchor_y = (
341
+ py + 4 * _SUPERSAMPLE
342
+ if py - 10 * _SUPERSAMPLE < 0
343
+ else py - 10 * _SUPERSAMPLE
344
  )
 
345
  # Nudge this label's box away from every label already placed in this
346
  # frame -- a crowded cluster fans its labels out instead of stacking them
347
  # into an unreadable smear (see _place_label_box's docstring).
348
  label_box, was_nudged = _place_label_box(
349
+ text_x,
350
+ anchor_y,
351
+ text_width,
352
+ text_height,
353
+ placed_boxes,
354
+ hi_res_size[1],
355
+ step=text_height + 2 * _SUPERSAMPLE,
356
  )
357
  placed_boxes.append(label_box)
358
  if was_nudged:
 
366
  anchor_y_mid = (label_box[1] + label_box[3]) / 2
367
  draw.line(
368
  [(px, py), (anchor_x, anchor_y_mid)],
369
+ fill=(255, 70, 55, 210),
370
+ width=max(2, _SUPERSAMPLE),
371
  )
372
  # A thin dark stroke (not a solid fill box) keeps the label legible
373
  # against any background without blotting out the photo underneath it.
374
  draw.text(
375
+ (label_box[0], label_box[1]),
376
+ label,
377
+ font=_LABEL_FONT,
378
+ fill="#ff4030",
379
+ stroke_width=max(2, _SUPERSAMPLE),
380
+ stroke_fill=(0, 0, 0, 235),
381
  )
382
  frame_labels.append(label)
383
  overlay_layer = overlay_layer.resize(image.size, Image.LANCZOS)
384
+ composited = Image.alpha_composite(
385
+ image.convert("RGBA"), overlay_layer
386
+ ).convert("RGB")
387
  stamped.append(composited)
388
  visible.append(frame_labels)
389
  if use_cache:
harness/C/overlay_launch.py CHANGED
@@ -84,15 +84,26 @@ def _generate_one(args):
84
  video_path, frame_count, input_selection
85
  )
86
  overlay.stamp_frames(
87
- frame_images, code, scene, depth, input_selection, tracking, frame_count,
 
 
 
 
 
 
88
  use_cache=True,
89
  )
 
 
 
90
  return scene, True, None
91
  except Exception:
92
  return scene, False, traceback.format_exc()
93
 
94
 
95
- def launch(depth, input_selection, tracking, frame_count, selected, rebuild=False, workers=0):
 
 
96
  """Pre-generate the overlay-frame cache for every scene in ``selected`` that has
97
  both required dependencies. Returns (succeeded, failed, skipped_missing_deps)
98
  scene-name lists."""
@@ -103,7 +114,9 @@ def launch(depth, input_selection, tracking, frame_count, selected, rebuild=Fals
103
  else:
104
  missing.append(scene)
105
  if missing:
106
- print(f"[overlay-launch] {len(missing)} scene(s) missing a code or SAM3 cache, skipped:")
 
 
107
  print(f" {missing}")
108
 
109
  if not rebuild:
@@ -112,7 +125,13 @@ def launch(depth, input_selection, tracking, frame_count, selected, rebuild=Fals
112
  cache_dir = overlay.overlay_frame_cache_dir(
113
  scene, depth, input_selection, tracking, frame_count
114
  )
115
- if overlay._load_cached_frames(cache_dir, frame_count) is not None:
 
 
 
 
 
 
116
  continue
117
  pending.append(scene)
118
  skipped = len(eligible) - len(pending)
@@ -122,13 +141,19 @@ def launch(depth, input_selection, tracking, frame_count, selected, rebuild=Fals
122
  pending = eligible
123
 
124
  if not pending:
125
- print(f"[overlay-launch] DONE: 0 generated, {len(eligible) - len(pending)} skipped")
 
 
126
  return [], [], missing
127
 
128
  worker_count = workers if workers > 0 else _available_cpu_count()
129
  worker_count = min(worker_count, len(pending))
130
- print(f"[overlay-launch] generating {len(pending)} scene(s) with {worker_count} worker(s)")
131
- tasks = [(scene, depth, input_selection, tracking, frame_count) for scene in pending]
 
 
 
 
132
  with mp.get_context("spawn").Pool(worker_count) as pool:
133
  results = pool.map(_generate_one, tasks)
134
 
@@ -149,17 +174,25 @@ def main():
149
  parser.add_argument("--tracking", required=True)
150
  parser.add_argument("--input", required=True, dest="input_selection")
151
  parser.add_argument("--frames", type=int, required=True)
152
- parser.add_argument("--scenes", default=None, help="comma-separated scenes (default: all)")
 
 
153
  parser.add_argument("--rebuild", action="store_true")
154
  parser.add_argument("--workers", type=int, default=0, help="0 = all available CPUs")
155
  args = parser.parse_args()
156
  selected = (
157
  [s.strip() for s in args.scenes.split(",") if s.strip()]
158
- if args.scenes else all_scenes()
 
159
  )
160
  _succeeded, failed, _missing = launch(
161
- args.depth, args.input_selection, args.tracking, args.frames, selected,
162
- rebuild=args.rebuild, workers=args.workers,
 
 
 
 
 
163
  )
164
  if failed:
165
  raise SystemExit(1)
 
84
  video_path, frame_count, input_selection
85
  )
86
  overlay.stamp_frames(
87
+ frame_images,
88
+ code,
89
+ scene,
90
+ depth,
91
+ input_selection,
92
+ tracking,
93
+ frame_count,
94
  use_cache=True,
95
  )
96
+ overlay.load_or_create_overlay_code(
97
+ code, scene, depth, input_selection, tracking, frame_count
98
+ )
99
  return scene, True, None
100
  except Exception:
101
  return scene, False, traceback.format_exc()
102
 
103
 
104
+ def launch(
105
+ depth, input_selection, tracking, frame_count, selected, rebuild=False, workers=0
106
+ ):
107
  """Pre-generate the overlay-frame cache for every scene in ``selected`` that has
108
  both required dependencies. Returns (succeeded, failed, skipped_missing_deps)
109
  scene-name lists."""
 
114
  else:
115
  missing.append(scene)
116
  if missing:
117
+ print(
118
+ f"[overlay-launch] {len(missing)} scene(s) missing a code or SAM3 cache, skipped:"
119
+ )
120
  print(f" {missing}")
121
 
122
  if not rebuild:
 
125
  cache_dir = overlay.overlay_frame_cache_dir(
126
  scene, depth, input_selection, tracking, frame_count
127
  )
128
+ code_path = overlay.overlay_spatial_code_path(
129
+ scene, depth, input_selection, tracking, frame_count
130
+ )
131
+ if (
132
+ overlay._load_cached_frames(cache_dir, frame_count) is not None
133
+ and code_path.is_file()
134
+ ):
135
  continue
136
  pending.append(scene)
137
  skipped = len(eligible) - len(pending)
 
141
  pending = eligible
142
 
143
  if not pending:
144
+ print(
145
+ f"[overlay-launch] DONE: 0 generated, {len(eligible) - len(pending)} skipped"
146
+ )
147
  return [], [], missing
148
 
149
  worker_count = workers if workers > 0 else _available_cpu_count()
150
  worker_count = min(worker_count, len(pending))
151
+ print(
152
+ f"[overlay-launch] generating {len(pending)} scene(s) with {worker_count} worker(s)"
153
+ )
154
+ tasks = [
155
+ (scene, depth, input_selection, tracking, frame_count) for scene in pending
156
+ ]
157
  with mp.get_context("spawn").Pool(worker_count) as pool:
158
  results = pool.map(_generate_one, tasks)
159
 
 
174
  parser.add_argument("--tracking", required=True)
175
  parser.add_argument("--input", required=True, dest="input_selection")
176
  parser.add_argument("--frames", type=int, required=True)
177
+ parser.add_argument(
178
+ "--scenes", default=None, help="comma-separated scenes (default: all)"
179
+ )
180
  parser.add_argument("--rebuild", action="store_true")
181
  parser.add_argument("--workers", type=int, default=0, help="0 = all available CPUs")
182
  args = parser.parse_args()
183
  selected = (
184
  [s.strip() for s in args.scenes.split(",") if s.strip()]
185
+ if args.scenes
186
+ else all_scenes()
187
  )
188
  _succeeded, failed, _missing = launch(
189
+ args.depth,
190
+ args.input_selection,
191
+ args.tracking,
192
+ args.frames,
193
+ selected,
194
+ rebuild=args.rebuild,
195
+ workers=args.workers,
196
  )
197
  if failed:
198
  raise SystemExit(1)
harness/C/prompts.py CHANGED
@@ -31,7 +31,9 @@ PRE_PROMPT = FRAMES_PRE_PROMPT + " Also provided is a spatial code: " + CODE_DES
31
  # No-legend variant: same literal composition, minus the legend claim -- keeps C's
32
  # line a strict concatenation of A's sentence and B's (no-legend) description.
33
  NO_LEGEND_PRE_PROMPT = (
34
- FRAMES_PRE_PROMPT + " Also provided is a spatial code: " + NO_LEGEND_CODE_DESCRIPTION
 
 
35
  )
36
 
37
  # Strong correspondence arm (Set-of-Marks overlays): the no-legend line plus ONE added
@@ -80,7 +82,9 @@ def frame_linked_code(explicit_code, compact_code, frame_timestamps):
80
  return code
81
 
82
 
83
- def build_prompt(spatial_code, question_type, question, options=None, context_line=None):
 
 
84
  """Return the full trailing text block: context line, the spatial code itself, the
85
  question, and the same VSI-Bench post-prompt harness.A uses for the same
86
  question_type. Frames themselves are prepended separately by the caller via
@@ -94,7 +98,9 @@ def build_prompt(spatial_code, question_type, question, options=None, context_li
94
  if not options:
95
  raise ValueError(f"question_type {question_type!r} requires options")
96
  options_block = "Options:\n" + "\n".join(options)
97
- return "\n".join([pre_prompt, code_text, question, options_block, MCA_POST_PROMPT])
 
 
98
  raise ValueError(
99
  f"unknown question_type {question_type!r}; "
100
  f"expected one of {MCA_QUESTION_TYPES + NA_QUESTION_TYPES}"
 
31
  # No-legend variant: same literal composition, minus the legend claim -- keeps C's
32
  # line a strict concatenation of A's sentence and B's (no-legend) description.
33
  NO_LEGEND_PRE_PROMPT = (
34
+ FRAMES_PRE_PROMPT
35
+ + " Also provided is a spatial code: "
36
+ + NO_LEGEND_CODE_DESCRIPTION
37
  )
38
 
39
  # Strong correspondence arm (Set-of-Marks overlays): the no-legend line plus ONE added
 
82
  return code
83
 
84
 
85
+ def build_prompt(
86
+ spatial_code, question_type, question, options=None, context_line=None
87
+ ):
88
  """Return the full trailing text block: context line, the spatial code itself, the
89
  question, and the same VSI-Bench post-prompt harness.A uses for the same
90
  question_type. Frames themselves are prepended separately by the caller via
 
98
  if not options:
99
  raise ValueError(f"question_type {question_type!r} requires options")
100
  options_block = "Options:\n" + "\n".join(options)
101
+ return "\n".join(
102
+ [pre_prompt, code_text, question, options_block, MCA_POST_PROMPT]
103
+ )
104
  raise ValueError(
105
  f"unknown question_type {question_type!r}; "
106
  f"expected one of {MCA_QUESTION_TYPES + NA_QUESTION_TYPES}"
harness/C/run.py CHANGED
@@ -42,8 +42,15 @@ from harness.C.prompts import NO_LEGEND_PRE_PROMPT # noqa: E402
42
 
43
 
44
  def results_dir_for(
45
- model, protocol, spatial_code_format, depth, tracking, input_selection, frame_count,
46
- results_dir=None, overlay=False,
 
 
 
 
 
 
 
47
  ):
48
  """Return the result root isolated by model + protocol + spatial-code-format +
49
  depth + tracking + input + frames. ``protocol`` is "base" (16-token) or
@@ -53,12 +60,20 @@ def results_dir_for(
53
  return Path(results_dir)
54
  root = RESULTS_DIR / "overlay" if overlay else RESULTS_DIR
55
  return (
56
- root / model / protocol / spatial_code_format / depth / tracking
57
- / input_selection / str(frame_count)
 
 
 
 
 
 
58
  )
59
 
60
 
61
- def _build_record(row, prompt, answer, metric_name, score, model, model_path, source_info):
 
 
62
  """Assemble one question's full, untruncated result record (nothing summarized)."""
63
  return {
64
  "model": model,
@@ -113,10 +128,20 @@ def _build_record(row, prompt, answer, metric_name, score, model, model_path, so
113
 
114
 
115
  def write_question_result(
116
- row, prompt, answer, metric_name, score, model, model_path, source_info, results_dir=None
 
 
 
 
 
 
 
 
117
  ):
118
  """Write one question's full, untruncated result record. Return (path, record)."""
119
- record = _build_record(row, prompt, answer, metric_name, score, model, model_path, source_info)
 
 
120
  root = results_dir_for(
121
  model,
122
  source_info["protocol"],
@@ -126,6 +151,7 @@ def write_question_result(
126
  source_info["input_selection"],
127
  source_info["frame_count"],
128
  results_dir,
 
129
  )
130
  scene_dir = root / record["scene"]
131
  scene_dir.mkdir(parents=True, exist_ok=True)
@@ -202,13 +228,20 @@ def run(
202
  "no-legend context line, which is only truthful without the embedded schema"
203
  )
204
  protocol = (
205
- f"{reasoning_budget}" if extended
206
- else f"truncated/{raw_budget}" if raw_budget is not None
207
- else "base"
208
  )
209
  results_dir = results_dir_for(
210
- model, protocol, spatial_code_format, depth, tracking, input_selection,
211
- frame_count, results_dir, overlay=overlay,
 
 
 
 
 
 
 
212
  )
213
  rows = load_questions(jsonl_path, scene, scenes, limit)
214
  if not rows:
@@ -224,15 +257,27 @@ def run(
224
  scene_id = row["scene_name"]
225
  if scene_id not in source_cache:
226
  video_path = inference_config.video_path(scene_id, row.get("dataset"))
227
- frame_images, frame_timestamps, frame_indices = frame_sampling.sample_frames(
228
- video_path, frame_count, input_selection
 
 
229
  )
230
  code, code_path = spatial_codes.load_spatial_code(
231
- scene_id, depth, input_selection, tracking, frame_count, spatial_code_format
 
 
 
 
 
232
  )
233
  if frame_linked:
234
  compact_code, _ = spatial_codes.load_spatial_code(
235
- scene_id, depth, input_selection, tracking, frame_count, "compact"
 
 
 
 
 
236
  )
237
  code = combined_prompts.frame_linked_code(
238
  code, compact_code, frame_timestamps
@@ -241,10 +286,17 @@ def run(
241
  from harness.C import overlay as overlay_module
242
 
243
  frame_images, _visible = overlay_module.stamp_frames(
244
- frame_images, code, scene_id, depth, input_selection, tracking,
 
 
 
 
 
245
  frame_count,
246
  )
247
- code = overlay_module.instance_ids(code)
 
 
248
  if strip_schema_legend:
249
  code = {k: v for k, v in code.items() if k != "spatial code schema"}
250
  if flat_distance_table:
@@ -265,18 +317,28 @@ def run(
265
  else:
266
  context_line = None
267
  prompt = combined_prompts.build_prompt(
268
- cached["code"], row["question_type"], row["question"], row.get("options"),
 
 
 
269
  context_line=context_line,
270
  )
271
  answer = (
272
  adapter.answer_extended(
273
- cached["frame_images"], prompt,
274
- reasoning_budget=reasoning_budget, force_budget=force_budget,
 
 
275
  )
276
  if extended
277
- else adapter.answer(cached["frame_images"], prompt, max_new_tokens=raw_budget)
 
 
278
  )
279
- doc = {"question_type": row["question_type"], "ground_truth": row["ground_truth"]}
 
 
 
280
  score_doc = vsi_official_eval.vsibench_process_results(
281
  doc, [answer["answer_text"]]
282
  )["vsibench_score"]
@@ -292,16 +354,31 @@ def run(
292
  "video_path": cached["video_path"],
293
  "frame_indices": cached["frame_indices"],
294
  "frame_timestamps": cached["frame_timestamps"],
 
295
  }
296
  if write_results:
297
  path, record = write_question_result(
298
- row, prompt, answer, metric_name, score, model, adapter.model_path,
299
- source_info, results_dir,
 
 
 
 
 
 
 
300
  )
301
  else:
302
  path = None
303
  record = _build_record(
304
- row, prompt, answer, metric_name, score, model, adapter.model_path, source_info
 
 
 
 
 
 
 
305
  )
306
  record["result_path"] = str(path) if path else None
307
  results.append(record)
@@ -316,57 +393,76 @@ def main():
316
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
317
  parser.add_argument("--scene", default=None, help="restrict to one VSI-Bench scene")
318
  parser.add_argument(
319
- "--spatial-code-format", default=DEFAULT_SPATIAL_CODE_FORMAT,
320
- choices=SPATIAL_CODE_FORMATS, dest="spatial_code_format",
 
 
321
  )
322
  parser.add_argument(
323
- "--input-selection", default=DEFAULT_INPUT_SELECTION,
324
- choices=INPUT_SELECTIONS, dest="input_selection",
 
 
325
  )
326
  parser.add_argument("--frames", type=int, default=FRAMES_PER_VIDEO)
327
  parser.add_argument("--depth", default=DEFAULT_DEPTH, choices=DEPTH_VARIANTS)
328
  parser.add_argument("--tracking", default=DEFAULT_TRACKING, choices=TRACKING_MODES)
329
- parser.add_argument("--limit", type=int, default=None, help="cap the number of questions")
 
 
330
  parser.add_argument("--device", default="cuda")
331
  parser.add_argument(
332
- "--results-dir", default=None,
 
333
  help="override the default results/C/<model>/<protocol>/<format>/"
334
  "<depth>/<tracking>/<input>/<frames> root",
335
  )
336
  parser.add_argument(
337
- "--no-write", action="store_true",
 
338
  help="skip writing per-question JSON files; print/score only",
339
  )
340
  parser.add_argument(
341
- "--base-protocol", action="store_true",
 
342
  help="run harness.A's exact fixed 16-token protocol (plain answer()) instead of "
343
  "the extended 2048-token default",
344
  )
345
  parser.add_argument(
346
- "--overlay-ids", action="store_true", dest="overlay",
 
 
347
  help="strong correspondence arm: stamp instance ids onto the frames at each "
348
  "instance's projected position and add matching ids to the code (defaults to "
349
  "/root/results/C/overlay; pair with --no-schema-legend)",
350
  )
351
  parser.add_argument(
352
- "--frame-linked-code", action="store_true", dest="frame_linked",
 
 
353
  help="correspondence arm: add per-instance 'first visible in: frame N' pointers "
354
  "(pair with an explicit --results-dir)",
355
  )
356
  parser.add_argument(
357
- "--no-schema-legend", action="store_true", dest="strip_schema_legend",
 
 
358
  help="drop the embedded schema legend (the amended main-run design)",
359
  )
360
  parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
361
  parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
362
  parser.add_argument(
363
- "--truncated-budget", type=int, default=None,
 
 
364
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
365
  "rescue) at this token cap instead of the hardcoded 16 (mutually exclusive "
366
  "with --base-protocol)",
367
  )
368
  parser.add_argument(
369
- "--flat-distance-table", action="store_true", dest="flat_distance_table",
 
 
370
  help="flat-table arm: flatten the distance table's two-level nesting into "
371
  "single-level '<class> to <other>' keys, identical information (pair with "
372
  "an explicit --results-dir)",
 
42
 
43
 
44
  def results_dir_for(
45
+ model,
46
+ protocol,
47
+ spatial_code_format,
48
+ depth,
49
+ tracking,
50
+ input_selection,
51
+ frame_count,
52
+ results_dir=None,
53
+ overlay=False,
54
  ):
55
  """Return the result root isolated by model + protocol + spatial-code-format +
56
  depth + tracking + input + frames. ``protocol`` is "base" (16-token) or
 
60
  return Path(results_dir)
61
  root = RESULTS_DIR / "overlay" if overlay else RESULTS_DIR
62
  return (
63
+ root
64
+ / model
65
+ / protocol
66
+ / spatial_code_format
67
+ / depth
68
+ / tracking
69
+ / input_selection
70
+ / str(frame_count)
71
  )
72
 
73
 
74
+ def _build_record(
75
+ row, prompt, answer, metric_name, score, model, model_path, source_info
76
+ ):
77
  """Assemble one question's full, untruncated result record (nothing summarized)."""
78
  return {
79
  "model": model,
 
128
 
129
 
130
  def write_question_result(
131
+ row,
132
+ prompt,
133
+ answer,
134
+ metric_name,
135
+ score,
136
+ model,
137
+ model_path,
138
+ source_info,
139
+ results_dir=None,
140
  ):
141
  """Write one question's full, untruncated result record. Return (path, record)."""
142
+ record = _build_record(
143
+ row, prompt, answer, metric_name, score, model, model_path, source_info
144
+ )
145
  root = results_dir_for(
146
  model,
147
  source_info["protocol"],
 
151
  source_info["input_selection"],
152
  source_info["frame_count"],
153
  results_dir,
154
+ overlay=source_info.get("overlay", False),
155
  )
156
  scene_dir = root / record["scene"]
157
  scene_dir.mkdir(parents=True, exist_ok=True)
 
228
  "no-legend context line, which is only truthful without the embedded schema"
229
  )
230
  protocol = (
231
+ f"{reasoning_budget}"
232
+ if extended
233
+ else f"truncated/{raw_budget}" if raw_budget is not None else "base"
234
  )
235
  results_dir = results_dir_for(
236
+ model,
237
+ protocol,
238
+ spatial_code_format,
239
+ depth,
240
+ tracking,
241
+ input_selection,
242
+ frame_count,
243
+ results_dir,
244
+ overlay=overlay,
245
  )
246
  rows = load_questions(jsonl_path, scene, scenes, limit)
247
  if not rows:
 
257
  scene_id = row["scene_name"]
258
  if scene_id not in source_cache:
259
  video_path = inference_config.video_path(scene_id, row.get("dataset"))
260
+ frame_images, frame_timestamps, frame_indices = (
261
+ frame_sampling.sample_frames(
262
+ video_path, frame_count, input_selection
263
+ )
264
  )
265
  code, code_path = spatial_codes.load_spatial_code(
266
+ scene_id,
267
+ depth,
268
+ input_selection,
269
+ tracking,
270
+ frame_count,
271
+ spatial_code_format,
272
  )
273
  if frame_linked:
274
  compact_code, _ = spatial_codes.load_spatial_code(
275
+ scene_id,
276
+ depth,
277
+ input_selection,
278
+ tracking,
279
+ frame_count,
280
+ "compact",
281
  )
282
  code = combined_prompts.frame_linked_code(
283
  code, compact_code, frame_timestamps
 
286
  from harness.C import overlay as overlay_module
287
 
288
  frame_images, _visible = overlay_module.stamp_frames(
289
+ frame_images,
290
+ code,
291
+ scene_id,
292
+ depth,
293
+ input_selection,
294
+ tracking,
295
  frame_count,
296
  )
297
+ code, code_path = overlay_module.load_or_create_overlay_code(
298
+ code, scene_id, depth, input_selection, tracking, frame_count
299
+ )
300
  if strip_schema_legend:
301
  code = {k: v for k, v in code.items() if k != "spatial code schema"}
302
  if flat_distance_table:
 
317
  else:
318
  context_line = None
319
  prompt = combined_prompts.build_prompt(
320
+ cached["code"],
321
+ row["question_type"],
322
+ row["question"],
323
+ row.get("options"),
324
  context_line=context_line,
325
  )
326
  answer = (
327
  adapter.answer_extended(
328
+ cached["frame_images"],
329
+ prompt,
330
+ reasoning_budget=reasoning_budget,
331
+ force_budget=force_budget,
332
  )
333
  if extended
334
+ else adapter.answer(
335
+ cached["frame_images"], prompt, max_new_tokens=raw_budget
336
+ )
337
  )
338
+ doc = {
339
+ "question_type": row["question_type"],
340
+ "ground_truth": row["ground_truth"],
341
+ }
342
  score_doc = vsi_official_eval.vsibench_process_results(
343
  doc, [answer["answer_text"]]
344
  )["vsibench_score"]
 
354
  "video_path": cached["video_path"],
355
  "frame_indices": cached["frame_indices"],
356
  "frame_timestamps": cached["frame_timestamps"],
357
+ "overlay": overlay,
358
  }
359
  if write_results:
360
  path, record = write_question_result(
361
+ row,
362
+ prompt,
363
+ answer,
364
+ metric_name,
365
+ score,
366
+ model,
367
+ adapter.model_path,
368
+ source_info,
369
+ results_dir,
370
  )
371
  else:
372
  path = None
373
  record = _build_record(
374
+ row,
375
+ prompt,
376
+ answer,
377
+ metric_name,
378
+ score,
379
+ model,
380
+ adapter.model_path,
381
+ source_info,
382
  )
383
  record["result_path"] = str(path) if path else None
384
  results.append(record)
 
393
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
394
  parser.add_argument("--scene", default=None, help="restrict to one VSI-Bench scene")
395
  parser.add_argument(
396
+ "--spatial-code-format",
397
+ default=DEFAULT_SPATIAL_CODE_FORMAT,
398
+ choices=SPATIAL_CODE_FORMATS,
399
+ dest="spatial_code_format",
400
  )
401
  parser.add_argument(
402
+ "--input-selection",
403
+ default=DEFAULT_INPUT_SELECTION,
404
+ choices=INPUT_SELECTIONS,
405
+ dest="input_selection",
406
  )
407
  parser.add_argument("--frames", type=int, default=FRAMES_PER_VIDEO)
408
  parser.add_argument("--depth", default=DEFAULT_DEPTH, choices=DEPTH_VARIANTS)
409
  parser.add_argument("--tracking", default=DEFAULT_TRACKING, choices=TRACKING_MODES)
410
+ parser.add_argument(
411
+ "--limit", type=int, default=None, help="cap the number of questions"
412
+ )
413
  parser.add_argument("--device", default="cuda")
414
  parser.add_argument(
415
+ "--results-dir",
416
+ default=None,
417
  help="override the default results/C/<model>/<protocol>/<format>/"
418
  "<depth>/<tracking>/<input>/<frames> root",
419
  )
420
  parser.add_argument(
421
+ "--no-write",
422
+ action="store_true",
423
  help="skip writing per-question JSON files; print/score only",
424
  )
425
  parser.add_argument(
426
+ "--base-protocol",
427
+ action="store_true",
428
  help="run harness.A's exact fixed 16-token protocol (plain answer()) instead of "
429
  "the extended 2048-token default",
430
  )
431
  parser.add_argument(
432
+ "--overlay-ids",
433
+ action="store_true",
434
+ dest="overlay",
435
  help="strong correspondence arm: stamp instance ids onto the frames at each "
436
  "instance's projected position and add matching ids to the code (defaults to "
437
  "/root/results/C/overlay; pair with --no-schema-legend)",
438
  )
439
  parser.add_argument(
440
+ "--frame-linked-code",
441
+ action="store_true",
442
+ dest="frame_linked",
443
  help="correspondence arm: add per-instance 'first visible in: frame N' pointers "
444
  "(pair with an explicit --results-dir)",
445
  )
446
  parser.add_argument(
447
+ "--no-schema-legend",
448
+ action="store_true",
449
+ dest="strip_schema_legend",
450
  help="drop the embedded schema legend (the amended main-run design)",
451
  )
452
  parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
453
  parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
454
  parser.add_argument(
455
+ "--truncated-budget",
456
+ type=int,
457
+ default=None,
458
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
459
  "rescue) at this token cap instead of the hardcoded 16 (mutually exclusive "
460
  "with --base-protocol)",
461
  )
462
  parser.add_argument(
463
+ "--flat-distance-table",
464
+ action="store_true",
465
+ dest="flat_distance_table",
466
  help="flat-table arm: flatten the distance table's two-level nesting into "
467
  "single-level '<class> to <other>' keys, identical information (pair with "
468
  "an explicit --results-dir)",
harness/C/sweep.py CHANGED
@@ -35,7 +35,9 @@ from harness.B import ( # noqa: E402
35
  from harness.C import launch as harness_launch # noqa: E402
36
 
37
 
38
- def build_plan(models, spatial_code_formats, input_selections, frame_counts, depths, trackings):
 
 
39
  """Return every (model, spatial_code_format, depth, tracking, input_selection,
40
  frame_count) 6-tuple in the sweep, in a stable, cheapest-first-ish order (frame
41
  count sorted first)."""
@@ -51,30 +53,57 @@ def build_plan(models, spatial_code_formats, input_selections, frame_counts, dep
51
 
52
 
53
  def sweep(
54
- models, spatial_code_formats, input_selections, frame_counts, selected_scenes,
55
- depths=(DEFAULT_DEPTH,), trackings=(DEFAULT_TRACKING,), results_dir=None, rebuild=False,
56
- extended=True, reasoning_budget=EXTENDED_MAX_NEW_TOKENS, strip_schema_legend=False,
57
- frame_linked=False, overlay=False, raw_budget=None, flat_distance_table=False,
 
 
 
 
 
 
 
 
 
 
 
 
58
  ):
59
  """Run every sweep combination across all visible GPUs."""
60
- plan = build_plan(models, spatial_code_formats, input_selections, frame_counts, depths, trackings)
 
 
61
  protocol = (
62
- f"{reasoning_budget}" if extended
63
- else f"truncated/{raw_budget}" if raw_budget is not None
64
- else "base"
65
  )
66
- for index, (model, spatial_code_format, depth, tracking, input_selection, frame_count) in enumerate(
67
- plan, start=1
68
- ):
 
 
 
 
 
69
  print(
70
  f"=== sweep {index}/{len(plan)}: {model}/{protocol}/"
71
  f"{spatial_code_format}/{depth}/{tracking}/{input_selection}/{frame_count} ===",
72
  flush=True,
73
  )
74
  harness_launch.launch(
75
- model, spatial_code_format, input_selection, frame_count, selected_scenes,
76
- depth=depth, tracking=tracking, results_dir=results_dir, rebuild=rebuild,
77
- extended=extended, reasoning_budget=reasoning_budget,
 
 
 
 
 
 
 
 
78
  strip_schema_legend=strip_schema_legend,
79
  frame_linked=frame_linked,
80
  overlay=overlay,
@@ -87,66 +116,87 @@ def main():
87
  parser = argparse.ArgumentParser()
88
  parser.add_argument("scene", nargs="?")
89
  parser.add_argument(
90
- "--scenes", help="comma-separated scenes (cannot be combined with positional scene)"
 
91
  )
92
  parser.add_argument(
93
- "--models", required=True,
 
94
  help=f"comma-separated models (or 'all'); one of {vlm_models.available_models()}",
95
  )
96
  parser.add_argument(
97
- "--spatial-code-formats", required=True, dest="spatial_code_formats",
 
 
98
  help=f"comma-separated formats (or 'all'); one of {SPATIAL_CODE_FORMATS}",
99
  )
100
  parser.add_argument(
101
- "--input-selections", required=True, dest="input_selections",
 
 
102
  help=f"comma-separated selections (or 'all'); one of {INPUT_SELECTIONS}",
103
  )
104
  parser.add_argument(
105
  "--frames", required=True, help="comma-separated frame counts, e.g. 16,32,64"
106
  )
107
  parser.add_argument(
108
- "--depths", default=DEFAULT_DEPTH,
 
109
  help=f"comma-separated depths (or 'all'); one of {DEPTH_VARIANTS}",
110
  )
111
  parser.add_argument(
112
- "--trackings", default=DEFAULT_TRACKING,
 
113
  help=f"comma-separated tracking modes (or 'all'); one of {TRACKING_MODES}",
114
  )
115
  parser.add_argument("--results-dir", default=None)
116
  parser.add_argument("--rebuild", action="store_true")
117
  parser.add_argument(
118
- "--base-protocol", action="store_true",
 
119
  help="run the whole sweep under harness.A's exact fixed 16-token protocol "
120
  "instead of the extended default",
121
  )
122
  parser.add_argument(
123
- "--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS,
 
 
124
  dest="reasoning_budget",
125
  help="extended-protocol first-pass budget (the calibrated value from "
126
  "preregistration.md, e.g. 512)",
127
  )
128
  parser.add_argument(
129
- "--overlay-ids", action="store_true", dest="overlay",
 
 
130
  help="strong correspondence arm: stamp instance ids onto the frames at each "
131
  "instance's projected position and add matching ids to the code (defaults to "
132
  "/root/results/C/overlay; pair with --no-schema-legend)",
133
  )
134
  parser.add_argument(
135
- "--frame-linked-code", action="store_true", dest="frame_linked",
 
 
136
  help="correspondence arm: add per-instance 'first visible in: frame N' pointers "
137
  "(pair with an explicit --results-dir)",
138
  )
139
  parser.add_argument(
140
- "--no-schema-legend", action="store_true", dest="strip_schema_legend",
 
 
141
  help="drop the embedded schema legend (the amended main-run design)",
142
  )
143
  parser.add_argument(
144
- "--truncated-budget", type=int, default=None,
 
 
145
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
146
  "rescue) at this token cap (mutually exclusive with --base-protocol)",
147
  )
148
  parser.add_argument(
149
- "--flat-distance-table", action="store_true", dest="flat_distance_table",
 
 
150
  help="flat-table arm: flatten the distance table's two-level nesting into "
151
  "single-level '<class> to <other>' keys, identical information",
152
  )
@@ -157,7 +207,9 @@ def main():
157
  parser.error("--base-protocol and --truncated-budget are mutually exclusive")
158
 
159
  try:
160
- models = _parse_csv_choice(args.models, vlm_models.available_models(), "--models")
 
 
161
  spatial_code_formats = _parse_csv_choice(
162
  args.spatial_code_formats, SPATIAL_CODE_FORMATS, "--spatial-code-formats"
163
  )
@@ -181,9 +233,15 @@ def main():
181
  selected = [args.scene] if args.scene else scenes()
182
 
183
  sweep(
184
- models, spatial_code_formats, input_selections, frame_counts, selected,
185
- depths=depths, trackings=trackings,
186
- results_dir=args.results_dir, rebuild=args.rebuild,
 
 
 
 
 
 
187
  extended=not args.base_protocol and args.truncated_budget is None,
188
  reasoning_budget=args.reasoning_budget,
189
  strip_schema_legend=args.strip_schema_legend,
 
35
  from harness.C import launch as harness_launch # noqa: E402
36
 
37
 
38
+ def build_plan(
39
+ models, spatial_code_formats, input_selections, frame_counts, depths, trackings
40
+ ):
41
  """Return every (model, spatial_code_format, depth, tracking, input_selection,
42
  frame_count) 6-tuple in the sweep, in a stable, cheapest-first-ish order (frame
43
  count sorted first)."""
 
53
 
54
 
55
  def sweep(
56
+ models,
57
+ spatial_code_formats,
58
+ input_selections,
59
+ frame_counts,
60
+ selected_scenes,
61
+ depths=(DEFAULT_DEPTH,),
62
+ trackings=(DEFAULT_TRACKING,),
63
+ results_dir=None,
64
+ rebuild=False,
65
+ extended=True,
66
+ reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
67
+ strip_schema_legend=False,
68
+ frame_linked=False,
69
+ overlay=False,
70
+ raw_budget=None,
71
+ flat_distance_table=False,
72
  ):
73
  """Run every sweep combination across all visible GPUs."""
74
+ plan = build_plan(
75
+ models, spatial_code_formats, input_selections, frame_counts, depths, trackings
76
+ )
77
  protocol = (
78
+ f"{reasoning_budget}"
79
+ if extended
80
+ else f"truncated/{raw_budget}" if raw_budget is not None else "base"
81
  )
82
+ for index, (
83
+ model,
84
+ spatial_code_format,
85
+ depth,
86
+ tracking,
87
+ input_selection,
88
+ frame_count,
89
+ ) in enumerate(plan, start=1):
90
  print(
91
  f"=== sweep {index}/{len(plan)}: {model}/{protocol}/"
92
  f"{spatial_code_format}/{depth}/{tracking}/{input_selection}/{frame_count} ===",
93
  flush=True,
94
  )
95
  harness_launch.launch(
96
+ model,
97
+ spatial_code_format,
98
+ input_selection,
99
+ frame_count,
100
+ selected_scenes,
101
+ depth=depth,
102
+ tracking=tracking,
103
+ results_dir=results_dir,
104
+ rebuild=rebuild,
105
+ extended=extended,
106
+ reasoning_budget=reasoning_budget,
107
  strip_schema_legend=strip_schema_legend,
108
  frame_linked=frame_linked,
109
  overlay=overlay,
 
116
  parser = argparse.ArgumentParser()
117
  parser.add_argument("scene", nargs="?")
118
  parser.add_argument(
119
+ "--scenes",
120
+ help="comma-separated scenes (cannot be combined with positional scene)",
121
  )
122
  parser.add_argument(
123
+ "--models",
124
+ required=True,
125
  help=f"comma-separated models (or 'all'); one of {vlm_models.available_models()}",
126
  )
127
  parser.add_argument(
128
+ "--spatial-code-formats",
129
+ required=True,
130
+ dest="spatial_code_formats",
131
  help=f"comma-separated formats (or 'all'); one of {SPATIAL_CODE_FORMATS}",
132
  )
133
  parser.add_argument(
134
+ "--input-selections",
135
+ required=True,
136
+ dest="input_selections",
137
  help=f"comma-separated selections (or 'all'); one of {INPUT_SELECTIONS}",
138
  )
139
  parser.add_argument(
140
  "--frames", required=True, help="comma-separated frame counts, e.g. 16,32,64"
141
  )
142
  parser.add_argument(
143
+ "--depths",
144
+ default=DEFAULT_DEPTH,
145
  help=f"comma-separated depths (or 'all'); one of {DEPTH_VARIANTS}",
146
  )
147
  parser.add_argument(
148
+ "--trackings",
149
+ default=DEFAULT_TRACKING,
150
  help=f"comma-separated tracking modes (or 'all'); one of {TRACKING_MODES}",
151
  )
152
  parser.add_argument("--results-dir", default=None)
153
  parser.add_argument("--rebuild", action="store_true")
154
  parser.add_argument(
155
+ "--base-protocol",
156
+ action="store_true",
157
  help="run the whole sweep under harness.A's exact fixed 16-token protocol "
158
  "instead of the extended default",
159
  )
160
  parser.add_argument(
161
+ "--reasoning-budget",
162
+ type=int,
163
+ default=EXTENDED_MAX_NEW_TOKENS,
164
  dest="reasoning_budget",
165
  help="extended-protocol first-pass budget (the calibrated value from "
166
  "preregistration.md, e.g. 512)",
167
  )
168
  parser.add_argument(
169
+ "--overlay-ids",
170
+ action="store_true",
171
+ dest="overlay",
172
  help="strong correspondence arm: stamp instance ids onto the frames at each "
173
  "instance's projected position and add matching ids to the code (defaults to "
174
  "/root/results/C/overlay; pair with --no-schema-legend)",
175
  )
176
  parser.add_argument(
177
+ "--frame-linked-code",
178
+ action="store_true",
179
+ dest="frame_linked",
180
  help="correspondence arm: add per-instance 'first visible in: frame N' pointers "
181
  "(pair with an explicit --results-dir)",
182
  )
183
  parser.add_argument(
184
+ "--no-schema-legend",
185
+ action="store_true",
186
+ dest="strip_schema_legend",
187
  help="drop the embedded schema legend (the amended main-run design)",
188
  )
189
  parser.add_argument(
190
+ "--truncated-budget",
191
+ type=int,
192
+ default=None,
193
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
194
  "rescue) at this token cap (mutually exclusive with --base-protocol)",
195
  )
196
  parser.add_argument(
197
+ "--flat-distance-table",
198
+ action="store_true",
199
+ dest="flat_distance_table",
200
  help="flat-table arm: flatten the distance table's two-level nesting into "
201
  "single-level '<class> to <other>' keys, identical information",
202
  )
 
207
  parser.error("--base-protocol and --truncated-budget are mutually exclusive")
208
 
209
  try:
210
+ models = _parse_csv_choice(
211
+ args.models, vlm_models.available_models(), "--models"
212
+ )
213
  spatial_code_formats = _parse_csv_choice(
214
  args.spatial_code_formats, SPATIAL_CODE_FORMATS, "--spatial-code-formats"
215
  )
 
233
  selected = [args.scene] if args.scene else scenes()
234
 
235
  sweep(
236
+ models,
237
+ spatial_code_formats,
238
+ input_selections,
239
+ frame_counts,
240
+ selected,
241
+ depths=depths,
242
+ trackings=trackings,
243
+ results_dir=args.results_dir,
244
+ rebuild=args.rebuild,
245
  extended=not args.base_protocol and args.truncated_budget is None,
246
  reasoning_budget=args.reasoning_budget,
247
  strip_schema_legend=args.strip_schema_legend,
harness/D/__init__.py CHANGED
@@ -25,13 +25,18 @@ from __future__ import annotations
25
  import os
26
  from pathlib import Path
27
 
28
- from harness.A import DO_SAMPLE, JSONL, MAX_NEW_TOKENS, MODEL_PATHS, TEMPERATURE, WORKSPACE_ROOT
 
 
 
 
 
 
 
29
  from harness.B import SPATIAL_CODE_FORMATS
30
 
31
  DEFAULT_SPATIAL_CODE_FORMAT = "explicit"
32
 
33
  # One JSON per question, matching harness.B's layout minus the axes ground truth doesn't
34
  # have: results/D/<model>/code/<protocol>/<spatial_code_format>/<scene>/<question_id>.json
35
- RESULTS_DIR = Path(
36
- os.environ.get("VSI_HARNESS_D_RESULTS_DIR", "/root/results/D")
37
- )
 
25
  import os
26
  from pathlib import Path
27
 
28
+ from harness.A import (
29
+ DO_SAMPLE,
30
+ JSONL,
31
+ MAX_NEW_TOKENS,
32
+ MODEL_PATHS,
33
+ TEMPERATURE,
34
+ WORKSPACE_ROOT,
35
+ )
36
  from harness.B import SPATIAL_CODE_FORMATS
37
 
38
  DEFAULT_SPATIAL_CODE_FORMAT = "explicit"
39
 
40
  # One JSON per question, matching harness.B's layout minus the axes ground truth doesn't
41
  # have: results/D/<model>/code/<protocol>/<spatial_code_format>/<scene>/<question_id>.json
42
+ RESULTS_DIR = Path(os.environ.get("VSI_HARNESS_D_RESULTS_DIR", "/root/results/D"))
 
 
harness/D/__pycache__/__init__.cpython-311.pyc CHANGED
Binary files a/harness/D/__pycache__/__init__.cpython-311.pyc and b/harness/D/__pycache__/__init__.cpython-311.pyc differ
 
harness/D/__pycache__/launch.cpython-311.pyc CHANGED
Binary files a/harness/D/__pycache__/launch.cpython-311.pyc and b/harness/D/__pycache__/launch.cpython-311.pyc differ
 
harness/D/__pycache__/prompts.cpython-311.pyc CHANGED
Binary files a/harness/D/__pycache__/prompts.cpython-311.pyc and b/harness/D/__pycache__/prompts.cpython-311.pyc differ
 
harness/D/__pycache__/run.cpython-311.pyc CHANGED
Binary files a/harness/D/__pycache__/run.cpython-311.pyc and b/harness/D/__pycache__/run.cpython-311.pyc differ
 
harness/D/__pycache__/sweep.cpython-311.pyc CHANGED
Binary files a/harness/D/__pycache__/sweep.cpython-311.pyc and b/harness/D/__pycache__/sweep.cpython-311.pyc differ
 
harness/D/__pycache__/symbolic_eval.cpython-311.pyc CHANGED
Binary files a/harness/D/__pycache__/symbolic_eval.cpython-311.pyc and b/harness/D/__pycache__/symbolic_eval.cpython-311.pyc differ
 
harness/D/launch.py CHANGED
@@ -26,7 +26,11 @@ if str(WORKSPACE_ROOT) not in sys.path:
26
  from encoder.ground_truth import scenes as ground_truth_scenes # noqa: E402
27
  from harness.A import EXTENDED_MAX_NEW_TOKENS, MAX_NEW_TOKENS # noqa: E402
28
  from harness.A import models as vlm_models # noqa: E402
29
- from harness.B import DEFAULT_INPUT_SELECTION, FRAMES_PER_VIDEO, INPUT_SELECTIONS # noqa: E402
 
 
 
 
30
  from harness.D import DEFAULT_SPATIAL_CODE_FORMAT, SPATIAL_CODE_FORMATS # noqa: E402
31
  from inference.launch import available_cpu_count, visible_gpus # noqa: E402
32
 
@@ -39,9 +43,24 @@ def _load_run_module():
39
  return module
40
 
41
 
42
- def _worker(tasks, results, model, spatial_code_format, results_dir, gpu, cpu_threads,
43
- extended, reasoning_budget, force_budget, strip_schema_legend,
44
- frames, frame_selection, frame_count, raw_budget, flat_distance_table):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  if gpu is not None:
46
  os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu)
47
  for variable in ("OMP_NUM_THREADS", "MKL_NUM_THREADS", "OPENBLAS_NUM_THREADS"):
@@ -89,11 +108,20 @@ def _worker(tasks, results, model, spatial_code_format, results_dir, gpu, cpu_th
89
 
90
 
91
  def launch(
92
- model, spatial_code_format, selected, results_dir=None, rebuild=False,
93
- extended=True, reasoning_budget=EXTENDED_MAX_NEW_TOKENS, force_budget=MAX_NEW_TOKENS,
 
 
 
 
 
 
94
  strip_schema_legend=False,
95
- frames=False, frame_selection=DEFAULT_INPUT_SELECTION, frame_count=FRAMES_PER_VIDEO,
96
- raw_budget=None, flat_distance_table=False,
 
 
 
97
  ):
98
  """Answer every question for ``selected`` scenes, sharded across every visible GPU.
99
 
@@ -103,26 +131,38 @@ def launch(
103
  if extended and raw_budget is not None:
104
  raise ValueError("extended and raw_budget are mutually exclusive")
105
  protocol = (
106
- f"{reasoning_budget}" if extended
107
- else f"truncated/{raw_budget}" if raw_budget is not None
108
- else "base"
109
  )
110
  condition = f"{model}/{protocol}/{spatial_code_format}"
111
  if frames:
112
  condition += f"/frames/{frame_selection}/{frame_count}"
113
  run = _load_run_module()
114
  root = run.results_dir_for(
115
- model, protocol, spatial_code_format, results_dir,
116
- frames=frames, frame_selection=frame_selection, frame_count=frame_count,
 
 
 
 
 
117
  )
118
  pending = []
119
  completed = 0
120
  for scene in selected:
121
  rows = run.load_questions(scene=scene)
 
 
 
 
122
  answered = all((root / scene / f"{row['id']}.json").is_file() for row in rows)
123
  if answered and not rebuild:
124
  completed += 1
125
- print(f"[{condition} {completed}/{len(selected)}] {scene}: skipped", flush=True)
 
 
 
126
  else:
127
  pending.append(scene)
128
  if not pending:
@@ -150,9 +190,22 @@ def launch(
150
  context.Process(
151
  target=_worker,
152
  args=(
153
- tasks, results, model, spatial_code_format, results_dir, gpu, cpu_threads,
154
- extended, reasoning_budget, force_budget, strip_schema_legend,
155
- frames, frame_selection, frame_count, raw_budget, flat_distance_table,
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  ),
157
  )
158
  for gpu in assignments
@@ -194,47 +247,65 @@ def main():
194
  parser = argparse.ArgumentParser()
195
  parser.add_argument("scene", nargs="?")
196
  parser.add_argument(
197
- "--scenes", help="comma-separated scenes (cannot be combined with positional scene)"
 
198
  )
199
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
200
  parser.add_argument(
201
- "--spatial-code-format", default=DEFAULT_SPATIAL_CODE_FORMAT,
202
- choices=SPATIAL_CODE_FORMATS, dest="spatial_code_format",
 
 
203
  )
204
  parser.add_argument("--results-dir", default=None)
205
  parser.add_argument("--rebuild", action="store_true")
206
  parser.add_argument(
207
- "--base-protocol", action="store_true",
 
208
  help="run harness.A's exact fixed 16-token protocol instead of the extended default",
209
  )
210
  parser.add_argument(
211
- "--no-schema-legend", action="store_true", dest="strip_schema_legend",
 
 
212
  help="drop the embedded schema legend (the amended main-run design)",
213
  )
214
  parser.add_argument(
215
- "--with-frames", action="store_true", dest="frames",
 
 
216
  help="frames+ground-truth-code arm: also sample and show the scene's raw video "
217
  "frames alongside the ground-truth code (default sampling: uniform, 32 frames -- "
218
  "the frozen Step-1 config)",
219
  )
220
  parser.add_argument(
221
- "--frame-selection", default=DEFAULT_INPUT_SELECTION, choices=INPUT_SELECTIONS,
222
- dest="frame_selection", help="only used with --with-frames",
 
 
 
223
  )
224
  parser.add_argument(
225
- "--frames-per-video", type=int, default=FRAMES_PER_VIDEO, dest="frame_count",
 
 
 
226
  help="only used with --with-frames",
227
  )
228
  parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
229
  parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
230
  parser.add_argument(
231
- "--truncated-budget", type=int, default=None,
 
 
232
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
233
  "rescue) at this token cap instead of the hardcoded 16 (mutually exclusive "
234
  "with --base-protocol)",
235
  )
236
  parser.add_argument(
237
- "--flat-distance-table", action="store_true", dest="flat_distance_table",
 
 
238
  help="flat-table arm: flatten the distance table's two-level nesting into "
239
  "single-level '<class> to <other>' keys, identical information (pair with "
240
  "an explicit --results-dir)",
@@ -260,11 +331,17 @@ def main():
260
  if args.base_protocol and args.truncated_budget is not None:
261
  parser.error("--base-protocol and --truncated-budget are mutually exclusive")
262
  launch(
263
- args.model, args.spatial_code_format, selected,
264
- results_dir=args.results_dir, rebuild=args.rebuild,
 
 
 
265
  extended=not args.base_protocol and args.truncated_budget is None,
266
- frames=args.frames, frame_selection=args.frame_selection, frame_count=args.frame_count,
267
- reasoning_budget=args.reasoning_budget, force_budget=args.force_budget,
 
 
 
268
  strip_schema_legend=args.strip_schema_legend,
269
  raw_budget=args.truncated_budget,
270
  flat_distance_table=args.flat_distance_table,
 
26
  from encoder.ground_truth import scenes as ground_truth_scenes # noqa: E402
27
  from harness.A import EXTENDED_MAX_NEW_TOKENS, MAX_NEW_TOKENS # noqa: E402
28
  from harness.A import models as vlm_models # noqa: E402
29
+ from harness.B import (
30
+ DEFAULT_INPUT_SELECTION,
31
+ FRAMES_PER_VIDEO,
32
+ INPUT_SELECTIONS,
33
+ ) # noqa: E402
34
  from harness.D import DEFAULT_SPATIAL_CODE_FORMAT, SPATIAL_CODE_FORMATS # noqa: E402
35
  from inference.launch import available_cpu_count, visible_gpus # noqa: E402
36
 
 
43
  return module
44
 
45
 
46
+ def _worker(
47
+ tasks,
48
+ results,
49
+ model,
50
+ spatial_code_format,
51
+ results_dir,
52
+ gpu,
53
+ cpu_threads,
54
+ extended,
55
+ reasoning_budget,
56
+ force_budget,
57
+ strip_schema_legend,
58
+ frames,
59
+ frame_selection,
60
+ frame_count,
61
+ raw_budget,
62
+ flat_distance_table,
63
+ ):
64
  if gpu is not None:
65
  os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu)
66
  for variable in ("OMP_NUM_THREADS", "MKL_NUM_THREADS", "OPENBLAS_NUM_THREADS"):
 
108
 
109
 
110
  def launch(
111
+ model,
112
+ spatial_code_format,
113
+ selected,
114
+ results_dir=None,
115
+ rebuild=False,
116
+ extended=True,
117
+ reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
118
+ force_budget=MAX_NEW_TOKENS,
119
  strip_schema_legend=False,
120
+ frames=False,
121
+ frame_selection=DEFAULT_INPUT_SELECTION,
122
+ frame_count=FRAMES_PER_VIDEO,
123
+ raw_budget=None,
124
+ flat_distance_table=False,
125
  ):
126
  """Answer every question for ``selected`` scenes, sharded across every visible GPU.
127
 
 
131
  if extended and raw_budget is not None:
132
  raise ValueError("extended and raw_budget are mutually exclusive")
133
  protocol = (
134
+ f"{reasoning_budget}"
135
+ if extended
136
+ else f"truncated/{raw_budget}" if raw_budget is not None else "base"
137
  )
138
  condition = f"{model}/{protocol}/{spatial_code_format}"
139
  if frames:
140
  condition += f"/frames/{frame_selection}/{frame_count}"
141
  run = _load_run_module()
142
  root = run.results_dir_for(
143
+ model,
144
+ protocol,
145
+ spatial_code_format,
146
+ results_dir,
147
+ frames=frames,
148
+ frame_selection=frame_selection,
149
+ frame_count=frame_count,
150
  )
151
  pending = []
152
  completed = 0
153
  for scene in selected:
154
  rows = run.load_questions(scene=scene)
155
+ if not rows:
156
+ raise ValueError(
157
+ f"no questions found for scene {scene!r}; check the manifest/scene selection"
158
+ )
159
  answered = all((root / scene / f"{row['id']}.json").is_file() for row in rows)
160
  if answered and not rebuild:
161
  completed += 1
162
+ print(
163
+ f"[{condition} {completed}/{len(selected)}] {scene}: skipped",
164
+ flush=True,
165
+ )
166
  else:
167
  pending.append(scene)
168
  if not pending:
 
190
  context.Process(
191
  target=_worker,
192
  args=(
193
+ tasks,
194
+ results,
195
+ model,
196
+ spatial_code_format,
197
+ results_dir,
198
+ gpu,
199
+ cpu_threads,
200
+ extended,
201
+ reasoning_budget,
202
+ force_budget,
203
+ strip_schema_legend,
204
+ frames,
205
+ frame_selection,
206
+ frame_count,
207
+ raw_budget,
208
+ flat_distance_table,
209
  ),
210
  )
211
  for gpu in assignments
 
247
  parser = argparse.ArgumentParser()
248
  parser.add_argument("scene", nargs="?")
249
  parser.add_argument(
250
+ "--scenes",
251
+ help="comma-separated scenes (cannot be combined with positional scene)",
252
  )
253
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
254
  parser.add_argument(
255
+ "--spatial-code-format",
256
+ default=DEFAULT_SPATIAL_CODE_FORMAT,
257
+ choices=SPATIAL_CODE_FORMATS,
258
+ dest="spatial_code_format",
259
  )
260
  parser.add_argument("--results-dir", default=None)
261
  parser.add_argument("--rebuild", action="store_true")
262
  parser.add_argument(
263
+ "--base-protocol",
264
+ action="store_true",
265
  help="run harness.A's exact fixed 16-token protocol instead of the extended default",
266
  )
267
  parser.add_argument(
268
+ "--no-schema-legend",
269
+ action="store_true",
270
+ dest="strip_schema_legend",
271
  help="drop the embedded schema legend (the amended main-run design)",
272
  )
273
  parser.add_argument(
274
+ "--with-frames",
275
+ action="store_true",
276
+ dest="frames",
277
  help="frames+ground-truth-code arm: also sample and show the scene's raw video "
278
  "frames alongside the ground-truth code (default sampling: uniform, 32 frames -- "
279
  "the frozen Step-1 config)",
280
  )
281
  parser.add_argument(
282
+ "--frame-selection",
283
+ default=DEFAULT_INPUT_SELECTION,
284
+ choices=INPUT_SELECTIONS,
285
+ dest="frame_selection",
286
+ help="only used with --with-frames",
287
  )
288
  parser.add_argument(
289
+ "--frames-per-video",
290
+ type=int,
291
+ default=FRAMES_PER_VIDEO,
292
+ dest="frame_count",
293
  help="only used with --with-frames",
294
  )
295
  parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
296
  parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
297
  parser.add_argument(
298
+ "--truncated-budget",
299
+ type=int,
300
+ default=None,
301
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
302
  "rescue) at this token cap instead of the hardcoded 16 (mutually exclusive "
303
  "with --base-protocol)",
304
  )
305
  parser.add_argument(
306
+ "--flat-distance-table",
307
+ action="store_true",
308
+ dest="flat_distance_table",
309
  help="flat-table arm: flatten the distance table's two-level nesting into "
310
  "single-level '<class> to <other>' keys, identical information (pair with "
311
  "an explicit --results-dir)",
 
331
  if args.base_protocol and args.truncated_budget is not None:
332
  parser.error("--base-protocol and --truncated-budget are mutually exclusive")
333
  launch(
334
+ args.model,
335
+ args.spatial_code_format,
336
+ selected,
337
+ results_dir=args.results_dir,
338
+ rebuild=args.rebuild,
339
  extended=not args.base_protocol and args.truncated_budget is None,
340
+ frames=args.frames,
341
+ frame_selection=args.frame_selection,
342
+ frame_count=args.frame_count,
343
+ reasoning_budget=args.reasoning_budget,
344
+ force_budget=args.force_budget,
345
  strip_schema_legend=args.strip_schema_legend,
346
  raw_budget=args.truncated_budget,
347
  flat_distance_table=args.flat_distance_table,
harness/D/prompts.py CHANGED
@@ -12,11 +12,18 @@ from __future__ import annotations
12
 
13
  import json
14
 
15
- from harness.A.prompts import MCA_POST_PROMPT, MCA_QUESTION_TYPES, NA_POST_PROMPT, NA_QUESTION_TYPES
 
 
 
 
 
16
  from harness.B.prompts import NO_LEGEND_PRE_PROMPT, PRE_PROMPT
17
 
18
 
19
- def build_prompt(spatial_code, question_type, question, options=None, context_line=None):
 
 
20
  """Return the full text prompt: context line, the spatial code itself, the question,
21
  and the same VSI-Bench post-prompt harness.A uses for the same question_type.
22
  ``context_line`` overrides the standard PRE_PROMPT (the no-legend main-run design
@@ -29,7 +36,9 @@ def build_prompt(spatial_code, question_type, question, options=None, context_li
29
  if not options:
30
  raise ValueError(f"question_type {question_type!r} requires options")
31
  options_block = "Options:\n" + "\n".join(options)
32
- return "\n".join([pre_prompt, code_text, question, options_block, MCA_POST_PROMPT])
 
 
33
  raise ValueError(
34
  f"unknown question_type {question_type!r}; "
35
  f"expected one of {MCA_QUESTION_TYPES + NA_QUESTION_TYPES}"
 
12
 
13
  import json
14
 
15
+ from harness.A.prompts import (
16
+ MCA_POST_PROMPT,
17
+ MCA_QUESTION_TYPES,
18
+ NA_POST_PROMPT,
19
+ NA_QUESTION_TYPES,
20
+ )
21
  from harness.B.prompts import NO_LEGEND_PRE_PROMPT, PRE_PROMPT
22
 
23
 
24
+ def build_prompt(
25
+ spatial_code, question_type, question, options=None, context_line=None
26
+ ):
27
  """Return the full text prompt: context line, the spatial code itself, the question,
28
  and the same VSI-Bench post-prompt harness.A uses for the same question_type.
29
  ``context_line`` overrides the standard PRE_PROMPT (the no-legend main-run design
 
36
  if not options:
37
  raise ValueError(f"question_type {question_type!r} requires options")
38
  options_block = "Options:\n" + "\n".join(options)
39
+ return "\n".join(
40
+ [pre_prompt, code_text, question, options_block, MCA_POST_PROMPT]
41
+ )
42
  raise ValueError(
43
  f"unknown question_type {question_type!r}; "
44
  f"expected one of {MCA_QUESTION_TYPES + NA_QUESTION_TYPES}"
harness/D/run.py CHANGED
@@ -25,18 +25,31 @@ from harness.A import EXTENDED_MAX_NEW_TOKENS, MAX_NEW_TOKENS # noqa: E402
25
  from harness.A import frames as frame_sampling # noqa: E402
26
  from harness.A import models as vlm_models # noqa: E402
27
  from harness.A.run import _scalar_score, load_questions, vsi_official_eval # noqa: E402
28
- from harness.B import DEFAULT_INPUT_SELECTION, FRAMES_PER_VIDEO, INPUT_SELECTIONS # noqa: E402
 
 
 
 
29
  from harness.B.prompts import flat_distance_table as _flat_distance_table # noqa: E402
30
  from harness.C import prompts as combined_prompts # noqa: E402
31
- from harness.D import DEFAULT_SPATIAL_CODE_FORMAT, RESULTS_DIR, SPATIAL_CODE_FORMATS # noqa: E402
 
 
 
 
32
  from harness.D import prompts as code_prompts # noqa: E402
33
  from harness.D.prompts import NO_LEGEND_PRE_PROMPT # noqa: E402
34
  from harness.D import spatial_codes # noqa: E402
35
 
36
 
37
  def results_dir_for(
38
- model, protocol, spatial_code_format, results_dir=None,
39
- frames=False, frame_selection=DEFAULT_INPUT_SELECTION, frame_count=FRAMES_PER_VIDEO,
 
 
 
 
 
40
  ):
41
  """Return the result root isolated by model + protocol + spatial-code-format.
42
  ``protocol`` is "base" (16-token) or "<reasoning budget>" (e.g. "512") -- a real path segment, so records from different protocols OR
@@ -49,13 +62,21 @@ def results_dir_for(
49
  records must never share a path with the text-only condition's."""
50
  if results_dir is not None:
51
  return Path(results_dir)
52
- root = RESULTS_DIR / model / ("code + frames" if frames else "code") / protocol / spatial_code_format
 
 
 
 
 
 
53
  if frames:
54
  root = root / frame_selection / str(frame_count)
55
  return root
56
 
57
 
58
- def _build_record(row, prompt, answer, metric_name, score, model, model_path, code_info):
 
 
59
  """Assemble one question's full, untruncated result record (nothing summarized).
60
 
61
  ``code_info`` carries frame provenance (``video_path``, ``frame_indices``,
@@ -64,7 +85,9 @@ def _build_record(row, prompt, answer, metric_name, score, model, model_path, co
64
  fields (``reasoning_text`` etc.) are present-but-null rather than absent."""
65
  condition = f"{code_info['protocol']}:{code_info['spatial_code_format']}"
66
  if code_info.get("frames"):
67
- condition += f":frames:{code_info['frame_selection']}:{code_info['frame_count']}"
 
 
68
  return {
69
  "model": model,
70
  "model_path": str(model_path),
@@ -113,12 +136,25 @@ def _build_record(row, prompt, answer, metric_name, score, model, model_path, co
113
 
114
 
115
  def write_question_result(
116
- row, prompt, answer, metric_name, score, model, model_path, code_info, results_dir=None
 
 
 
 
 
 
 
 
117
  ):
118
  """Write one question's full, untruncated result record. Return (path, record)."""
119
- record = _build_record(row, prompt, answer, metric_name, score, model, model_path, code_info)
 
 
120
  root = results_dir_for(
121
- model, code_info["protocol"], code_info["spatial_code_format"], results_dir,
 
 
 
122
  frames=code_info.get("frames", False),
123
  frame_selection=code_info.get("frame_selection", DEFAULT_INPUT_SELECTION),
124
  frame_count=code_info.get("frame_count", FRAMES_PER_VIDEO),
@@ -215,7 +251,9 @@ def run(
215
  for row in rows:
216
  scene_id = row["scene_name"]
217
  if scene_id not in code_cache:
218
- code, path = spatial_codes.load_spatial_code(scene_id, spatial_code_format)
 
 
219
  if code_transform is not None:
220
  code = code_transform(code, scene_id, spatial_code_format)
221
  if strip_schema_legend:
@@ -224,47 +262,64 @@ def run(
224
  code = _flat_distance_table(code)
225
  entry = {"code": code, "path": path}
226
  if frames:
227
- video_path = inference_config.video_path(scene_id, row.get("dataset"))
228
- frame_images, frame_timestamps, frame_indices = frame_sampling.sample_frames(
229
- video_path, frame_count, frame_selection
 
 
 
 
230
  )
231
  entry.update(
232
- video_path=video_path, frame_images=frame_images,
233
- frame_timestamps=frame_timestamps, frame_indices=frame_indices,
 
 
234
  )
235
  code_cache[scene_id] = entry
236
  cached = code_cache[scene_id]
237
  if frames:
238
  context_line = (
239
- combined_prompts.NO_LEGEND_PRE_PROMPT if strip_schema_legend
 
240
  else combined_prompts.PRE_PROMPT
241
  )
242
  else:
243
  context_line = NO_LEGEND_PRE_PROMPT if strip_schema_legend else None
244
  prompt = code_prompts.build_prompt(
245
- cached["code"], row["question_type"], row["question"], row.get("options"),
 
 
 
246
  context_line=context_line,
247
  )
248
  answer = (
249
  adapter.answer_extended(
250
- cached["frame_images"] if frames else [], prompt,
251
- reasoning_budget=reasoning_budget, force_budget=force_budget,
 
 
252
  )
253
  if extended
254
  else adapter.answer(
255
- cached["frame_images"] if frames else [], prompt, max_new_tokens=raw_budget
 
 
256
  )
257
  )
258
- doc = {"question_type": row["question_type"], "ground_truth": row["ground_truth"]}
 
 
 
259
  score_doc = vsi_official_eval.vsibench_process_results(
260
  doc, [answer["answer_text"]]
261
  )["vsibench_score"]
262
  metric_name, score = _scalar_score(row["question_type"], score_doc)
263
  code_info = {
264
  "protocol": (
265
- f"{reasoning_budget}" if extended
266
- else f"truncated/{raw_budget}" if raw_budget is not None
267
- else "base"
268
  ),
269
  "spatial_code_format": spatial_code_format,
270
  "spatial_code_path": cached["path"],
@@ -277,13 +332,27 @@ def run(
277
  }
278
  if write_results:
279
  path, record = write_question_result(
280
- row, prompt, answer, metric_name, score, model, adapter.model_path,
281
- code_info, results_dir,
 
 
 
 
 
 
 
282
  )
283
  else:
284
  path = None
285
  record = _build_record(
286
- row, prompt, answer, metric_name, score, model, adapter.model_path, code_info
 
 
 
 
 
 
 
287
  )
288
  record["result_path"] = str(path) if path else None
289
  results.append(record)
@@ -298,52 +367,73 @@ def main():
298
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
299
  parser.add_argument("--scene", default=None, help="restrict to one VSI-Bench scene")
300
  parser.add_argument(
301
- "--spatial-code-format", default=DEFAULT_SPATIAL_CODE_FORMAT,
302
- choices=SPATIAL_CODE_FORMATS, dest="spatial_code_format",
 
 
 
 
 
303
  )
304
- parser.add_argument("--limit", type=int, default=None, help="cap the number of questions")
305
  parser.add_argument("--device", default="cuda")
306
  parser.add_argument(
307
- "--results-dir", default=None,
 
308
  help="override the default results/D/<model>/<code or code + frames>/<protocol>/<format> root",
309
  )
310
  parser.add_argument(
311
- "--no-write", action="store_true",
 
312
  help="skip writing per-question JSON files; print/score only",
313
  )
314
  parser.add_argument(
315
- "--base-protocol", action="store_true",
 
316
  help="run harness.A's exact fixed 16-token protocol (plain answer()) instead of "
317
  "the extended 2048-token default",
318
  )
319
  parser.add_argument(
320
- "--no-schema-legend", action="store_true", dest="strip_schema_legend",
 
 
321
  help="drop the embedded schema legend (the amended main-run design)",
322
  )
323
  parser.add_argument(
324
- "--with-frames", action="store_true", dest="frames",
 
 
325
  help="frames+ground-truth-code arm: also sample and show the scene's raw video "
326
  "frames alongside the ground-truth code (default sampling: uniform, 32 frames -- "
327
  "the frozen Step-1 config)",
328
  )
329
  parser.add_argument(
330
- "--frame-selection", default=DEFAULT_INPUT_SELECTION, choices=INPUT_SELECTIONS,
331
- dest="frame_selection", help="only used with --with-frames",
 
 
 
332
  )
333
  parser.add_argument(
334
- "--frames-per-video", type=int, default=FRAMES_PER_VIDEO, dest="frame_count",
 
 
 
335
  help="only used with --with-frames",
336
  )
337
  parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
338
  parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
339
  parser.add_argument(
340
- "--truncated-budget", type=int, default=None,
 
 
341
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
342
  "rescue) at this token cap instead of the hardcoded 16 (mutually exclusive "
343
  "with --base-protocol)",
344
  )
345
  parser.add_argument(
346
- "--flat-distance-table", action="store_true", dest="flat_distance_table",
 
 
347
  help="flat-table arm: flatten the distance table's two-level nesting into "
348
  "single-level '<class> to <other>' keys, identical information (pair with "
349
  "an explicit --results-dir)",
 
25
  from harness.A import frames as frame_sampling # noqa: E402
26
  from harness.A import models as vlm_models # noqa: E402
27
  from harness.A.run import _scalar_score, load_questions, vsi_official_eval # noqa: E402
28
+ from harness.B import (
29
+ DEFAULT_INPUT_SELECTION,
30
+ FRAMES_PER_VIDEO,
31
+ INPUT_SELECTIONS,
32
+ ) # noqa: E402
33
  from harness.B.prompts import flat_distance_table as _flat_distance_table # noqa: E402
34
  from harness.C import prompts as combined_prompts # noqa: E402
35
+ from harness.D import (
36
+ DEFAULT_SPATIAL_CODE_FORMAT,
37
+ RESULTS_DIR,
38
+ SPATIAL_CODE_FORMATS,
39
+ ) # noqa: E402
40
  from harness.D import prompts as code_prompts # noqa: E402
41
  from harness.D.prompts import NO_LEGEND_PRE_PROMPT # noqa: E402
42
  from harness.D import spatial_codes # noqa: E402
43
 
44
 
45
  def results_dir_for(
46
+ model,
47
+ protocol,
48
+ spatial_code_format,
49
+ results_dir=None,
50
+ frames=False,
51
+ frame_selection=DEFAULT_INPUT_SELECTION,
52
+ frame_count=FRAMES_PER_VIDEO,
53
  ):
54
  """Return the result root isolated by model + protocol + spatial-code-format.
55
  ``protocol`` is "base" (16-token) or "<reasoning budget>" (e.g. "512") -- a real path segment, so records from different protocols OR
 
62
  records must never share a path with the text-only condition's."""
63
  if results_dir is not None:
64
  return Path(results_dir)
65
+ root = (
66
+ RESULTS_DIR
67
+ / model
68
+ / ("code + frames" if frames else "code")
69
+ / protocol
70
+ / spatial_code_format
71
+ )
72
  if frames:
73
  root = root / frame_selection / str(frame_count)
74
  return root
75
 
76
 
77
+ def _build_record(
78
+ row, prompt, answer, metric_name, score, model, model_path, code_info
79
+ ):
80
  """Assemble one question's full, untruncated result record (nothing summarized).
81
 
82
  ``code_info`` carries frame provenance (``video_path``, ``frame_indices``,
 
85
  fields (``reasoning_text`` etc.) are present-but-null rather than absent."""
86
  condition = f"{code_info['protocol']}:{code_info['spatial_code_format']}"
87
  if code_info.get("frames"):
88
+ condition += (
89
+ f":frames:{code_info['frame_selection']}:{code_info['frame_count']}"
90
+ )
91
  return {
92
  "model": model,
93
  "model_path": str(model_path),
 
136
 
137
 
138
  def write_question_result(
139
+ row,
140
+ prompt,
141
+ answer,
142
+ metric_name,
143
+ score,
144
+ model,
145
+ model_path,
146
+ code_info,
147
+ results_dir=None,
148
  ):
149
  """Write one question's full, untruncated result record. Return (path, record)."""
150
+ record = _build_record(
151
+ row, prompt, answer, metric_name, score, model, model_path, code_info
152
+ )
153
  root = results_dir_for(
154
+ model,
155
+ code_info["protocol"],
156
+ code_info["spatial_code_format"],
157
+ results_dir,
158
  frames=code_info.get("frames", False),
159
  frame_selection=code_info.get("frame_selection", DEFAULT_INPUT_SELECTION),
160
  frame_count=code_info.get("frame_count", FRAMES_PER_VIDEO),
 
251
  for row in rows:
252
  scene_id = row["scene_name"]
253
  if scene_id not in code_cache:
254
+ code, path = spatial_codes.load_spatial_code(
255
+ scene_id, spatial_code_format
256
+ )
257
  if code_transform is not None:
258
  code = code_transform(code, scene_id, spatial_code_format)
259
  if strip_schema_legend:
 
262
  code = _flat_distance_table(code)
263
  entry = {"code": code, "path": path}
264
  if frames:
265
+ video_path = inference_config.video_path(
266
+ scene_id, row.get("dataset")
267
+ )
268
+ frame_images, frame_timestamps, frame_indices = (
269
+ frame_sampling.sample_frames(
270
+ video_path, frame_count, frame_selection
271
+ )
272
  )
273
  entry.update(
274
+ video_path=video_path,
275
+ frame_images=frame_images,
276
+ frame_timestamps=frame_timestamps,
277
+ frame_indices=frame_indices,
278
  )
279
  code_cache[scene_id] = entry
280
  cached = code_cache[scene_id]
281
  if frames:
282
  context_line = (
283
+ combined_prompts.NO_LEGEND_PRE_PROMPT
284
+ if strip_schema_legend
285
  else combined_prompts.PRE_PROMPT
286
  )
287
  else:
288
  context_line = NO_LEGEND_PRE_PROMPT if strip_schema_legend else None
289
  prompt = code_prompts.build_prompt(
290
+ cached["code"],
291
+ row["question_type"],
292
+ row["question"],
293
+ row.get("options"),
294
  context_line=context_line,
295
  )
296
  answer = (
297
  adapter.answer_extended(
298
+ cached["frame_images"] if frames else [],
299
+ prompt,
300
+ reasoning_budget=reasoning_budget,
301
+ force_budget=force_budget,
302
  )
303
  if extended
304
  else adapter.answer(
305
+ cached["frame_images"] if frames else [],
306
+ prompt,
307
+ max_new_tokens=raw_budget,
308
  )
309
  )
310
+ doc = {
311
+ "question_type": row["question_type"],
312
+ "ground_truth": row["ground_truth"],
313
+ }
314
  score_doc = vsi_official_eval.vsibench_process_results(
315
  doc, [answer["answer_text"]]
316
  )["vsibench_score"]
317
  metric_name, score = _scalar_score(row["question_type"], score_doc)
318
  code_info = {
319
  "protocol": (
320
+ f"{reasoning_budget}"
321
+ if extended
322
+ else f"truncated/{raw_budget}" if raw_budget is not None else "base"
323
  ),
324
  "spatial_code_format": spatial_code_format,
325
  "spatial_code_path": cached["path"],
 
332
  }
333
  if write_results:
334
  path, record = write_question_result(
335
+ row,
336
+ prompt,
337
+ answer,
338
+ metric_name,
339
+ score,
340
+ model,
341
+ adapter.model_path,
342
+ code_info,
343
+ results_dir,
344
  )
345
  else:
346
  path = None
347
  record = _build_record(
348
+ row,
349
+ prompt,
350
+ answer,
351
+ metric_name,
352
+ score,
353
+ model,
354
+ adapter.model_path,
355
+ code_info,
356
  )
357
  record["result_path"] = str(path) if path else None
358
  results.append(record)
 
367
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
368
  parser.add_argument("--scene", default=None, help="restrict to one VSI-Bench scene")
369
  parser.add_argument(
370
+ "--spatial-code-format",
371
+ default=DEFAULT_SPATIAL_CODE_FORMAT,
372
+ choices=SPATIAL_CODE_FORMATS,
373
+ dest="spatial_code_format",
374
+ )
375
+ parser.add_argument(
376
+ "--limit", type=int, default=None, help="cap the number of questions"
377
  )
 
378
  parser.add_argument("--device", default="cuda")
379
  parser.add_argument(
380
+ "--results-dir",
381
+ default=None,
382
  help="override the default results/D/<model>/<code or code + frames>/<protocol>/<format> root",
383
  )
384
  parser.add_argument(
385
+ "--no-write",
386
+ action="store_true",
387
  help="skip writing per-question JSON files; print/score only",
388
  )
389
  parser.add_argument(
390
+ "--base-protocol",
391
+ action="store_true",
392
  help="run harness.A's exact fixed 16-token protocol (plain answer()) instead of "
393
  "the extended 2048-token default",
394
  )
395
  parser.add_argument(
396
+ "--no-schema-legend",
397
+ action="store_true",
398
+ dest="strip_schema_legend",
399
  help="drop the embedded schema legend (the amended main-run design)",
400
  )
401
  parser.add_argument(
402
+ "--with-frames",
403
+ action="store_true",
404
+ dest="frames",
405
  help="frames+ground-truth-code arm: also sample and show the scene's raw video "
406
  "frames alongside the ground-truth code (default sampling: uniform, 32 frames -- "
407
  "the frozen Step-1 config)",
408
  )
409
  parser.add_argument(
410
+ "--frame-selection",
411
+ default=DEFAULT_INPUT_SELECTION,
412
+ choices=INPUT_SELECTIONS,
413
+ dest="frame_selection",
414
+ help="only used with --with-frames",
415
  )
416
  parser.add_argument(
417
+ "--frames-per-video",
418
+ type=int,
419
+ default=FRAMES_PER_VIDEO,
420
+ dest="frame_count",
421
  help="only used with --with-frames",
422
  )
423
  parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
424
  parser.add_argument("--force-budget", type=int, default=MAX_NEW_TOKENS)
425
  parser.add_argument(
426
+ "--truncated-budget",
427
+ type=int,
428
+ default=None,
429
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
430
  "rescue) at this token cap instead of the hardcoded 16 (mutually exclusive "
431
  "with --base-protocol)",
432
  )
433
  parser.add_argument(
434
+ "--flat-distance-table",
435
+ action="store_true",
436
+ dest="flat_distance_table",
437
  help="flat-table arm: flatten the distance table's two-level nesting into "
438
  "single-level '<class> to <other>' keys, identical information (pair with "
439
  "an explicit --results-dir)",
harness/D/sweep.py CHANGED
@@ -25,7 +25,12 @@ if str(WORKSPACE_ROOT) not in sys.path:
25
  from harness.A import models as vlm_models # noqa: E402
26
  from harness.A import EXTENDED_MAX_NEW_TOKENS # noqa: E402
27
  from harness.A.sweep import _parse_csv_choice # noqa: E402
28
- from harness.B import DEFAULT_INPUT_SELECTION, FRAMES_PER_VIDEO, INPUT_SELECTIONS, SPATIAL_CODE_FORMATS # noqa: E402
 
 
 
 
 
29
  from harness.D import launch as harness_launch # noqa: E402
30
 
31
 
@@ -39,30 +44,48 @@ def build_plan(models, spatial_code_formats):
39
 
40
 
41
  def sweep(
42
- models, spatial_code_formats, selected_scenes, results_dir=None, rebuild=False,
43
- extended=True, reasoning_budget=EXTENDED_MAX_NEW_TOKENS, strip_schema_legend=False,
44
- frames=False, frame_selection=DEFAULT_INPUT_SELECTION, frame_count=FRAMES_PER_VIDEO,
45
- raw_budget=None, flat_distance_table=False,
 
 
 
 
 
 
 
 
 
46
  ):
47
  """Run every (model, spatial_code_format) pair across all visible GPUs."""
48
  plan = build_plan(models, spatial_code_formats)
49
  protocol = (
50
- f"{reasoning_budget}" if extended
51
- else f"truncated/{raw_budget}" if raw_budget is not None
52
- else "base"
53
  )
54
  for index, (model, spatial_code_format) in enumerate(plan, start=1):
55
  print(
56
  f"=== sweep {index}/{len(plan)}: {model}/{protocol}/{spatial_code_format}"
57
- + (f"/frames/{frame_selection}/{frame_count}" if frames else "") + " ===",
 
58
  flush=True,
59
  )
60
  harness_launch.launch(
61
- model, spatial_code_format, selected_scenes,
62
- results_dir=results_dir, rebuild=rebuild, extended=extended,
63
- reasoning_budget=reasoning_budget, strip_schema_legend=strip_schema_legend,
64
- frames=frames, frame_selection=frame_selection, frame_count=frame_count,
65
- raw_budget=raw_budget, flat_distance_table=flat_distance_table,
 
 
 
 
 
 
 
 
66
  )
67
 
68
 
@@ -70,55 +93,76 @@ def main():
70
  parser = argparse.ArgumentParser()
71
  parser.add_argument("scene", nargs="?")
72
  parser.add_argument(
73
- "--scenes", help="comma-separated scenes (cannot be combined with positional scene)"
 
74
  )
75
  parser.add_argument(
76
- "--models", required=True,
 
77
  help=f"comma-separated models (or 'all'); one of {vlm_models.available_models()}",
78
  )
79
  parser.add_argument(
80
- "--spatial-code-formats", default="all", dest="spatial_code_formats",
 
 
81
  help=f"comma-separated formats (or 'all'); one of {SPATIAL_CODE_FORMATS}",
82
  )
83
  parser.add_argument("--results-dir", default=None)
84
  parser.add_argument("--rebuild", action="store_true")
85
  parser.add_argument(
86
- "--base-protocol", action="store_true",
 
87
  help="run the whole sweep under harness.A's exact fixed 16-token protocol "
88
  "instead of the extended default",
89
  )
90
  parser.add_argument(
91
- "--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS,
 
 
92
  dest="reasoning_budget",
93
  help="extended-protocol first-pass budget (the calibrated value from "
94
  "analysis/preregistration.md, e.g. 512)",
95
  )
96
  parser.add_argument(
97
- "--no-schema-legend", action="store_true", dest="strip_schema_legend",
 
 
98
  help="drop the embedded schema legend (the amended main-run design)",
99
  )
100
  parser.add_argument(
101
- "--with-frames", action="store_true", dest="frames",
 
 
102
  help="frames+ground-truth-code arm: also sample and show the scene's raw video "
103
  "frames alongside the ground-truth code (default sampling: uniform, 32 frames -- "
104
  "the frozen Step-1 config)",
105
  )
106
  parser.add_argument(
107
- "--frame-selection", default=DEFAULT_INPUT_SELECTION, choices=INPUT_SELECTIONS,
108
- dest="frame_selection", help="only used with --with-frames",
 
 
 
109
  )
110
  parser.add_argument(
111
- "--frames-per-video", type=int, default=FRAMES_PER_VIDEO, dest="frame_count",
 
 
 
112
  help="only used with --with-frames",
113
  )
114
  parser.add_argument(
115
- "--truncated-budget", type=int, default=None,
 
 
116
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
117
  "rescue) at this token cap instead of the hardcoded 16 (mutually exclusive "
118
  "with --base-protocol)",
119
  )
120
  parser.add_argument(
121
- "--flat-distance-table", action="store_true", dest="flat_distance_table",
 
 
122
  help="flat-table arm: flatten the distance table's two-level nesting into "
123
  "single-level '<class> to <other>' keys, identical information",
124
  )
@@ -133,7 +177,9 @@ def main():
133
  parser.error("--base-protocol and --truncated-budget are mutually exclusive")
134
 
135
  try:
136
- models = _parse_csv_choice(args.models, vlm_models.available_models(), "--models")
 
 
137
  spatial_code_formats = _parse_csv_choice(
138
  args.spatial_code_formats, SPATIAL_CODE_FORMATS, "--spatial-code-formats"
139
  )
@@ -149,12 +195,17 @@ def main():
149
  selected = [args.scene] if args.scene else harness_launch.scenes()
150
 
151
  sweep(
152
- models, spatial_code_formats, selected,
153
- results_dir=args.results_dir, rebuild=args.rebuild,
 
 
 
154
  extended=not args.base_protocol and args.truncated_budget is None,
155
  reasoning_budget=args.reasoning_budget,
156
  strip_schema_legend=args.strip_schema_legend,
157
- frames=args.frames, frame_selection=args.frame_selection, frame_count=args.frame_count,
 
 
158
  raw_budget=args.truncated_budget,
159
  flat_distance_table=args.flat_distance_table,
160
  )
 
25
  from harness.A import models as vlm_models # noqa: E402
26
  from harness.A import EXTENDED_MAX_NEW_TOKENS # noqa: E402
27
  from harness.A.sweep import _parse_csv_choice # noqa: E402
28
+ from harness.B import (
29
+ DEFAULT_INPUT_SELECTION,
30
+ FRAMES_PER_VIDEO,
31
+ INPUT_SELECTIONS,
32
+ SPATIAL_CODE_FORMATS,
33
+ ) # noqa: E402
34
  from harness.D import launch as harness_launch # noqa: E402
35
 
36
 
 
44
 
45
 
46
  def sweep(
47
+ models,
48
+ spatial_code_formats,
49
+ selected_scenes,
50
+ results_dir=None,
51
+ rebuild=False,
52
+ extended=True,
53
+ reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
54
+ strip_schema_legend=False,
55
+ frames=False,
56
+ frame_selection=DEFAULT_INPUT_SELECTION,
57
+ frame_count=FRAMES_PER_VIDEO,
58
+ raw_budget=None,
59
+ flat_distance_table=False,
60
  ):
61
  """Run every (model, spatial_code_format) pair across all visible GPUs."""
62
  plan = build_plan(models, spatial_code_formats)
63
  protocol = (
64
+ f"{reasoning_budget}"
65
+ if extended
66
+ else f"truncated/{raw_budget}" if raw_budget is not None else "base"
67
  )
68
  for index, (model, spatial_code_format) in enumerate(plan, start=1):
69
  print(
70
  f"=== sweep {index}/{len(plan)}: {model}/{protocol}/{spatial_code_format}"
71
+ + (f"/frames/{frame_selection}/{frame_count}" if frames else "")
72
+ + " ===",
73
  flush=True,
74
  )
75
  harness_launch.launch(
76
+ model,
77
+ spatial_code_format,
78
+ selected_scenes,
79
+ results_dir=results_dir,
80
+ rebuild=rebuild,
81
+ extended=extended,
82
+ reasoning_budget=reasoning_budget,
83
+ strip_schema_legend=strip_schema_legend,
84
+ frames=frames,
85
+ frame_selection=frame_selection,
86
+ frame_count=frame_count,
87
+ raw_budget=raw_budget,
88
+ flat_distance_table=flat_distance_table,
89
  )
90
 
91
 
 
93
  parser = argparse.ArgumentParser()
94
  parser.add_argument("scene", nargs="?")
95
  parser.add_argument(
96
+ "--scenes",
97
+ help="comma-separated scenes (cannot be combined with positional scene)",
98
  )
99
  parser.add_argument(
100
+ "--models",
101
+ required=True,
102
  help=f"comma-separated models (or 'all'); one of {vlm_models.available_models()}",
103
  )
104
  parser.add_argument(
105
+ "--spatial-code-formats",
106
+ default="all",
107
+ dest="spatial_code_formats",
108
  help=f"comma-separated formats (or 'all'); one of {SPATIAL_CODE_FORMATS}",
109
  )
110
  parser.add_argument("--results-dir", default=None)
111
  parser.add_argument("--rebuild", action="store_true")
112
  parser.add_argument(
113
+ "--base-protocol",
114
+ action="store_true",
115
  help="run the whole sweep under harness.A's exact fixed 16-token protocol "
116
  "instead of the extended default",
117
  )
118
  parser.add_argument(
119
+ "--reasoning-budget",
120
+ type=int,
121
+ default=EXTENDED_MAX_NEW_TOKENS,
122
  dest="reasoning_budget",
123
  help="extended-protocol first-pass budget (the calibrated value from "
124
  "analysis/preregistration.md, e.g. 512)",
125
  )
126
  parser.add_argument(
127
+ "--no-schema-legend",
128
+ action="store_true",
129
+ dest="strip_schema_legend",
130
  help="drop the embedded schema legend (the amended main-run design)",
131
  )
132
  parser.add_argument(
133
+ "--with-frames",
134
+ action="store_true",
135
+ dest="frames",
136
  help="frames+ground-truth-code arm: also sample and show the scene's raw video "
137
  "frames alongside the ground-truth code (default sampling: uniform, 32 frames -- "
138
  "the frozen Step-1 config)",
139
  )
140
  parser.add_argument(
141
+ "--frame-selection",
142
+ default=DEFAULT_INPUT_SELECTION,
143
+ choices=INPUT_SELECTIONS,
144
+ dest="frame_selection",
145
+ help="only used with --with-frames",
146
  )
147
  parser.add_argument(
148
+ "--frames-per-video",
149
+ type=int,
150
+ default=FRAMES_PER_VIDEO,
151
+ dest="frame_count",
152
  help="only used with --with-frames",
153
  )
154
  parser.add_argument(
155
+ "--truncated-budget",
156
+ type=int,
157
+ default=None,
158
  help="raw-budget arm: base-protocol mechanics (single generation, no forced "
159
  "rescue) at this token cap instead of the hardcoded 16 (mutually exclusive "
160
  "with --base-protocol)",
161
  )
162
  parser.add_argument(
163
+ "--flat-distance-table",
164
+ action="store_true",
165
+ dest="flat_distance_table",
166
  help="flat-table arm: flatten the distance table's two-level nesting into "
167
  "single-level '<class> to <other>' keys, identical information",
168
  )
 
177
  parser.error("--base-protocol and --truncated-budget are mutually exclusive")
178
 
179
  try:
180
+ models = _parse_csv_choice(
181
+ args.models, vlm_models.available_models(), "--models"
182
+ )
183
  spatial_code_formats = _parse_csv_choice(
184
  args.spatial_code_formats, SPATIAL_CODE_FORMATS, "--spatial-code-formats"
185
  )
 
195
  selected = [args.scene] if args.scene else harness_launch.scenes()
196
 
197
  sweep(
198
+ models,
199
+ spatial_code_formats,
200
+ selected,
201
+ results_dir=args.results_dir,
202
+ rebuild=args.rebuild,
203
  extended=not args.base_protocol and args.truncated_budget is None,
204
  reasoning_budget=args.reasoning_budget,
205
  strip_schema_legend=args.strip_schema_legend,
206
+ frames=args.frames,
207
+ frame_selection=args.frame_selection,
208
+ frame_count=args.frame_count,
209
  raw_budget=args.truncated_budget,
210
  flat_distance_table=args.flat_distance_table,
211
  )
harness/D/symbolic_eval.py CHANGED
@@ -55,12 +55,22 @@ def run(
55
  scene_id = row["scene_name"]
56
  if scene_id not in code_cache:
57
  code, path = spatial_codes.load_spatial_code(scene_id, spatial_code_format)
58
- code_cache[scene_id] = {"adapted": adapters.adapt_spatial_code(code), "path": path}
 
 
 
59
  cached = code_cache[scene_id]
60
- answer = solver.answer(row["question_type"], row["question"], row["options"], cached["adapted"])
 
 
61
  pred_str = "" if answer is None else str(answer)
62
- doc = {"question_type": row["question_type"], "ground_truth": row["ground_truth"]}
63
- score_doc = vsi_official_eval.vsibench_process_results(doc, [pred_str])["vsibench_score"]
 
 
 
 
 
64
  _metric_name, score = _scalar_score(row["question_type"], score_doc)
65
  record = {
66
  "scene": scene_id,
@@ -98,12 +108,15 @@ def main():
98
  parser.add_argument("scene", nargs="?")
99
  parser.add_argument("--scenes", help="comma-separated scenes")
100
  parser.add_argument(
101
- "--spatial-code-format", default=DEFAULT_SPATIAL_CODE_FORMAT,
102
- choices=SPATIAL_CODE_FORMATS, dest="spatial_code_format",
 
 
103
  )
104
  parser.add_argument("--limit", type=int, default=None)
105
  parser.add_argument(
106
- "--results-dir", default=None,
 
107
  help="override the default results/symbolic/ground truth/<format> root",
108
  )
109
  parser.add_argument("--no-write", action="store_true")
@@ -112,7 +125,9 @@ def main():
112
  parser.error("positional scene and --scenes cannot be used together")
113
  selected = None
114
  if args.scenes:
115
- selected = list(dict.fromkeys(s.strip() for s in args.scenes.split(",") if s.strip()))
 
 
116
 
117
  results = run(
118
  spatial_code_format=args.spatial_code_format,
 
55
  scene_id = row["scene_name"]
56
  if scene_id not in code_cache:
57
  code, path = spatial_codes.load_spatial_code(scene_id, spatial_code_format)
58
+ code_cache[scene_id] = {
59
+ "adapted": adapters.adapt_spatial_code(code),
60
+ "path": path,
61
+ }
62
  cached = code_cache[scene_id]
63
+ answer = solver.answer(
64
+ row["question_type"], row["question"], row["options"], cached["adapted"]
65
+ )
66
  pred_str = "" if answer is None else str(answer)
67
+ doc = {
68
+ "question_type": row["question_type"],
69
+ "ground_truth": row["ground_truth"],
70
+ }
71
+ score_doc = vsi_official_eval.vsibench_process_results(doc, [pred_str])[
72
+ "vsibench_score"
73
+ ]
74
  _metric_name, score = _scalar_score(row["question_type"], score_doc)
75
  record = {
76
  "scene": scene_id,
 
108
  parser.add_argument("scene", nargs="?")
109
  parser.add_argument("--scenes", help="comma-separated scenes")
110
  parser.add_argument(
111
+ "--spatial-code-format",
112
+ default=DEFAULT_SPATIAL_CODE_FORMAT,
113
+ choices=SPATIAL_CODE_FORMATS,
114
+ dest="spatial_code_format",
115
  )
116
  parser.add_argument("--limit", type=int, default=None)
117
  parser.add_argument(
118
+ "--results-dir",
119
+ default=None,
120
  help="override the default results/symbolic/ground truth/<format> root",
121
  )
122
  parser.add_argument("--no-write", action="store_true")
 
125
  parser.error("positional scene and --scenes cannot be used together")
126
  selected = None
127
  if args.scenes:
128
+ selected = list(
129
+ dict.fromkeys(s.strip() for s in args.scenes.split(",") if s.strip())
130
+ )
131
 
132
  results = run(
133
  spatial_code_format=args.spatial_code_format,
harness/E/__init__.py CHANGED
@@ -28,6 +28,4 @@ from harness.A import (
28
  )
29
 
30
  # One JSON per question: results/E/<model>/<protocol>/<scene>/<question_id>.json
31
- RESULTS_DIR = Path(
32
- os.environ.get("VSI_HARNESS_E_RESULTS_DIR", "/root/results/E")
33
- )
 
28
  )
29
 
30
  # One JSON per question: results/E/<model>/<protocol>/<scene>/<question_id>.json
31
+ RESULTS_DIR = Path(os.environ.get("VSI_HARNESS_E_RESULTS_DIR", "/root/results/E"))
 
 
harness/E/__pycache__/__init__.cpython-311.pyc CHANGED
Binary files a/harness/E/__pycache__/__init__.cpython-311.pyc and b/harness/E/__pycache__/__init__.cpython-311.pyc differ
 
harness/E/__pycache__/launch.cpython-311.pyc CHANGED
Binary files a/harness/E/__pycache__/launch.cpython-311.pyc and b/harness/E/__pycache__/launch.cpython-311.pyc differ
 
harness/E/__pycache__/prompts.cpython-311.pyc CHANGED
Binary files a/harness/E/__pycache__/prompts.cpython-311.pyc and b/harness/E/__pycache__/prompts.cpython-311.pyc differ
 
harness/E/__pycache__/run.cpython-311.pyc CHANGED
Binary files a/harness/E/__pycache__/run.cpython-311.pyc and b/harness/E/__pycache__/run.cpython-311.pyc differ
 
harness/E/__pycache__/sweep.cpython-311.pyc CHANGED
Binary files a/harness/E/__pycache__/sweep.cpython-311.pyc and b/harness/E/__pycache__/sweep.cpython-311.pyc differ
 
harness/E/launch.py CHANGED
@@ -35,8 +35,17 @@ def _load_run_module():
35
  return module
36
 
37
 
38
- def _worker(tasks, results, model, results_dir, gpu, cpu_threads, extended,
39
- reasoning_budget, force_budget):
 
 
 
 
 
 
 
 
 
40
  if gpu is not None:
41
  os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu)
42
  for variable in ("OMP_NUM_THREADS", "MKL_NUM_THREADS", "OPENBLAS_NUM_THREADS"):
@@ -77,8 +86,13 @@ def _worker(tasks, results, model, results_dir, gpu, cpu_threads, extended,
77
 
78
 
79
  def launch(
80
- model, selected, results_dir=None, rebuild=False, extended=False,
81
- reasoning_budget=EXTENDED_MAX_NEW_TOKENS, force_budget=MAX_NEW_TOKENS,
 
 
 
 
 
82
  ):
83
  """Answer every question for ``selected`` scenes, sharded across every visible GPU."""
84
  protocol = f"{reasoning_budget}" if extended else "base"
@@ -89,10 +103,17 @@ def launch(
89
  completed = 0
90
  for scene in selected:
91
  rows = run.load_questions(scene=scene)
 
 
 
 
92
  answered = all((root / scene / f"{row['id']}.json").is_file() for row in rows)
93
  if answered and not rebuild:
94
  completed += 1
95
- print(f"[{condition} {completed}/{len(selected)}] {scene}: skipped", flush=True)
 
 
 
96
  else:
97
  pending.append(scene)
98
  if not pending:
@@ -120,8 +141,15 @@ def launch(
120
  context.Process(
121
  target=_worker,
122
  args=(
123
- tasks, results, model, results_dir, gpu, cpu_threads, extended,
124
- reasoning_budget, force_budget,
 
 
 
 
 
 
 
125
  ),
126
  )
127
  for gpu in assignments
@@ -152,13 +180,15 @@ def main():
152
  parser = argparse.ArgumentParser()
153
  parser.add_argument("scene", nargs="?")
154
  parser.add_argument(
155
- "--scenes", help="comma-separated scenes (cannot be combined with positional scene)"
 
156
  )
157
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
158
  parser.add_argument("--results-dir", default=None)
159
  parser.add_argument("--rebuild", action="store_true")
160
  parser.add_argument(
161
- "--extended", action="store_true",
 
162
  help="use the extended 2048-token protocol instead of the fixed 16-token default",
163
  )
164
  parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
@@ -178,8 +208,12 @@ def main():
178
  if args.force_budget < 1:
179
  parser.error("--force-budget must be positive")
180
  launch(
181
- args.model, selected, results_dir=args.results_dir, rebuild=args.rebuild,
182
- extended=args.extended, reasoning_budget=args.reasoning_budget,
 
 
 
 
183
  force_budget=args.force_budget,
184
  )
185
 
 
35
  return module
36
 
37
 
38
+ def _worker(
39
+ tasks,
40
+ results,
41
+ model,
42
+ results_dir,
43
+ gpu,
44
+ cpu_threads,
45
+ extended,
46
+ reasoning_budget,
47
+ force_budget,
48
+ ):
49
  if gpu is not None:
50
  os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu)
51
  for variable in ("OMP_NUM_THREADS", "MKL_NUM_THREADS", "OPENBLAS_NUM_THREADS"):
 
86
 
87
 
88
  def launch(
89
+ model,
90
+ selected,
91
+ results_dir=None,
92
+ rebuild=False,
93
+ extended=False,
94
+ reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
95
+ force_budget=MAX_NEW_TOKENS,
96
  ):
97
  """Answer every question for ``selected`` scenes, sharded across every visible GPU."""
98
  protocol = f"{reasoning_budget}" if extended else "base"
 
103
  completed = 0
104
  for scene in selected:
105
  rows = run.load_questions(scene=scene)
106
+ if not rows:
107
+ raise ValueError(
108
+ f"no questions found for scene {scene!r}; check the manifest/scene selection"
109
+ )
110
  answered = all((root / scene / f"{row['id']}.json").is_file() for row in rows)
111
  if answered and not rebuild:
112
  completed += 1
113
+ print(
114
+ f"[{condition} {completed}/{len(selected)}] {scene}: skipped",
115
+ flush=True,
116
+ )
117
  else:
118
  pending.append(scene)
119
  if not pending:
 
141
  context.Process(
142
  target=_worker,
143
  args=(
144
+ tasks,
145
+ results,
146
+ model,
147
+ results_dir,
148
+ gpu,
149
+ cpu_threads,
150
+ extended,
151
+ reasoning_budget,
152
+ force_budget,
153
  ),
154
  )
155
  for gpu in assignments
 
180
  parser = argparse.ArgumentParser()
181
  parser.add_argument("scene", nargs="?")
182
  parser.add_argument(
183
+ "--scenes",
184
+ help="comma-separated scenes (cannot be combined with positional scene)",
185
  )
186
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
187
  parser.add_argument("--results-dir", default=None)
188
  parser.add_argument("--rebuild", action="store_true")
189
  parser.add_argument(
190
+ "--extended",
191
+ action="store_true",
192
  help="use the extended 2048-token protocol instead of the fixed 16-token default",
193
  )
194
  parser.add_argument("--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS)
 
208
  if args.force_budget < 1:
209
  parser.error("--force-budget must be positive")
210
  launch(
211
+ args.model,
212
+ selected,
213
+ results_dir=args.results_dir,
214
+ rebuild=args.rebuild,
215
+ extended=args.extended,
216
+ reasoning_budget=args.reasoning_budget,
217
  force_budget=args.force_budget,
218
  )
219
 
harness/E/prompts.py CHANGED
@@ -9,7 +9,12 @@ plus the same post-prompt every other harness uses for that question type.
9
 
10
  from __future__ import annotations
11
 
12
- from harness.A.prompts import MCA_POST_PROMPT, MCA_QUESTION_TYPES, NA_POST_PROMPT, NA_QUESTION_TYPES
 
 
 
 
 
13
 
14
 
15
  def build_prompt(question_type, question, options=None):
 
9
 
10
  from __future__ import annotations
11
 
12
+ from harness.A.prompts import (
13
+ MCA_POST_PROMPT,
14
+ MCA_QUESTION_TYPES,
15
+ NA_POST_PROMPT,
16
+ NA_QUESTION_TYPES,
17
+ )
18
 
19
 
20
  def build_prompt(question_type, question, options=None):
harness/E/run.py CHANGED
@@ -74,10 +74,20 @@ def _build_record(row, prompt, answer, metric_name, score, model, model_path, pr
74
 
75
 
76
  def write_question_result(
77
- row, prompt, answer, metric_name, score, model, model_path, protocol, results_dir=None
 
 
 
 
 
 
 
 
78
  ):
79
  """Write one question's full, untruncated result record. Return (path, record)."""
80
- record = _build_record(row, prompt, answer, metric_name, score, model, model_path, protocol)
 
 
81
  root = results_dir_for(model, protocol, results_dir)
82
  scene_dir = root / record["scene"]
83
  scene_dir.mkdir(parents=True, exist_ok=True)
@@ -128,25 +138,45 @@ def run(
128
  )
129
  answer = (
130
  adapter.answer_extended(
131
- [], prompt, reasoning_budget=reasoning_budget, force_budget=force_budget
 
 
 
132
  )
133
  if extended
134
  else adapter.answer([], prompt)
135
  )
136
- doc = {"question_type": row["question_type"], "ground_truth": row["ground_truth"]}
 
 
 
137
  score_doc = vsi_official_eval.vsibench_process_results(
138
  doc, [answer["answer_text"]]
139
  )["vsibench_score"]
140
  metric_name, score = _scalar_score(row["question_type"], score_doc)
141
  if write_results:
142
  path, record = write_question_result(
143
- row, prompt, answer, metric_name, score, model, adapter.model_path,
144
- protocol, results_dir,
 
 
 
 
 
 
 
145
  )
146
  else:
147
  path = None
148
  record = _build_record(
149
- row, prompt, answer, metric_name, score, model, adapter.model_path, protocol
 
 
 
 
 
 
 
150
  )
151
  record["result_path"] = str(path) if path else None
152
  results.append(record)
@@ -160,18 +190,23 @@ def main():
160
  parser = argparse.ArgumentParser()
161
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
162
  parser.add_argument("--scene", default=None, help="restrict to one VSI-Bench scene")
163
- parser.add_argument("--limit", type=int, default=None, help="cap the number of questions")
 
 
164
  parser.add_argument("--device", default="cuda")
165
  parser.add_argument(
166
- "--results-dir", default=None,
 
167
  help="override the default results/E/<model>/<protocol> root",
168
  )
169
  parser.add_argument(
170
- "--no-write", action="store_true",
 
171
  help="skip writing per-question JSON files; print/score only",
172
  )
173
  parser.add_argument(
174
- "--extended", action="store_true",
 
175
  help=(
176
  f"use a {EXTENDED_MAX_NEW_TOKENS}-token reasoning budget instead of the fixed "
177
  f"{MAX_NEW_TOKENS}-token VSI-Bench protocol, with a short forced second call "
 
74
 
75
 
76
  def write_question_result(
77
+ row,
78
+ prompt,
79
+ answer,
80
+ metric_name,
81
+ score,
82
+ model,
83
+ model_path,
84
+ protocol,
85
+ results_dir=None,
86
  ):
87
  """Write one question's full, untruncated result record. Return (path, record)."""
88
+ record = _build_record(
89
+ row, prompt, answer, metric_name, score, model, model_path, protocol
90
+ )
91
  root = results_dir_for(model, protocol, results_dir)
92
  scene_dir = root / record["scene"]
93
  scene_dir.mkdir(parents=True, exist_ok=True)
 
138
  )
139
  answer = (
140
  adapter.answer_extended(
141
+ [],
142
+ prompt,
143
+ reasoning_budget=reasoning_budget,
144
+ force_budget=force_budget,
145
  )
146
  if extended
147
  else adapter.answer([], prompt)
148
  )
149
+ doc = {
150
+ "question_type": row["question_type"],
151
+ "ground_truth": row["ground_truth"],
152
+ }
153
  score_doc = vsi_official_eval.vsibench_process_results(
154
  doc, [answer["answer_text"]]
155
  )["vsibench_score"]
156
  metric_name, score = _scalar_score(row["question_type"], score_doc)
157
  if write_results:
158
  path, record = write_question_result(
159
+ row,
160
+ prompt,
161
+ answer,
162
+ metric_name,
163
+ score,
164
+ model,
165
+ adapter.model_path,
166
+ protocol,
167
+ results_dir,
168
  )
169
  else:
170
  path = None
171
  record = _build_record(
172
+ row,
173
+ prompt,
174
+ answer,
175
+ metric_name,
176
+ score,
177
+ model,
178
+ adapter.model_path,
179
+ protocol,
180
  )
181
  record["result_path"] = str(path) if path else None
182
  results.append(record)
 
190
  parser = argparse.ArgumentParser()
191
  parser.add_argument("--model", required=True, choices=vlm_models.available_models())
192
  parser.add_argument("--scene", default=None, help="restrict to one VSI-Bench scene")
193
+ parser.add_argument(
194
+ "--limit", type=int, default=None, help="cap the number of questions"
195
+ )
196
  parser.add_argument("--device", default="cuda")
197
  parser.add_argument(
198
+ "--results-dir",
199
+ default=None,
200
  help="override the default results/E/<model>/<protocol> root",
201
  )
202
  parser.add_argument(
203
+ "--no-write",
204
+ action="store_true",
205
  help="skip writing per-question JSON files; print/score only",
206
  )
207
  parser.add_argument(
208
+ "--extended",
209
+ action="store_true",
210
  help=(
211
  f"use a {EXTENDED_MAX_NEW_TOKENS}-token reasoning budget instead of the fixed "
212
  f"{MAX_NEW_TOKENS}-token VSI-Bench protocol, with a short forced second call "
harness/E/sweep.py CHANGED
@@ -23,7 +23,11 @@ from harness.E import launch as harness_launch # noqa: E402
23
 
24
 
25
  def sweep(
26
- models, selected_scenes, results_dir=None, rebuild=False, extended=False,
 
 
 
 
27
  reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
28
  ):
29
  """Run every model across all visible GPUs."""
@@ -31,8 +35,12 @@ def sweep(
31
  for index, model in enumerate(models, start=1):
32
  print(f"=== sweep {index}/{len(models)}: {model}/{protocol} ===", flush=True)
33
  harness_launch.launch(
34
- model, selected_scenes, results_dir=results_dir, rebuild=rebuild,
35
- extended=extended, reasoning_budget=reasoning_budget,
 
 
 
 
36
  )
37
 
38
 
@@ -40,21 +48,26 @@ def main():
40
  parser = argparse.ArgumentParser()
41
  parser.add_argument("scene", nargs="?")
42
  parser.add_argument(
43
- "--scenes", help="comma-separated scenes (cannot be combined with positional scene)"
 
44
  )
45
  parser.add_argument(
46
- "--models", required=True,
 
47
  help=f"comma-separated models (or 'all'); one of {vlm_models.available_models()}",
48
  )
49
  parser.add_argument("--results-dir", default=None)
50
  parser.add_argument("--rebuild", action="store_true")
51
  parser.add_argument(
52
- "--extended", action="store_true",
 
53
  help="run the whole sweep under the extended protocol instead of the fixed "
54
  "16-token default",
55
  )
56
  parser.add_argument(
57
- "--reasoning-budget", type=int, default=EXTENDED_MAX_NEW_TOKENS,
 
 
58
  dest="reasoning_budget",
59
  help="extended-protocol first-pass budget (the calibrated value from "
60
  "analysis/preregistration.md, e.g. 512)",
@@ -64,7 +77,9 @@ def main():
64
  parser.error("positional scene and --scenes cannot be used together")
65
 
66
  try:
67
- models = _parse_csv_choice(args.models, vlm_models.available_models(), "--models")
 
 
68
  except ValueError as exc:
69
  parser.error(str(exc))
70
 
@@ -79,8 +94,12 @@ def main():
79
  selected = [args.scene] if args.scene else scenes()
80
 
81
  sweep(
82
- models, selected, results_dir=args.results_dir, rebuild=args.rebuild,
83
- extended=args.extended, reasoning_budget=args.reasoning_budget,
 
 
 
 
84
  )
85
 
86
 
 
23
 
24
 
25
  def sweep(
26
+ models,
27
+ selected_scenes,
28
+ results_dir=None,
29
+ rebuild=False,
30
+ extended=False,
31
  reasoning_budget=EXTENDED_MAX_NEW_TOKENS,
32
  ):
33
  """Run every model across all visible GPUs."""
 
35
  for index, model in enumerate(models, start=1):
36
  print(f"=== sweep {index}/{len(models)}: {model}/{protocol} ===", flush=True)
37
  harness_launch.launch(
38
+ model,
39
+ selected_scenes,
40
+ results_dir=results_dir,
41
+ rebuild=rebuild,
42
+ extended=extended,
43
+ reasoning_budget=reasoning_budget,
44
  )
45
 
46
 
 
48
  parser = argparse.ArgumentParser()
49
  parser.add_argument("scene", nargs="?")
50
  parser.add_argument(
51
+ "--scenes",
52
+ help="comma-separated scenes (cannot be combined with positional scene)",
53
  )
54
  parser.add_argument(
55
+ "--models",
56
+ required=True,
57
  help=f"comma-separated models (or 'all'); one of {vlm_models.available_models()}",
58
  )
59
  parser.add_argument("--results-dir", default=None)
60
  parser.add_argument("--rebuild", action="store_true")
61
  parser.add_argument(
62
+ "--extended",
63
+ action="store_true",
64
  help="run the whole sweep under the extended protocol instead of the fixed "
65
  "16-token default",
66
  )
67
  parser.add_argument(
68
+ "--reasoning-budget",
69
+ type=int,
70
+ default=EXTENDED_MAX_NEW_TOKENS,
71
  dest="reasoning_budget",
72
  help="extended-protocol first-pass budget (the calibrated value from "
73
  "analysis/preregistration.md, e.g. 512)",
 
77
  parser.error("positional scene and --scenes cannot be used together")
78
 
79
  try:
80
+ models = _parse_csv_choice(
81
+ args.models, vlm_models.available_models(), "--models"
82
+ )
83
  except ValueError as exc:
84
  parser.error(str(exc))
85
 
 
94
  selected = [args.scene] if args.scene else scenes()
95
 
96
  sweep(
97
+ models,
98
+ selected,
99
+ results_dir=args.results_dir,
100
+ rebuild=args.rebuild,
101
+ extended=args.extended,
102
+ reasoning_budget=args.reasoning_budget,
103
  )
104
 
105
 
harness/F/__init__.py CHANGED
@@ -1,4 +1,5 @@
1
  """Harness F: deterministic symbolic reasoning over perceived or ground-truth spatial codes."""
 
2
  from pathlib import Path
3
  import os
4
 
 
1
  """Harness F: deterministic symbolic reasoning over perceived or ground-truth spatial codes."""
2
+
3
  from pathlib import Path
4
  import os
5
 
harness/F/__pycache__/__init__.cpython-311.pyc CHANGED
Binary files a/harness/F/__pycache__/__init__.cpython-311.pyc and b/harness/F/__pycache__/__init__.cpython-311.pyc differ
 
harness/F/__pycache__/launch.cpython-311.pyc CHANGED
Binary files a/harness/F/__pycache__/launch.cpython-311.pyc and b/harness/F/__pycache__/launch.cpython-311.pyc differ