Skip to content

Commit 6298805

Browse files
committed
stack_lab: sign off trinity phase15 parity rows
1 parent 91a2747 commit 6298805

2 files changed

Lines changed: 238 additions & 1 deletion

File tree

examples/trinity_parity_harness/lib/stack_lab/examples/trinity_parity_harness.ex

Lines changed: 162 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ defmodule StackLab.Examples.TRINITYParityHarness do
2828
:deferred_stage_parity
2929
]
3030

31+
@phase15_rows [
32+
:source_inventory,
33+
:task_surface,
34+
:prompt_eval_fixtures,
35+
:no_bypass_fixtures,
36+
:cuda_parity,
37+
:stage_parity,
38+
:python_scripts
39+
]
40+
3141
@all_task_count 17
3242
@coordinator_source_count 60
3343

@@ -38,7 +48,7 @@ defmodule StackLab.Examples.TRINITYParityHarness do
3848

3949
rows =
4050
opts
41-
|> Keyword.get(:rows, @default_rows)
51+
|> selected_rows()
4252
|> Enum.map(&run_row(&1, coordinator_root, framework_root, opts))
4353

4454
status =
@@ -60,6 +70,15 @@ defmodule StackLab.Examples.TRINITYParityHarness do
6070
receipt
6171
end
6272

73+
@spec run!(keyword()) :: Receipt.t()
74+
def run!(opts) do
75+
{:ok, receipt} = run(opts)
76+
receipt
77+
end
78+
79+
@spec phase15_rows() :: [atom()]
80+
def phase15_rows, do: @phase15_rows
81+
6382
defp run_row(:source_inventory, coordinator_root, _framework_root, _opts) do
6483
files =
6584
coordinator_root
@@ -158,6 +177,86 @@ defmodule StackLab.Examples.TRINITYParityHarness do
158177
}
159178
end
160179

180+
defp run_row(:cuda_parity, _coordinator_root, _framework_root, opts) do
181+
phase15_dir = phase15_dir(opts)
182+
old_snapshot = Path.join(phase15_dir, "coordinator_cuda_qwen_router_prompt_eval_logits.json")
183+
new_snapshot = Path.join(phase15_dir, "framework_cuda_qwen_router_prompt_eval_logits.json")
184+
old_log = Path.join(phase15_dir, "coordinator_cuda_qwen_router_prompt_eval.log")
185+
new_log = Path.join(phase15_dir, "framework_cuda_qwen_router_prompt_eval.log")
186+
187+
details = cuda_parity_details(old_snapshot, new_snapshot, old_log, new_log)
188+
status = if details.pass?, do: :pass, else: :open_defect
189+
190+
%Row{
191+
id: :cuda_parity,
192+
description:
193+
"old/new CUDA prompt-eval snapshots pass 37/37 and match decision-stable invariants",
194+
status: status,
195+
details: Map.delete(details, :pass?)
196+
}
197+
end
198+
199+
defp run_row(:stage_parity, _coordinator_root, _framework_root, opts) do
200+
summary_path = Path.join(phase15_dir(opts), "stage_parity_summary.json")
201+
202+
details =
203+
if File.regular?(summary_path) do
204+
summary = summary_path |> File.read!() |> Jason.decode!()
205+
206+
%{
207+
pass?: summary["ok"] == true and summary["exit_status"] == 0,
208+
summary_path: summary_path,
209+
python_report: summary["python_report"],
210+
elixir_report: summary["elixir_report"],
211+
strict_stage_tolerances?: "--strict-stage-tolerances" in summary["comparator_args"]
212+
}
213+
else
214+
%{pass?: false, summary_path: summary_path, reason: :missing_summary}
215+
end
216+
217+
%Row{
218+
id: :stage_parity,
219+
description: "strict Python/Elixir stage tolerance comparator completed successfully",
220+
status: if(details.pass?, do: :pass, else: :open_defect),
221+
details: Map.delete(details, :pass?)
222+
}
223+
end
224+
225+
defp run_row(:python_scripts, coordinator_root, _framework_root, _opts) do
226+
expected = %{
227+
py: [
228+
"compare_sakana_parity_reports.py",
229+
"convert_router_vector_to_safetensors.py",
230+
"debug_sakana_large_tensor_chunks.py",
231+
"debug_sakana_parity_sample.py",
232+
"debug_sakana_router_trace.py",
233+
"export_sakana_trinity_safetensors.py"
234+
],
235+
sh: ["run_expensive_all_selected_decompose.sh", "run_original_submission_svd_weights.sh"],
236+
md: ["SVD_PARITY_DEBUG.md"]
237+
}
238+
239+
script_dir = Path.join(coordinator_root, "priv/sakana_trinity/scripts")
240+
241+
missing =
242+
expected
243+
|> Map.values()
244+
|> List.flatten()
245+
|> Enum.reject(&File.regular?(Path.join(script_dir, &1)))
246+
247+
%Row{
248+
id: :python_scripts,
249+
description: "Sakana Python parity scripts remain preserved as the external reference gate",
250+
status: if(missing == [], do: :pass, else: :open_defect),
251+
details: %{
252+
script_dir: script_dir,
253+
expected: expected,
254+
missing: missing,
255+
preservation: :coordinator_external_reference_until_shim_cutover
256+
}
257+
}
258+
end
259+
161260
defp run_row(:deferred_cuda_parity, _coordinator_root, _framework_root, _opts) do
162261
%Row{
163262
id: :deferred_cuda_parity,
@@ -185,6 +284,68 @@ defmodule StackLab.Examples.TRINITYParityHarness do
185284
}
186285
end
187286

287+
defp selected_rows(opts) do
288+
if Keyword.get(opts, :phase15, false),
289+
do: @phase15_rows,
290+
else: Keyword.get(opts, :rows, @default_rows)
291+
end
292+
293+
defp cuda_parity_details(old_snapshot, new_snapshot, old_log, new_log) do
294+
with {:old_snapshot, true} <- {:old_snapshot, File.regular?(old_snapshot)},
295+
{:new_snapshot, true} <- {:new_snapshot, File.regular?(new_snapshot)},
296+
{:old_log, true} <- {:old_log, File.regular?(old_log)},
297+
{:new_log, true} <- {:new_log, File.regular?(new_log)} do
298+
old_cases = snapshot_cases!(old_snapshot)
299+
new_cases = snapshot_cases!(new_snapshot)
300+
count = length(old_cases)
301+
stable_keys = ~w(id agent_id role_id token_count transcript_hash)
302+
stable_matches = Map.new(stable_keys, &{&1, matching_count(old_cases, new_cases, &1)})
303+
route_hash_matches = matching_count(old_cases, new_cases, "route_hash")
304+
old_log_pass? = qwen_log_pass?(old_log)
305+
new_log_pass? = qwen_log_pass?(new_log)
306+
307+
%{
308+
pass?:
309+
count == 37 and length(new_cases) == 37 and old_log_pass? and new_log_pass? and
310+
Enum.all?(stable_matches, fn {_key, matches} -> matches == 37 end),
311+
old_snapshot: old_snapshot,
312+
new_snapshot: new_snapshot,
313+
old_log: old_log,
314+
new_log: new_log,
315+
old_case_count: count,
316+
new_case_count: length(new_cases),
317+
stable_matches: stable_matches,
318+
route_hash_matches: route_hash_matches,
319+
route_hash_policy: :diagnostic_across_processes
320+
}
321+
else
322+
{missing, false} ->
323+
%{pass?: false, reason: :missing_file, missing: missing}
324+
end
325+
end
326+
327+
defp snapshot_cases!(path) do
328+
path
329+
|> File.read!()
330+
|> Jason.decode!()
331+
|> Map.fetch!("cases")
332+
end
333+
334+
defp matching_count(old_cases, new_cases, key) do
335+
old_cases
336+
|> Enum.zip(new_cases)
337+
|> Enum.count(fn {old_case, new_case} -> Map.get(old_case, key) == Map.get(new_case, key) end)
338+
end
339+
340+
defp qwen_log_pass?(path) do
341+
log = File.read!(path)
342+
343+
String.contains?(log, "passed: 37") and String.contains?(log, "failed: 0") and
344+
String.contains?(log, "PASS qwen_router_prompt_eval")
345+
end
346+
347+
defp phase15_dir(opts), do: Keyword.get(opts, :phase15_dir, "tmp/phase15")
348+
188349
defp mix_help_tasks!(runner, root) do
189350
output = runner.(root, ["help", "--search", "trinity"])
190351

examples/trinity_parity_harness/test/stack_lab/examples/trinity_parity_harness_test.exs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,30 @@ defmodule StackLab.Examples.TRINITYParityHarnessTest do
5959
assert details.old == details.new
6060
end
6161

62+
test "phase 15 CUDA and stage rows sign off generated receipts" do
63+
phase15_dir = write_phase15_receipts!()
64+
65+
assert {:ok, receipt} =
66+
TRINITYParityHarness.run(
67+
rows: [:cuda_parity, :stage_parity],
68+
phase15_dir: phase15_dir
69+
)
70+
71+
assert receipt.status == :pass
72+
73+
assert Enum.map(receipt.rows, &{&1.id, &1.status}) == [
74+
cuda_parity: :pass,
75+
stage_parity: :pass
76+
]
77+
78+
cuda = Enum.find(receipt.rows, &(&1.id == :cuda_parity))
79+
assert cuda.details.stable_matches["agent_id"] == 37
80+
assert cuda.details.route_hash_matches == 0
81+
82+
stage = Enum.find(receipt.rows, &(&1.id == :stage_parity))
83+
assert stage.details.strict_stage_tolerances?
84+
end
85+
6286
test "no-bypass fixtures fail and pass in the intended places" do
6387
results = NoBypassFixtures.run()
6488

@@ -71,4 +95,56 @@ defmodule StackLab.Examples.TRINITYParityHarnessTest do
7195

7296
assert Enum.all?(results, &(&1.status == &1.expected_status))
7397
end
98+
99+
defp write_phase15_receipts! do
100+
root =
101+
Path.join(
102+
System.tmp_dir!(),
103+
"stack_lab_trinity_phase15_#{System.unique_integer([:positive])}"
104+
)
105+
106+
File.mkdir_p!(root)
107+
on_exit(fn -> File.rm_rf(root) end)
108+
109+
old_cases = Enum.map(1..37, &phase15_case(&1, "old-route-#{&1}"))
110+
new_cases = Enum.map(1..37, &phase15_case(&1, "new-route-#{&1}"))
111+
112+
File.write!(
113+
Path.join(root, "coordinator_cuda_qwen_router_prompt_eval_logits.json"),
114+
Jason.encode!(%{cases: old_cases})
115+
)
116+
117+
File.write!(
118+
Path.join(root, "framework_cuda_qwen_router_prompt_eval_logits.json"),
119+
Jason.encode!(%{cases: new_cases})
120+
)
121+
122+
log = "Summary\n passed: 37\n failed: 0\n\nPASS qwen_router_prompt_eval\n"
123+
File.write!(Path.join(root, "coordinator_cuda_qwen_router_prompt_eval.log"), log)
124+
File.write!(Path.join(root, "framework_cuda_qwen_router_prompt_eval.log"), log)
125+
126+
File.write!(
127+
Path.join(root, "stage_parity_summary.json"),
128+
Jason.encode!(%{
129+
ok: true,
130+
exit_status: 0,
131+
python_report: "python.json",
132+
elixir_report: "elixir.json",
133+
comparator_args: ["python.json", "elixir.json", "--strict-stage-tolerances"]
134+
})
135+
)
136+
137+
root
138+
end
139+
140+
defp phase15_case(index, route_hash) do
141+
%{
142+
id: "case-#{index}",
143+
agent_id: rem(index, 7),
144+
role_id: rem(index, 3),
145+
token_count: index + 10,
146+
transcript_hash: "transcript-#{index}",
147+
route_hash: route_hash
148+
}
149+
end
74150
end

0 commit comments

Comments
 (0)