Download code/v2_compiler_costs.py from PureOne/Echo-Mirror-RSI: direct link, hf CLI and curl.
- Browser
- Download file 3.23 kB
-
https://huggingface.co/datasets/PureOne/Echo-Mirror-RSI/resolve/main/code/v2_compiler_costs.py
- Command line
-
hf download hf://datasets/PureOne/Echo-Mirror-RSI/code/v2_compiler_costs.py
-
curl -L -o v2_compiler_costs.py https://huggingface.co/datasets/PureOne/Echo-Mirror-RSI/resolve/main/code/v2_compiler_costs.py
3.23 kB
| """Descriptive setup/update microbenchmark; not an end-to-end RSI speed test.""" | |
| from pathlib import Path | |
| import json | |
| import time | |
| import numpy as np | |
| from v2_gated_program_search import Config, Task, Grammar | |
| def main(): | |
| cfg=Config();task=Task(0,cfg);grammar=Grammar(task) | |
| anchor=task.anchor(task.train[0]);rng=np.random.default_rng(719234) | |
| for i in range(120): | |
| parents=rng.choice(len(grammar.nodes),size=2,replace=True) | |
| params=rng.normal(0,1.2,size=(2,cfg.responses+1)) | |
| grammar.add(parents,params,anchor) | |
| ids=list(range(cfg.primitives,len(grammar.nodes))) | |
| build_times=[] | |
| for _ in range(50): | |
| t=time.perf_counter();task.anchor(task.train[0]);build_times.append(time.perf_counter()-t) | |
| timings={} | |
| for mode in ['minimal','raw_contracted_first_jet','full_field_and_jacobian']: | |
| runs=[] | |
| for _ in range(20): | |
| cache={};values=[];start=time.perf_counter() | |
| for index in ids: | |
| if mode=='minimal':values.append(grammar.signature(index,anchor,cache)) | |
| elif mode=='raw_contracted_first_jet':values.append(grammar.contracted_jet(index,anchor,cache)) | |
| else:values.append(grammar.full_jet(index,anchor,cache)) | |
| runs.append(time.perf_counter()-start) | |
| timings[mode]={'median_seconds':float(np.median(runs)),'all_seconds':runs} | |
| errors=[] | |
| for _ in range(100): | |
| i,j=rng.choice(ids,size=2) | |
| errors.append(abs(grammar.score(i,j,anchor,'minimal')-grammar.score(i,j,anchor,'full_jacobian'))) | |
| result={'status':'Executed small synthetic compiler microbenchmark. Interpret as this Python implementation only.', | |
| 'dimension':cfg.dimension,'primitive_fields':cfg.primitives,'protected_responses':cfg.responses, | |
| 'generated_nodes':len(ids),'maximum_node_depth':max(n['depth'] for n in grammar.nodes), | |
| 'setup_seconds_median':float(np.median(build_times)), | |
| 'update_timings':timings, | |
| 'scalar_cache_per_generated_node':{'skew_quotient':anchor['rank'], | |
| 'raw_contracted_first_jet':cfg.primitives+cfg.responses, | |
| 'full_field_and_jacobian':cfg.dimension+cfg.dimension**2}, | |
| 'shared_primitive_matrix_scalars':int(task.maps.size), | |
| 'shared_compiler_factor_scalars':int(anchor['a'].size+anchor['omega'].size+anchor['ell'].size+anchor['gate'].size), | |
| 'maximum_tested_score_error':max(errors), | |
| 'limits':['Setup assumes supplied exact primitive Jacobians and task gradients.', | |
| 'Per-node scalar counts exclude generated program source, gate parameters, base fields, objective state, shared maps, and the rest of the search algorithm.', | |
| 'The convex program grammar is restricted; rankT is not asserted to be the least possible representation for that restricted grammar.', | |
| 'This is not total training-memory accounting or a hardware-independent speed result.']} | |
| out=Path(__file__).resolve().parents[1]/'results/v2_compiler_costs.json' | |
| out.write_text(json.dumps(result,indent=2)+'\n') | |
| print(json.dumps({k:v for k,v in result.items() if k!='update_timings'},indent=2)) | |
| print({k:v['median_seconds'] for k,v in timings.items()}) | |
| if __name__=='__main__':main() | |