okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
407ea8192
main
1"""Opt-in Windows direct API trials. Never loads a model, edits config, or runs tools.""" 2import argparse 3import json 4import os 5import time 6from pathlib import Path 7import benchmark as b 8 9QUOTE = 'An office quote includes four visits at $120 each, three floor jobs at $85 each, and $45 materials. Apply 10% discount to the subtotal then 13% tax. Return only JSON with numeric subtotal, discounted, tax and total.' 10VALIDATION = 'Accept only JSON numbers which are finite and nonnegative (zero is valid); reject null, strings and negatives. Classify [0, null, "4", -2, 1.5, 3]. Return only JSON with arrays accepted and rejected, preserving their relative order.' 11TOOL_PROMPT = 'Use the read_file tool to inspect package.json before suggesting a test command. Do not guess its contents. Call the tool exactly once; no other actions.' 12TOOLS = [{'type' :'function' ,'function' : {'name' :'read_file' ,'description' :'Read a file in the current project' ,'parameters' : {'type' :'object' ,'properties' : {'path' : {'type' :'string' }},'required' : ['path' ],'additionalProperties' :False }}}] 13 14 15def recall (n ): 16filler = 'This is irrelevant background about routine office cleaning schedules. Ignore it when extracting marked keys.\n' 17return 'START_KEY=CLENEX-4181\n' + filler * n + 'MIDDLE_KEY=STRATA-8081\n' + filler * n + 'END_KEY=LONDON-9060\nReturn only JSON with start, middle and end holding the three marked key values.' 18 19 20def wait_idle (base ): 21for _ in range (30 ): 22if not any (s .get ('is_processing' )for s in b .get_json (base ,'/slots' )): 23return 24time .sleep (0.5 ) 25raise RuntimeError ('Engine busy; no request sent' ) 26 27 28def main (): 29p = argparse .ArgumentParser () 30p .add_argument ('--base' ,required = True ,help = 'Your locally accessible server URL, without /v1' ) 31p .add_argument ('--model' ,required = True ) 32p .add_argument ('--mode' ,choices = ('prefill' ,'recall120k' ,'medium' ),required = True ) 33p .add_argument ('--prefill' ,type = int ,default = 8192 ,help = 'Label only; configure server separately' ) 34p .add_argument ('--output' ,type = Path ,required = True ) 35a = p .parse_args () 36if a .output .exists (): 37p .error ('Output exists; choose a new path. No requests were sent.' ) 38if os .environ .get ('STRATA_API_KEY' ): 39b .AUTH_HEADERS ['Authorization' ]= 'Bearer ' + os .environ ['STRATA_API_KEY' ] 40status = b .get_json (a .base ,'/v1/status' ) 41if not status .get ('loaded' )or status .get ('model' )!= a .model or status .get ('context' , {}).get ('max_positions' )!= 122880 : 42p .error ('Expected the selected loaded model at 122880 context. No benchmark request sent.' ) 43wait_idle (a .base ) 44result = {'mode' :a .mode ,'declared_server_prefill' :a .prefill ,'results' : []} 45a .output .parent .mkdir (parents = True ,exist_ok = True ) 46if a .mode == 'prefill' : 47result ['warmup' ]= b .request (a .base ,a .model ,'quote_math' ,QUOTE ,0 ) 48a .output .write_text (json .dumps (result ,indent = 2 ),encoding = 'utf-8' ) 49if not b .validate (result ['warmup' ]): 50raise RuntimeError ('Warmup failed; stopping' ) 51cases = [(label ,recall (n ),run ,None ,None ,'low' ,1024 ) 52for label ,n in [('recall_8k' ,220 ), ('recall_28k' ,780 )]for run in (1 ,2 ,3 )] 53elif a .mode == 'recall120k' : 54cases = [('recall_120k' ,recall (3150 ),1 ,None ,None ,'low' ,1024 )] 55else : 56cases = [('quote_math' ,QUOTE ,1 ,None , {'type' :'json_object' },'medium' ,8192 ), 57 ('validation_logic' ,VALIDATION ,1 ,None , {'type' :'json_object' },'medium' ,8192 ), 58 ('tool_call' ,TOOL_PROMPT ,1 ,TOOLS ,None ,'medium' ,8192 )] 59for label ,prompt ,run ,tools ,fmt ,effort ,allowance in cases : 60wait_idle (a .base ) 61if b .available_ram ()<= 4 : 62raise RuntimeError ('Less than 4 GiB available physical RAM; no next request sent' ) 63row = b .request (a .base ,a .model ,label ,prompt ,run ,tools ,response_format = fmt , 64reasoning_effort = effort ,max_tokens = allowance ) 65row ['semantic_pass' ]= b .validate (row ) 66row ['strict_pass' ]= b .validate (row ,strict = True ) 67result ['results' ].append (row ) 68a .output .write_text (json .dumps (result ,indent = 2 ),encoding = 'utf-8' ) 69json .dumps ({k :row [k ]for k in ('case' ,'run' ,'wall_seconds' ,'semantic_pass' ,'strict_pass' ,'error' )}),flush = True ) 70if row ['error' ]or not row ['semantic_pass' ]or row ['timings' ].get ('cache_n' )!= 0 : 71raise RuntimeError ('Failed or cache-reused trial preserved; stopping without retry' ) 72 73 74if __name__ == '__main__' : 75main ()