Datasets:
File size: 13,298 Bytes
b1a18a7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | """Frozen, user-authorized 80/23 task final run; native Prime schemas and checks."""
from copy import deepcopy
import hashlib
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parent
MODEL_REVISION = 'c202236235762e1c871ad0ccb60c8ee5ba337b9a'
COMMITS = ('ced9c90b75b5a13263265089091c11dc136dfbfd', 'ed74dad125d77dcc339c6ff07e67cbdb0cc90607')
def digest(value):
return hashlib.sha256(json.dumps(value, sort_keys=True, separators=(',', ':')).encode()).hexdigest()
def freeze():
import tomllib
plan = json.loads((ROOT/'plans/training103-plan.json').read_text())
template = json.loads((ROOT/'calibration/validation11-c64-20261029-01-frozen.json').read_text())
available = [json.loads((ROOT/'calibration'/name).read_text()) for name in
('screening-all116-manifest.json', 'screening-round2-manifest.json')]
train = list(plan['split']['train'])
heldout = list(plan['split']['validation']) + list(plan['split']['test'])
all_manifest = {name: records[name] for records in available for name in train+heldout if name in records}
def sources(names, training=False):
result = []
for index, source in enumerate(template['evaluation']['source']):
selected = [name for name in names if name in available[index]]
if not selected:
continue
item = deepcopy(source)
item['name'] = ('final-train-' if training else 'final-heldout-')+str(index+1)
item['env']['taskset']['tasks'] = selected
item['select'] = {'limit':len(selected), 'shuffle':bool(training)}
if training:
item['select']['seed'] = 42
item['serve']['max_concurrent'] = 128 if training else 64
item['env']['agent']['harness']['env'] = {'VF_BASH_LENGTH_RECOVERY':'1'}
item['env']['interception']['tunnel']['port'] = 8001+len(result)
if training:
item['ratio'] = len(selected)
result.append(item)
return result
config = tomllib.loads((ROOT/'train.toml').read_text())
config.update(max_steps=10, output_dir='/outputs/prime/FINAL', dashboard=False, run={'name':'training'})
config['deployment'].update(gpus_per_node=3, num_train_gpus=1, num_infer_gpus=2)
config['ckpt'] = {'interval':5, 'keep_interval':5}
config['orchestrator'].update(batch_size=64, max_off_policy_steps=1, constant_trainer_batch_size=True,
eval=None, concurrency={key:128 for key in ('initial_inflight','min_inflight','max_inflight')})
config['orchestrator']['train'].update(group_size=8, source=sources(train, training=True))
config['orchestrator']['train']['sampling']['temperature'] = 0.6
config['inference'].update(router=None)
config['inference']['vllm'].update(max_num_seqs=64, tensor_parallel_size=1, data_parallel_size=2, api_server_count=1)
runtime = {name:hashlib.sha256((ROOT/name).read_bytes()).hexdigest()
for name in ('bash_timeout.py','compaction_task.py','bash_recovery.py')}
shards = []
for shard, names in enumerate((heldout[:11], heldout[11:])):
evaluation = deepcopy(template)
evaluation['evaluation'].update(source=sources(names), select={'limit':len(names),'shuffle':False})
evaluation['evaluation']['sampling']['temperature'] = 0.6
evaluation['experiment'].update(purpose='final_heldout', task_count=len(names), total_attempts=len(names)*8,
replicas=1, inference_seeds=[5100+shard], task_git_commits=list(COMMITS),
profile='rl-next', workspace='susindra-turtlelabs', split='merged_heldout', shard=shard)
evaluation['inference'].update(router=None)
evaluation['inference']['vllm'].update(enable_lora=True, max_lora_rank=16, max_num_seqs=64,
data_parallel_size=1, tensor_parallel_size=1)
evaluation['task_manifest'] = {name:all_manifest[name] for name in names}
evaluation['runtime_sha256'] = runtime
evaluation['split_note'] = 'Frozen existing 11+12 heldout tasks; previously examined, not a blind test.'
shards.append(evaluation)
frozen = {'purpose':'final-training-80-23', 'profile':'rl-next', 'workspace':'susindra-turtlelabs',
'training':config, 'train_tasks':train, 'heldout_tasks':heldout, 'task_manifest':all_manifest,
'runtime_sha256':runtime, 'evaluation_shards':shards,
'accepted_trace_target':640, 'post_training_eval_attempts':368,
'watchdog_seconds':32400, 'function_timeout_seconds':33000,
'provenance':{'prime_commit':'9e15490dcab1d506ce3462e69b8aa5dde45c6b3a',
'task_commits':list(COMMITS), 'source_plan_sha256':hashlib.sha256((ROOT/'plans/training103-plan.json').read_bytes()).hexdigest(),
'split_note':'User merged existing validation/test into one 23-task heldout; selection and task bytes unchanged.'}}
validate(frozen)
return frozen
def validate(frozen):
from prime_rl.configs.rl import RLConfig
from prime_rl.configs.eval import EvalConfig
from prime_rl.configs.inference import InferenceConfig
assert frozen['purpose'] == 'final-training-80-23'
assert frozen['profile']=='rl-next' and frozen['workspace']=='susindra-turtlelabs'
train, heldout = frozen['train_tasks'], frozen['heldout_tasks']
assert len(train)==len(set(train))==80 and len(heldout)==len(set(heldout))==23
assert not set(train)&set(heldout) and set(train+heldout)==set(frozen['task_manifest'])
assert frozen['accepted_trace_target']==640 and frozen['post_training_eval_attempts']==368
assert frozen['watchdog_seconds']==32400 and frozen['function_timeout_seconds']==33000
config = frozen['training']
parsed = RLConfig.model_validate(deepcopy(config))
assert parsed.max_steps==10 and parsed.orchestrator.batch_size==64
assert parsed.orchestrator.train.group_size==8 and parsed.orchestrator.eval is None
assert parsed.orchestrator.constant_trainer_batch_size and parsed.orchestrator.max_off_policy_steps==1
assert parsed.orchestrator.concurrency.model_dump()==dict(initial_inflight=128,min_inflight=128,max_inflight=128)
assert parsed.deployment.type=='single_node'
assert (parsed.deployment.gpus_per_node, parsed.deployment.num_train_gpus, parsed.deployment.num_infer_gpus)==(3,1,2)
assert parsed.inference.router is None and parsed.inference.vllm.api_server_count==1
assert (parsed.inference.vllm.data_parallel_size,parsed.inference.vllm.tensor_parallel_size,parsed.inference.vllm.max_num_seqs)==(2,1,64)
assert parsed.trainer.model.compile.model_dump()=={'fullgraph':False,'mode':None}
assert parsed.trainer.model.lora.rank==16 and parsed.trainer.model.lora.alpha==32
assert parsed.trainer.optim.lr==1e-5 and parsed.seq_len==50000
assert config['model']['name']=='Qwen/Qwen3.5-9B' and config['inference']['vllm']['revision']==MODEL_REVISION
assert config['inference']['vllm']['quantization']=='fp8_per_block'
assert config['ckpt']=={'interval':5,'keep_interval':5}
assert parsed.resume is None and parsed.weight_broadcast.type=='filesystem'
sampling=config['orchestrator']['train']['sampling']
assert sampling=={'temperature':0.6,'top_p':0.95,'top_k':20,'max_completion_tokens':8192,
'extra_body':{'min_p':0.0,'chat_template_kwargs':{'enable_thinking':True}}}
assert config['orchestrator']['renderer']['enable_thinking'] is True
selected=[]
for raw, source in zip(config['orchestrator']['train']['source'],parsed.orchestrator.train.source):
names=raw['env']['taskset']['tasks'];selected+=names
assert source.group_size==8 and raw['ratio']==len(names)
assert raw['select']=={'limit':len(names),'shuffle':True,'seed':42}
_validate_source(raw,128)
assert len(selected)==80 and set(selected)==set(train)
shard_names=[]
for shard in frozen['evaluation_shards']:
count=shard['experiment']['task_count']
assert count in (11,12) and shard['experiment']['purpose']=='final_heldout'
assert shard['experiment']['total_attempts']==count*8 and shard['evaluation']['group_size']==8
assert shard['runtime_sha256']==frozen['runtime_sha256']
assert shard['evaluation']['sampling']=={'temperature':0.6,'top_p':0.95,'top_k':20,'min_p':0.0,
'max_tokens':8192,'extra_body':{'chat_template_kwargs':{'enable_thinking':True}}}
assert shard['evaluation']['concurrency']==dict(initial_inflight=64,min_inflight=64,max_inflight=64)
names=[name for source in shard['evaluation']['source'] for name in source['env']['taskset']['tasks']]
assert len(names)==count and set(names)==set(shard['task_manifest'])
assert shard['task_manifest']=={name:frozen['task_manifest'][name] for name in names}
for source in shard['evaluation']['source']:_validate_source(source,64)
EvalConfig.model_validate(deepcopy(shard['evaluation']))
serving=InferenceConfig.model_validate(deepcopy(shard['inference']))
assert serving.router is None and serving.vllm.enable_lora and serving.vllm.max_num_seqs==64
shard_names+=names
assert len(shard_names)==23 and set(shard_names)==set(heldout)
return parsed
def _validate_source(source, capacity):
assert source['env']['taskset']['repo'].rsplit('@',1)[1] in COMMITS
assert source['serve']['max_concurrent']==capacity
agent=source['env']['agent']
assert agent['max_turns']==50
assert agent['harness']=={'id':'bash','edit':True,'search':False,
'compaction':{'summarize_at_tokens':30000},'env':{'VF_BASH_LENGTH_RECOVERY':'1'}}
assert source['env']['retries']['max_retries']==agent['retries']['max_retries']==source['env']['verifier']['retries']==0
def verify_runtime(frozen):
import ast
import importlib.util
import bash_recovery, bash_timeout, compaction_task
for name, expected in frozen['runtime_sha256'].items():
assert hashlib.sha256((Path(bash_recovery.__file__).parent/name).read_bytes()).hexdigest()==expected, name
result=bash_recovery.verify_runtime(frozen['runtime_sha256']['bash_recovery.py'])
core=Path(result['core_path']).read_text()
own=Path(bash_timeout.__file__).read_text()
def executor(text):
a,b=bash_timeout.function_span(text)
return ''.join(text.splitlines(keepends=True)[a:b])
assert executor(core)==executor(own)
compaction=Path(importlib.util.find_spec('verifiers.v1.harnesses.utils.compaction').origin).read_text()
assert compaction_task.patch_source(compaction)==compaction
from verifiers.v1.harnesses.utils.launch import CHAT_PROGRAM_SOURCE
assert 'original_task = next(' in CHAT_PROGRAM_SOURCE and executor(core).strip() in CHAT_PROGRAM_SOURCE
ast.parse(CHAT_PROGRAM_SOURCE)
return result
def audit_evaluation(directory, expected_tasks):
"""Run the official Prime readers in the same Python environment as native eval."""
import subprocess
result=subprocess.run(['/app/.venv/bin/python', '/workspace-smoke/final_training.py',
str(directory), json.dumps(sorted(expected_tasks))],capture_output=True,text=True,timeout=600)
if result.returncode:
raise RuntimeError('Native trace audit failed: '+result.stderr[-8000:])
return json.loads(result.stdout.splitlines()[-1])
def _audit_native(directory, expected_tasks):
"""Cohort assertions only; Prime owns layout, index and compressed record reads."""
import collections
from prime_rl.dashboard import server
from prime_rl.monitors.file.traces.index import summarize_episode
assert hashlib.sha256(Path(server.__file__).read_bytes()).hexdigest() == '51123d837fad119b8fa74fa5592476f561839b40356b4c16545e6d09b6e00d4a'
run=Path(directory)/'evaluation'
stream=server.require_stream(run)
index=server.written_index(run)
expected=len(expected_tasks)*8
assert index is not None and len(index)==len({row['id'] for row in index})==expected
counts=collections.Counter(); stops=collections.Counter(); ids=set()
for row in index:
record=server.read_episode_at(stream,row['line'],(row['chunk'],row['offset']))
summary=summarize_episode(row['line'],record)
assert record['id']==row['id'] and record['id'] not in ids
ids.add(record['id'])
for key in ('kind','ok','num_errors','reward','truncated','timeout','stop_condition'):
assert summary[key]==row[key], (row['id'],key)
assert summary['kind']=='eval' and summary['ok'] and summary['num_errors']==0
assert not summary['timeout'] and summary['reward'] in (0,1)
counts[record['task']['data']['name']]+=1
stops[summary['stop_condition']]+=1
assert counts=={name:8 for name in expected_tasks}
return {'attempts':expected,'task_counts':dict(counts),'passed':sum(row['reward']==1 for row in index),
'errors':0,'timeouts':0,'truncated':sum(bool(row['truncated']) for row in index),
'stop_conditions':dict(stops),'native_index':str(server.stream_index_file(run)),
'reader':'prime_rl.dashboard.server.read_episode_at','native_python':__import__('sys').executable}
if __name__ == '__main__':
import sys
print(json.dumps(_audit_native(sys.argv[1],json.loads(sys.argv[2]))))
|