169 lines
11 KiB
Python
169 lines
11 KiB
Python
"""Pure normal-suite cost proposal from externally authenticated parent receipts.
|
|
|
|
No process/file authentication occurs here. Every cycle, process event and full
|
|
output inventory must be bound to a caller-authenticated receipt SHA. Parent
|
|
monotonic stamps cover before-spawn through exit and independent postvalidation;
|
|
worker slot/core timing is never an end-to-end measurement. All clocks within a
|
|
cycle share its clock_id. Context SHA externally binds machine/code/runtime and
|
|
the exact proposed execution/output-retention policy, not merely a GPU model.
|
|
Observed maxima plus explicit reserves are conservative estimates, not guarantees
|
|
for future learning-dependent activity. No fitting, shortening or authorization.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from copy import deepcopy
|
|
import math
|
|
|
|
|
|
SCHEMA = 'conditioning-cost-cycle-v1'
|
|
N, E = 166700, 25582938
|
|
INVENTORY = dict(training_calls=30000, probe_calls=3920, brain_calls=33920,
|
|
steps_per_call=1200, total_steps=40704000, biological_seconds=4070.4,
|
|
original_E_calls=30000, CPU_validator_calls=30000)
|
|
RESERVE_ROLES = {'sampler_input', 'parent_hash', 'final_integrity', 'compiler_warmup', 'unknown_activity'}
|
|
OUTPUT_SCOPE = 'entire_cycle_tree_including_inputs_build_logs_receipts'
|
|
CYCLE_FIELDS = {'schema','cycle_id','kind','diagnostic_mode','steps','neurons','edges','dt_ms',
|
|
'context_sha256','clock_id','started_s','validated_s','authority','events','outputs','complete'}
|
|
EVENT_FIELDS = {'event_id','role','receipt_kind','receipt','spawn_s','exit_s','validated_s',
|
|
'exit_code','core_seconds','runtime_seconds','child_wall_seconds'}
|
|
|
|
|
|
def _require(ok, message):
|
|
if not ok:
|
|
raise ValueError(message)
|
|
|
|
|
|
def _sha(value):
|
|
return type(value) is str and len(value) == 64 and all(c in '0123456789abcdef' for c in value)
|
|
|
|
|
|
def _number(value):
|
|
return type(value) in (int,float) and math.isfinite(value) and value >= 0
|
|
|
|
|
|
def _text(value):
|
|
return type(value) is str and bool(value) and value.strip() == value
|
|
|
|
|
|
def _binding(value, authenticated):
|
|
_require(type(value) is dict and set(value) == {'receipt_id','sha256'} and
|
|
_text(value['receipt_id']) and _sha(value['sha256']) and
|
|
authenticated.get(value['receipt_id']) == value['sha256'], 'Unauthenticated receipt descriptor')
|
|
|
|
|
|
def _measure(row, authenticated, used):
|
|
_require(type(row) is dict and set(row) == CYCLE_FIELDS and row['schema'] == SCHEMA and
|
|
row['complete'] is True, 'Explicit complete authoritative cycle required; no worker-slot adapter')
|
|
_require(_text(row['cycle_id']) and _text(row['clock_id']) and _sha(row['context_sha256']), 'Missing cycle identity/context/clock')
|
|
_binding(row['authority'], authenticated)
|
|
_require(row['kind'] in ('training','probe','state_only_idle') and
|
|
row['diagnostic_mode'] in ('light','reference'), 'Unsupported cycle kind/mode')
|
|
_require(type(row['steps']) is int and row['steps'] > 0 and type(row['neurons']) is int and
|
|
row['neurons'] == N and type(row['edges']) is int and row['edges'] == E and
|
|
type(row['dt_ms']) in (int,float) and row['dt_ms'] == .1, 'Full frozen graph/clock required')
|
|
_require(all(_number(row[k]) for k in ('started_s','validated_s')) and
|
|
row['validated_s'] > row['started_s'], 'Invalid whole-cycle timing')
|
|
events = row['events']
|
|
roles = ['brain','original_E','cpu_validator'] if row['kind'] == 'training' else ['brain']
|
|
_require(type(events) is list and [e.get('role') for e in events if type(e) is dict] == roles,
|
|
'Training requires brain + original E + CPU validator; probes/idle must not update')
|
|
previous, totals = row['started_s'], dict(core_seconds=0.,runtime_seconds=0.,child_wall_seconds=0.)
|
|
measured = {key: True for key in totals}
|
|
receipt_ids = [row['authority']['receipt_id']]
|
|
for event in events:
|
|
_require(type(event) is dict and set(event) == EVENT_FIELDS and _text(event['event_id']) and
|
|
('event',event['event_id']) not in used and event['receipt_kind'] == 'parent-process' and
|
|
type(event['exit_code']) is int and event['exit_code'] == 0, 'Actual successful unique parent process required')
|
|
used.add(('event',event['event_id']))
|
|
_binding(event['receipt'], authenticated)
|
|
receipt_ids.append(event['receipt']['receipt_id'])
|
|
_require(all(_number(event[k]) for k in ('spawn_s','exit_s','validated_s')) and
|
|
previous <= event['spawn_s'] < event['exit_s'] <= event['validated_s'] <= row['validated_s'],
|
|
'Event clock ordering/whole-cycle binding failed')
|
|
previous = event['validated_s']
|
|
child = event['exit_s'] - event['spawn_s']
|
|
_require(_number(event['child_wall_seconds']) and math.isclose(event['child_wall_seconds'],child,rel_tol=1e-12),
|
|
'Child wall must be actual parent spawn-to-exit time')
|
|
upper = child
|
|
for key in ('runtime_seconds','core_seconds'):
|
|
value = event[key]
|
|
if value is not None:
|
|
_require(_number(value) and value <= upper, 'Core/runtime/child timing layers inconsistent')
|
|
upper = value
|
|
for key in totals:
|
|
if event[key] is None:
|
|
measured[key] = False
|
|
else:
|
|
totals[key] += event[key]
|
|
outputs = row['outputs']
|
|
_require(type(outputs) is dict and set(outputs) == {'inventory','scope','complete','total_bytes'} and
|
|
outputs['scope'] == OUTPUT_SCOPE and outputs['complete'] is True and
|
|
type(outputs['total_bytes']) is int and outputs['total_bytes'] > 0, 'Actual complete cycle output inventory required')
|
|
_binding(outputs['inventory'], authenticated)
|
|
receipt_ids.append(outputs['inventory']['receipt_id'])
|
|
_require(len(set(receipt_ids)) == len(receipt_ids), 'Cycle/event/output receipts must have distinct identities')
|
|
_require(not any(('receipt',key) in used for key in receipt_ids), 'Receipt reused across purported independent cycles')
|
|
used.update(('receipt',key) for key in receipt_ids)
|
|
return dict(cycle_id=row['cycle_id'], kind=row['kind'], diagnostic_mode=row['diagnostic_mode'],
|
|
steps=row['steps'], context_sha256=row['context_sha256'],
|
|
timing={**{k: totals[k] if measured[k] else None for k in totals},
|
|
'end_to_end_seconds':row['validated_s']-row['started_s']}, output_bytes=outputs['total_bytes'])
|
|
|
|
|
|
def estimate_normal_suite(cycles, *, authenticated_receipts, target_context_sha256, reserves, limits=None):
|
|
"""Return proposal or INSUFFICIENT-MEASUREMENTS, never permission to execute.
|
|
|
|
reserves requires cycle_multiplier>=1 plus all RESERVE_ROLES, each with
|
|
wall_seconds/output_bytes/basis. Explicit zero is permitted with a stated
|
|
basis (e.g. already included); none are silently assumed zero. limits, when
|
|
supplied, must specify wall_seconds and output_bytes caps for this proposal.
|
|
Only matched-context light complete 1200-tick cycles enter extrapolation.
|
|
"""
|
|
_require(type(cycles) is list and type(authenticated_receipts) is dict and
|
|
all(_text(k) and _sha(v) for k,v in authenticated_receipts.items()) and
|
|
_sha(target_context_sha256), 'Explicit authenticated receipt/context descriptors required')
|
|
_require(type(reserves) is dict and set(reserves) == RESERVE_ROLES | {'cycle_multiplier'} and
|
|
_number(reserves['cycle_multiplier']) and reserves['cycle_multiplier'] >= 1, 'Explicit complete reserves required')
|
|
for role in RESERVE_ROLES:
|
|
reserve = reserves[role]
|
|
_require(type(reserve) is dict and set(reserve) == {'wall_seconds','output_bytes','basis'} and
|
|
_number(reserve['wall_seconds']) and type(reserve['output_bytes']) is int and
|
|
reserve['output_bytes'] >= 0 and _text(reserve['basis']), 'Invalid explicit reserve: '+role)
|
|
if limits is not None:
|
|
_require(type(limits) is dict and set(limits) == {'wall_seconds','output_bytes'} and
|
|
_number(limits['wall_seconds']) and limits['wall_seconds'] > 0 and
|
|
type(limits['output_bytes']) is int and limits['output_bytes'] > 0, 'Invalid resource caps')
|
|
used = set()
|
|
measured = [_measure(row,authenticated_receipts,used) for row in cycles]
|
|
_require(len({r['cycle_id'] for r in measured}) == len(measured), 'Duplicate cycles')
|
|
eligible = {kind:[r for r in measured if r['kind'] == kind and r['diagnostic_mode'] == 'light' and
|
|
r['steps'] == 1200 and r['context_sha256'] == target_context_sha256] for kind in ('training','probe')}
|
|
missing = [kind+' complete matched-context light 1200-tick cycle' for kind,rows in eligible.items() if not rows]
|
|
result = dict(status='INSUFFICIENT-MEASUREMENTS' if missing else 'ESTIMATED-NOT-AUTHORIZED',
|
|
inventory=deepcopy(INVENTORY), measured_cycles=measured, missing=missing,
|
|
eligible_cycle_ids={kind:[r['cycle_id'] for r in rows] for kind,rows in eligible.items()},
|
|
symbolic_wall='cycle_multiplier * (30000 * max(train_end_to_end) + 3920 * max(probe_end_to_end)) + explicit_reserves',
|
|
symbolic_storage='cycle_multiplier * (30000 * max(train_full_bytes) + 3920 * max(probe_full_bytes)) + explicit_reserves',
|
|
estimated_wall_seconds=None, estimated_output_bytes=None, caps=deepcopy(limits), caps_pass=None,
|
|
reserves=deepcopy(reserves), basis='observed maxima; no fitted throughput, amortization or deletion assumptions',
|
|
limitations=['caller authenticates receipt bytes, event identity, complete inventories and execution context',
|
|
'reference and state-only idle are diagnostics only, never light training performance',
|
|
'observed maxima cannot bound unobserved learning-dependent activity or contention',
|
|
'retains every measured cycle output; no assumed cleanup/deduplication/compression gain',
|
|
'reserve coverage and sufficiency remain caller responsibilities; no guarantee'],
|
|
engineering_scope='measurement/interface evidence only, not learning PASS',
|
|
external_identity_verified_here=False, scientific_learning_claimed=False, execution_authorized=False,
|
|
on_limit='STOP; never_reduce_inventory_or_shorten_trials')
|
|
if missing:
|
|
return result
|
|
count = {'training':30000,'probe':3920}
|
|
wall = sum(count[k]*max(r['timing']['end_to_end_seconds'] for r in rows) for k,rows in eligible.items())
|
|
size = sum(count[k]*max(r['output_bytes'] for r in rows) for k,rows in eligible.items())
|
|
result['estimated_wall_seconds'] = math.ceil(reserves['cycle_multiplier']*wall + sum(reserves[k]['wall_seconds'] for k in RESERVE_ROLES))
|
|
result['estimated_output_bytes'] = math.ceil(reserves['cycle_multiplier']*size + sum(reserves[k]['output_bytes'] for k in RESERVE_ROLES))
|
|
if limits is not None:
|
|
result['caps_pass'] = result['estimated_wall_seconds'] <= limits['wall_seconds'] and result['estimated_output_bytes'] <= limits['output_bytes']
|
|
if not result['caps_pass']:
|
|
result['status'] = 'STOP-BUDGET-EXCEEDED'
|
|
return result
|