"""Package the stopped run's measured evidence without contacting training services.""" import ast import hashlib import json import os import subprocess import zipfile from pathlib import Path ROOT = Path(__file__).resolve().parent EXPECTED = 'ce6b64e8bbf72916acd8309c1888a1e3dbf86b3c9ed8e0522e26ee5b5b95b935' def sha(path): return hashlib.sha256(path.read_bytes()).hexdigest() def write_json(name, value): (ROOT / name).write_text(json.dumps(value, indent=2, allow_nan=False) + '\n') def git(directory, *args): return subprocess.check_output(['git', '-C', str(directory), *args], text=True).strip() def main(): assert sha(ROOT / 'launch-instructions.md') == EXPECTED spec = json.loads((ROOT / 'spec.json').read_text()) result = json.loads((ROOT / 'correctness-results.json').read_text()) report = json.loads((ROOT / 'correctness-preflight.json').read_text()) discovery = json.loads((ROOT / 'discovery.json').read_text()) on, packed, stale, stale_packed = result['cases'] assert on['sdpo_gradient']['max_abs_error'] == 0 assert on['grpo_gradient']['max_abs_error'] == 0 assert on['values'] == packed['values'] assert stale['values'] == stale_packed['values'] assert all(c['grpo_loss']['max_abs_error'] == 0 and c['grpo_gradient']['max_abs_error'] == 0 for c in result['cases']) tolerance = spec['correctness_preflight']['paths'][1]['tolerances']['reference_loss'] bound = tolerance['atol'] + tolerance['rtol'] * on['sdpo_loss']['reference_max_abs'] assert on['sdpo_loss']['max_abs_error'] > bound assert result['effective_validation']['status'] == 'failed' assert result['optimizer_updates'] == discovery['optimizer_updates'] == 0 revisions = {} for name, directory in [('tau-bench', ROOT / 'tau-bench'), ('SDPO', ROOT / 'SDPO'), ('tinker-cookbook', ROOT / 'tinker-cookbook'), ('spindle', ROOT / 'spindle'), ('research-exchange-validator', Path('/home/ubuntu/repos/research-exchange'))]: revisions[name] = {'commit': git(directory, 'rev-parse', 'HEAD'), 'dirty': bool(git(directory, 'status', '--porcelain'))} assert not revisions[name]['dirty'] revisions['paper'] = {'url': 'https://arxiv.org/html/2601.20802v2', 'download_sha256': sha(ROOT / 'paper-v2.html'), 'extracted_text_sha256': sha(ROOT / 'paper-v2.txt')} revisions['source_hashes'] = result['source_hashes'] write_json('code-revisions.json', revisions) counts = {} for split in ['train', 'test', 'dev']: path = ROOT / 'tau-bench/tau_bench/envs/retail' / f'tasks_{split}.py' lists = [n.value for n in ast.parse(path.read_text()).body if isinstance(n, ast.Assign) and isinstance(n.value, ast.List)] assert len(lists) == 1 counts[split] = {'available': len(lists[0].elts), 'source_sha256': sha(path)} assert counts['train']['available'] >= 160 and counts['test']['available'] == 115 write_json('dataset-discovery.json', counts) paper = (ROOT / 'paper-v2.txt').read_text() start = paper.index('A.1 Gradient Estimators', paper.index('A.1 Gradient Estimators') + 1) end = paper.index('B Theoretical Analysis', start) notes = ( '# Reference resolution and remaining contract mismatch\n\n' 'Paper: https://arxiv.org/html/2601.20802v2; code: https://github.com/lasgroup/SDPO/tree/' + revisions['SDPO']['commit'] + '\n\n' 'The saved method explicitly selects sampled-token reverse-KL advantages, not the authors YAML defaults ' '(full-logit/top-100+tail distillation, alpha=0.5, EMA teacher). The CPU reference therefore invokes the ' 'authors implemented sampled branch with full_logit_distillation=False, alpha=1, is_clip=None, token-mean. ' 'A second diagnostic uses the authors is_clip=2 option. Neither variant was used for training. ' 'This is not a claim that sampled reverse-KL is the default SDPO recipe.\n\n' 'Let l=current student logprob, o=immutable sampled student logprob, t=teacher logprob, N=masked token count. ' 'Specified IS surrogate: L_IS=-sum(mask*exp(l-o)*detach(t-o))/N. ' 'Authors sampled reverse-KL surrogate: L_ref=sum(mask*detach(l-t)*l)/N. ' 'At l=o their parameter gradients coincide, but raw loss values need not. With stale inputs they can also ' 'have different gradients. This suggests a surrogate/reference acceptance-contract mismatch, not an inactive ' 'treatment or an SDPO-vs-GRPO outcome. All measured gradients cover the complete 5x11 toy policy parameter ' 'matrix, NOT Qwen model parameters.\n\n' 'The authors generic reprompt template appends solution/feedback and asks to correctly solve the original ' 'question. It is preserved in authors-actor.yaml. No tau-bench-specific chat rendering, empty-critique ' 'behavior, real feedback injection, reward mixing, demo threshold, or clipping choice has been certified ' 'for remote training. No unchanged settings were silently replaced.\n\n' 'Exact zero/zero gradients in the disabled-teacher control have null cosine (undefined). The validator ' 'leaves the mandatory min_cosine check unverified. No fabricated cosine=1 is supplied. Pinning the saved ' 'UNRESOLVED revision strings in an effective spec eliminates revision mismatch, but does not eliminate ' 'the measured loss failure or undefined-zero-cosine check.\n\n' 'Cheapest next diagnostic: revise only the correctness contract before spending GPU: explicitly select ' 'the sampled-token variant and an on-policy one-update lag contract; define whether to compare a ' 'source-justified scalar surrogate or a predeclared detached-value alignment, and define zero/zero ' 'gradient acceptance. Rerun the retained CPU fixture. Do not simply raise tolerances. If a stale-input ' 'regime must be equivalent, change/justify the objective explicitly and revalidate all gradients. ' 'Only then probe actual Spindle sampler/trainer logprob alignment, active Adam config and matched init, ' 'followed by the authorized timing and activation pilots. No revised training was executed.\n\n' '## Paper appendix A (plain-text extraction, including math annotation text)\n\n' + paper[start:end] + '\n' ) (ROOT / 'reference-notes.md').write_text(notes) actor = ROOT / 'SDPO/verl/trainer/config/actor/actor.yaml' (ROOT / 'authors-actor.yaml').write_bytes(actor.read_bytes()) distill = ROOT / 'tinker-cookbook/tinker_cookbook/distillation/train_on_policy.py' (ROOT / 'cookbook-distillation-source.py').write_bytes(distill.read_bytes()) write_json('resource-ledger.json', { 'created_training_clients': [], 'created_sampling_clients': [], 'created_modal_apps': [], 'created_modal_sandboxes': [], 'optimizer_updates': 0, 'checkpoint_uris': [], 'cleanup_actions': [], 'reason': 'Only a capability query and local CPU checks ran. No trainer, sampler, fork, app or sandbox was created. Discovery Python process exited; no continuing heartbeat process was launched.', 'gpu_allocation_evidence': None, 'observed_gpu_hours': None, 'shared_service_resources_modified_or_stopped': False, }) report_text = f'''# run_299304ba85 — stopped before training **Status:** failed / incomplete_execution. **Hypothesis:** not tested; no verdict. ## Mandatory gate result The instruction file matched SHA256 `{EXPECTED}` and was read before setup. Spindle advertises both required models. The pinned tau-bench tree has 500 train tasks and exactly 115 test tasks. No training or evaluation was performed. The requested stock-IS token-advantage path and the closest authors-supported sampled reverse-KL branch were checked using a retained deterministic CPU float32 linear-softmax fixture: 4 sequences, 14 masked loss tokens, and the complete 55-parameter gradient. Packed and unpacked layouts agree. This is a necessary-condition diagnostic, **not** a Qwen/Spindle backend correctness certification. | Check | Measurement | Interpretation | |---|---:|---| | GRPO loss/full-gradient maximum error, all four cases | 0 | Local source-level path agrees | | SDPO on-policy configured IS scalar loss | {on['values']['configured_is_loss']:.12g} | Stock-IS surrogate | | SDPO on-policy authors sampled reverse-KL scalar loss | {on['values']['authors_sampled_rkl_loss']:.12g} | Authors surrogate | | SDPO on-policy loss absolute error | {on['sdpo_loss']['max_abs_error']:.12g} | Fails required bound {bound:.12g} | | SDPO on-policy full-gradient maximum error | 0 | Gradients match exactly on this fixture | | SDPO stale-input full-gradient relative L2 error | {stale['sdpo_gradient']['relative_l2_error']:.12g} | Diagnostic only; not measured runtime lag | | SDPO stale-input full-gradient cosine | {stale['sdpo_gradient']['cosine_similarity']:.12g} | Below declared 0.995 floor | The reference branch uses `full_logit_distillation=False`, `alpha=1`, `is_clip=None`, token-mean normalization. The authors default recipe is different (full/top-k logits and alpha=0.5); it was not silently adopted. A separate is_clip=2 diagnostic still has on-policy scalar mismatch and stale-gradient divergence. ## Diagnosis, gaps, and next step This is a **surrogate/reference contract mismatch**, not evidence SDPO underperforms. The IS surrogate and authors sampled reverse-KL surrogate have equal gradients at identical current/sampled logprobs, despite different scalar values. A stale-input perturbation separates gradients too. Exact zero/zero disabled-control gradients also have undefined cosine, so the required cosine check remains unverified; no numeric cosine was invented. The Research Exchange correctness CLI exited 1 with the pinned effective spec. Original-spec placeholder-revision validation is preserved separately. Cheapest next step: obtain a revised correctness contract that explicitly chooses the sampled-token SDPO variant, permitted lag, scalar-surrogate comparison convention, and zero-vector acceptance rule; rerun the retained fixture without relaxing numeric tolerances. If equivalence is required under stale inputs, explicitly revise/justify the objective first. After correctness passes, test actual Spindle logprob alignment, Adam configuration, and matched adapter initialization before activation/timing pilots. Unmeasured: real critique-conditioned advantages, empty/injected-critique behavior, initialization identity, active optimizer family/config, server gradients/precision, activation, representative training/eval timing, checkpoint performance, primary effect and confidence interval. The local Spindle source raises optimizer/introspection questions, but that is not proof about the deployed endpoint. No alternative objective or optimizer was trained. Feasibility remains null rather than fabricated. ## Resource and evidence accounting Training clients: 0. Sampling clients: 0. Optimizer updates: 0. Completed arms: 0. Checkpoints/predictions: none. No run-owned Modal app, fork, or sandbox was created, and no shared deployment was changed or stopped. The capability-query process exited. No measured GPU usage is asserted. The evidence bundle contains exact executed scripts, input/mask fixture, complete toy gradients, extracted pinned reference functions, raw parity/validator output, original and pinned effective specifications, instruction text, source revisions/hashes, dataset counts, reference notes and resource ledger. No outcome predictions or per-item decision rows were manufactured. Lint and Python compilation passed for the diagnostic; mypy reported no issues in both executed scripts (untyped portions are not exhaustively checked). ''' (ROOT / 'run-report.md').write_text(report_text) kinds = { 'launch-instructions.md': 'instructions', 'discover.py': 'script', 'check_correctness.py': 'script', 'build_report.py': 'script', 'reference-extracts.py': 'script', 'spec.json': 'effective_config', 'effective-spec-pinned.json': 'effective_config', 'fixed-fixture.json': 'effective_config', 'authors-actor.yaml': 'effective_config', 'cookbook-distillation-source.py': 'code_revision', 'code-revisions.json': 'code_revision', 'dataset-discovery.json': 'code_revision', 'reference-notes.md': 'code_revision', 'discovery.json': 'metrics', 'correctness-preflight.json': 'metrics', 'correctness-results.json': 'metrics', 'full-gradients.json': 'metrics', 'validator-stdout.json': 'metrics', 'resource-ledger.json': 'metrics', 'run-report.md': 'metrics', } files = [{'name': name, 'kind': kind, 'sha256': sha(ROOT / name), 'content': (ROOT / name).read_text()} for name, kind in kinds.items()] assert len(files) <= 64 and sum(len(f['content'].encode()) for f in files) < 40 * 1024 * 1024 for name in ['TINKER_API_KEY', 'MODAL_PROXY_TOKEN_ID', 'MODAL_PROXY_TOKEN_SECRET', 'RUNS_PROXY_TOKEN_ID', 'RUNS_PROXY_TOKEN_SECRET']: value = os.environ.get(name) if value and len(value) > 7: assert all(value not in f['content'] for f in files), 'Credential safety check failed' final = { 'status': 'failed', 'summary': f'Stopped before training: literal SDPO reference-loss parity failed on a retained CPU fixture ({on["sdpo_loss"]["max_abs_error"]:.6g} error versus {bound:.6g} tolerance), while on-policy full gradients matched. The hypothesis remains untested; resolve the surrogate/lag and zero-gradient acceptance contracts and rerun correctness before any GPU pilot.', 'metrics': {'optimizer_updates': 0, 'created_training_clients': 0, 'completed_comparison_steps': 0, 'correctness_on_policy_sdpo_loss_absolute_error': on['sdpo_loss']['max_abs_error'], 'correctness_on_policy_sdpo_loss_acceptance_bound': bound, 'correctness_on_policy_sdpo_gradient_max_absolute_error': 0, 'correctness_stale_sdpo_gradient_relative_l2_error': stale['sdpo_gradient']['relative_l2_error'], 'correctness_stale_sdpo_gradient_cosine': stale['sdpo_gradient']['cosine_similarity'], 'correctness_cpu_seconds': result['seconds'], 'discovery_seconds': discovery['discovery_seconds']}, 'completed_arms': [], 'outcome_reason': 'incomplete_execution', 'original_hypothesis_tested': False, 'margin': 0.05, 'deviations': [], 'feasibility': None, 'reasoning': 'The specified IS surrogate and the authors sampled reverse-KL surrogate are first-order equivalent on this on-policy fixture but have different scalar values; stale-input gradients also differ. This is a reference/acceptance-contract blocker, not a scientific comparison result. Runtime initialization, optimizer, activation and feasibility remain unverified.', 'tested_instead': 'Offline CPU float32 synthetic linear-softmax fixture with complete 55-parameter gradients, variable-length token masks and packed/unpacked on-policy and stale-input cases; no Qwen rollout or model update.', 'correctness_preflight': report, 'activation_calibration': {'values': {}, 'note': 'No model pilot or calibration training: blocked by prior correctness gate. Synthetic fixed logprobs are not actual critique-conditioned activation evidence.'}, 'evidence': {'version': 1, 'files': files, 'checkpoints': []}, } write_json('structured-result.json', final) write_json('evidence-manifest.json', {'files': [{'name': n, 'sha256': sha(ROOT / n)} for n in [*kinds, 'structured-result.json']]}) with zipfile.ZipFile(ROOT / 'run-evidence.zip', 'w', zipfile.ZIP_DEFLATED) as bundle: for name in [*kinds, 'structured-result.json', 'evidence-manifest.json']: bundle.write(ROOT / name, arcname=name) print('Evidence assembled and checked; instructions hash, diagnostic assertions, credential scan and resource ledger verified.') print('Files:', len(files), 'Bundle bytes:', (ROOT / 'run-evidence.zip').stat().st_size) if __name__ == '__main__': main()