Buckets:
| """Fail-closed offline/real-judge gates before any paid model computation.""" | |
| from __future__ import annotations | |
| import argparse | |
| import asyncio | |
| from concurrent.futures import ThreadPoolExecutor | |
| import hashlib | |
| import importlib.metadata | |
| import inspect | |
| import json | |
| import os | |
| from pathlib import Path | |
| import subprocess | |
| import sys | |
| import time | |
| from api_transport import atomic | |
| from component_core import build_candidates, sha, verify_uniform_mask_default | |
| from gpu_pool import JudgePool, gpu_state | |
| def digest(path): | |
| return hashlib.sha256(Path(path).read_bytes()).hexdigest() | |
| def cpu(root): | |
| env = os.environ.copy() | |
| env['CUDA_VISIBLE_DEVICES'] = '' | |
| env['PYTHONPATH'] = str(root / 'code') + ':' + str(root / 'source') | |
| env['KERNEL_TEST_RESULT_PATH'] = str(root / 'control/cpu_tests.json') | |
| env.pop('TTT_ALLOW_PAID_KERNEL_API10', None) | |
| with (root / 'control/cpu_tests.log').open('w') as out: | |
| result = subprocess.run([sys.executable, str(root / 'code/test_offline.py')], cwd=root, env=env, | |
| stdout=out, stderr=subprocess.STDOUT) | |
| if result.returncode: | |
| raise RuntimeError('Offline tests failed; inspect control/cpu_tests.log; no API computation was submitted') | |
| check = json.loads((root / 'control/cpu_tests.json').read_text()) | |
| if not check['success'] or check['cuda_initialized'] or check['actual_paid_api_calls']: | |
| raise RuntimeError('Offline-test invariants failed') | |
| print('CPU_PREFLIGHT', json.dumps(check), flush=True) | |
| def gpu(root): | |
| pool = JudgePool(root, gpus=(0, 1, 2, 3)) | |
| preparation = json.loads((root / 'control/preparation.json').read_text()) | |
| original = json.loads(Path(preparation['shared_step0_path']).read_text()) | |
| if original['policy_updates'] != 0 or original['task'] != 'trimul' or digest(preparation['shared_step0_path']) != preparation['shared_step0_sha256']: | |
| raise RuntimeError('Step-0 provenance is not the declared untrained program boundary') | |
| row = original['best_candidate'] | |
| fixed, edits = verify_uniform_mask_default(row['code']) | |
| record = dict(original_root_sha256=sha(row['code']), execution_root_sha256=sha(fixed), | |
| source_file_sha256=preparation['shared_step0_sha256'], mask_default_literal_edits=edits, | |
| adaptation='Uniform default nomask=False, matching prior true-mask validation; no algorithm/constant optimization.', | |
| imported_policy_weights=False, imported_optimizer=False, original_policy_updates=0) | |
| raw_library = root.parent / 'fcfw-kernel-component-joint-official-20261021-v1/programs' | |
| sources = [('step0_root', fixed)] | |
| for name in ['historical_best', 'change_A_only', 'change_B_only']: | |
| code, _ = verify_uniform_mask_default((raw_library / (name + '.py')).read_text()) | |
| sources.append((name, code)) | |
| with ThreadPoolExecutor(max_workers=4) as executor: | |
| futures = [(label, code, executor.submit(pool.evaluate, code, key='preflight/' + label)) for label, code in sources] | |
| results = [(label, code, future.result()) for label, code, future in futures] | |
| for label, code, result in results: | |
| if result['correctness'] != 1 or len(result.get('boolean_checks', [])) != 25 or not all(c['valid'] for c in result['boolean_checks']): | |
| raise RuntimeError('Preflight control did not pass the true-mask/full official judge: ' + label) | |
| root_result = results[0][2] | |
| if not root_result.get('component_profile', {}).get('complete'): | |
| raise RuntimeError('The imported Step-0 root has no usable observed contraction boundary') | |
| root_row = {**row, 'code': fixed, 'value': -root_result['score_us']} | |
| atomic(root / 'control/validated_root.json', dict(root=root_row, profile=root_result['component_profile'], | |
| provenance=record, judge=root_result)) | |
| parent = dict(id='preflight_parent', code=results[1][1], profile=results[1][2]['component_profile'], score_us=results[1][2]['score_us']) | |
| children = [dict(id='preflight_' + label, code=code, profile=result['component_profile'], score_us=result['score_us']) | |
| for label, code, result in results[2:]] | |
| candidates, audit = build_candidates(parent, children, per_side=2) | |
| atomic(root / 'control/replay_assembly_audit.json', audit) | |
| if not candidates: | |
| raise RuntimeError('The real archived replay produced no component candidates') | |
| screened = pool.screen([dict(label='control', code=parent['code']), *candidates], key='preflight/joint_screen') | |
| if not next(r for r in screened['results'] if r['label'] == 'control')['valid']: | |
| raise RuntimeError('Replay screening control failed') | |
| winners = sorted([r for r in screened['results'] if r['valid'] and r['label'] != 'control'], key=lambda r: r['geometric_us']) | |
| if not winners: | |
| raise RuntimeError('No assembled replay candidate passed actual GPU screening') | |
| selected = next(r for r in candidates if r['label'] == winners[0]['label']) | |
| full = pool.evaluate(selected['code'], key='preflight/joint_final') | |
| if not full['correctness'] or len(full.get('boolean_checks', [])) != 25 or not all(c['valid'] for c in full['boolean_checks']): | |
| raise RuntimeError('The assembled replay candidate failed full verification') | |
| recovered = full['score_us'] < min(parent['score_us'], *(c['score_us'] for c in children)) | |
| if not recovered: | |
| atomic(root / 'control/replay_no_gain.json', dict(assembly_audit=audit, final=full, | |
| selected_candidate=selected, screening=screened)) | |
| raise RuntimeError('Known joint-interaction gain was not recovered; do not spend API tokens on a broken component interface') | |
| packet = dict(success=True, paid_api_computation=0, root=root_result, root_adaptation=record, | |
| archived_control_results={label: result for label, _, result in results[1:]}, | |
| replay=dict(assembly_audit=audit, screening=screened, selected_candidate=selected, final=full, | |
| recovered_known_joint_gain=recovered), | |
| proof_scope='Known archived contraction interface and current entry; future incompatible candidates are rejected, not guessed.', | |
| gpus_after=[gpu_state(index) for index in range(4)]) | |
| atomic(root / 'control/gpu_tests.json', packet) | |
| print('GPU_PREFLIGHT_COMPLETE', root_result['score_us'], full['score_us'], flush=True) | |
| def access(root): | |
| from api_transport import make_service | |
| import tinker | |
| if importlib.metadata.version('tinker') != '0.34.0': | |
| raise RuntimeError('SDK version changed') | |
| service = make_service(root, allow_paid=False) | |
| # Read-only capabilities, not a model sample, gradient pass or LoRA creation. | |
| capabilities = service.client.get_server_capabilities() | |
| models = [m.model_name for m in capabilities.supported_models] | |
| if 'openai/gpt-oss-120b' not in models: | |
| raise RuntimeError('Requested baseline model is unavailable') | |
| functions = dict(save_state=inspect.signature(tinker.TrainingClient.save_state_async), | |
| save_sampler=inspect.signature(tinker.TrainingClient.save_weights_for_sampler_async), | |
| sampler=inspect.signature(tinker.TrainingClient.create_sampling_client)) | |
| if 'ttl_seconds' not in functions['save_state'].parameters or 'ttl_seconds' not in functions['save_sampler'].parameters: | |
| raise RuntimeError('Cannot bound checkpoint storage lifetime with this SDK') | |
| atomic(root / 'control/api_access.json', dict(readonly_capabilities_success=True, model='openai/gpt-oss-120b', | |
| sdk='0.34.0', supported_models=len(models), paid_requests=0, | |
| remaining_balance_not_queried=True, checkpoint_ttl_seconds=7 * 86400, | |
| sdk_interfaces={k: str(v) for k, v in functions.items()})) | |
| print('READONLY_API_ACCESS_VERIFIED_NO_MODEL_COMPUTATION', flush=True) | |
| def seal(root): | |
| import torch | |
| from api_transport import Ledger | |
| import integration | |
| from train_api import build_config | |
| cpu_record = json.loads((root / 'control/cpu_tests.json').read_text()) | |
| gpu_record = json.loads((root / 'control/gpu_tests.json').read_text()) | |
| api_record = json.loads((root / 'control/api_access.json').read_text()) | |
| if not cpu_record['success'] or not gpu_record['success'] or not api_record['readonly_capabilities_success']: | |
| raise RuntimeError('Incomplete preparation gates') | |
| if (root / 'run/api_audit/api_requests.jsonl').exists(): | |
| rows = (root / 'run/api_audit/api_requests.jsonl').read_text().strip() | |
| if rows: | |
| raise RuntimeError('Preflight unexpectedly made model computation requests') | |
| baseline = json.loads((root / 'control/preparation.json').read_text()) | |
| for relative, expected in baseline['files'].items(): | |
| if relative.startswith(('source/', 'code/reference/')) and digest(root / relative) != expected: | |
| raise RuntimeError('An original framework/reference helper changed: ' + relative) | |
| integration.configure(root, Ledger(root / 'control/prompt_preflight_audit', enabled=False), gpus=(0,)) | |
| cfg = build_config(root) | |
| from ttt_discover.tinker_utils.misc_utils import get_tokenizer | |
| from ttt_discover.tinker_utils import renderers | |
| tokenizer = get_tokenizer(cfg.local_model_path) | |
| renderer = renderers.get_renderer('gpt_oss_high_reasoning', tokenizer=tokenizer) | |
| state = integration.ComponentTriMulEnv.create_initial_state('trimul') | |
| env = integration.ComponentTriMulEnv(renderer, initial_state=state, sampler=object(), config=cfg.dataset_builder.config) | |
| prompt = renderer.build_generation_prompt([{'role': 'user', 'content': env.get_question()}]) | |
| if prompt.length >= cfg.phase1_max_tokens: | |
| raise RuntimeError('Initial prompt already exceeds the unchanged reasoning budget') | |
| # Exercise the real dataset/sampler factory and logging serialization on a | |
| # throw-away path. Never create real-run parent slots during preflight. | |
| import tempfile | |
| import dataclasses | |
| import chz | |
| from ttt_discover.tinker_utils import ml_log | |
| original_runtime_root = integration.RUNTIME.root | |
| with tempfile.TemporaryDirectory(prefix='startup-', dir=root / 'control') as sandbox: | |
| sandbox_root = Path(sandbox) | |
| (sandbox_root / 'run').mkdir() | |
| integration.RUNTIME.root = sandbox_root | |
| data_config = dataclasses.replace(cfg.dataset_builder.config, log_path=str(sandbox_root / 'run')) | |
| trial_cfg = chz.replace(cfg, log_path=str(sandbox_root / 'run'), | |
| dataset_builder=integration.ComponentDatasetBuilder(config=data_config)) | |
| logger = ml_log.setup_logging(log_dir=str(sandbox_root / 'run'), wandb_project=None, | |
| config=trial_cfg, wandb_name='offline-startup-only') | |
| dataset = asyncio.run(trial_cfg.dataset_builder()) | |
| builders = dataset.get_batch(0) | |
| if len(builders) != 8 or any(b.num_envs != 64 for b in builders): | |
| raise RuntimeError('Real dataset factory did not create eight 64-episode groups') | |
| if len({b.initial_state.id for b in builders}) != 8: | |
| raise RuntimeError('The eight initial single-anchor parent slots were accidentally collapsed') | |
| integration.RUNTIME.root = original_runtime_root | |
| integration.RUNTIME.ledger.logical_step = 0 | |
| if hasattr(logger, 'close'): | |
| logger.close() | |
| files = {str(p.relative_to(root)): digest(p) | |
| for folder in [root / 'code', root / 'source/ttt_discover', root / 'source/examples'] | |
| for p in folder.rglob('*.py')} | |
| for name in ['validated_root.json', 'cpu_tests.json', 'gpu_tests.json', 'api_access.json']: | |
| files['control/' + name] = digest(root / 'control' / name) | |
| packet = dict(ready=True, time=time.time(), files=files, | |
| paid_requests_during_preflight=0, offline_tests=cpu_record['tests'], | |
| GPU_archived_replay_verified=True, root_prompt_tokens=prompt.length, | |
| native_dataset_factory_and_logging_verified=True, | |
| initial_tokenizer_size=len(tokenizer), logical_steps=10, fresh_batches=9, episodes=4608, | |
| dollar_cap=None, no_extra_paid_smoke=True, checkpoint_ttl_seconds=7 * 86400, | |
| unchanged_RL_files=[k for k in files if k.startswith('source/ttt_discover/rl/')], | |
| library='parent_and_its_current_64_siblings_only', external_implementation_injection=False, | |
| cpu_cuda_initialized=torch.cuda.is_initialized()) | |
| if packet['cpu_cuda_initialized']: | |
| raise RuntimeError('The API controller unexpectedly initialized CUDA') | |
| if (root / 'control/ready.json').exists(): | |
| raise FileExistsError('Ready receipt is immutable; do not overwrite it') | |
| atomic(root / 'control/ready.json', packet) | |
| print('READY_WITH_ZERO_PAID_REQUESTS', cpu_record['tests'], prompt.length, flush=True) | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument('--root', type=Path, required=True) | |
| ap.add_argument('--stage', choices=['cpu', 'gpu', 'access', 'seal'], required=True) | |
| args = ap.parse_args() | |
| root = args.root.resolve() | |
| sys.path[:0] = [str(root / 'code'), str(root / 'source')] | |
| if args.stage in ['cpu', 'seal']: | |
| os.environ['CUDA_VISIBLE_DEVICES'] = '' | |
| os.environ.pop('TTT_ALLOW_PAID_KERNEL_API10', None) | |
| globals()[args.stage](root) | |
| if __name__ == '__main__': | |
| main() | |
Xet Storage Details
- Size:
- 13.7 kB
- Xet hash:
- 22bfe2daf1934c2b1812ee5b3fd2350ff39aed5bf3eb59cacf17a8dd9c490dd0
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.