okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-142c-small into f-142407ea8192

main
4.5 KiB75 linesraw
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):
16    filler = 'This is irrelevant background about routine office cleaning schedules. Ignore it when extracting marked keys.\n'
17    return '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):
21    for _ in range(30):
22        if not any(s.get('is_processing') for s in b.get_json(base, '/slots')):
23            return
24        time.sleep(0.5)
25    raise RuntimeError('Engine busy; no request sent')
26
27
28def main():
29    p = argparse.ArgumentParser()
30    p.add_argument('--base', required=True, help='Your locally accessible server URL, without /v1')
31    p.add_argument('--model', required=True)
32    p.add_argument('--mode', choices=('prefill', 'recall120k', 'medium'), required=True)
33    p.add_argument('--prefill', type=int, default=8192, help='Label only; configure server separately')
34    p.add_argument('--output', type=Path, required=True)
35    a = p.parse_args()
36    if a.output.exists():
37        p.error('Output exists; choose a new path. No requests were sent.')
38    if os.environ.get('STRATA_API_KEY'):
39        b.AUTH_HEADERS['Authorization'] = 'Bearer ' + os.environ['STRATA_API_KEY']
40    status = b.get_json(a.base, '/v1/status')
41    if not status.get('loaded') or status.get('model') != a.model or status.get('context', {}).get('max_positions') != 122880:
42        p.error('Expected the selected loaded model at 122880 context. No benchmark request sent.')
43    wait_idle(a.base)
44    result = {'mode': a.mode, 'declared_server_prefill': a.prefill, 'results': []}
45    a.output.parent.mkdir(parents=True, exist_ok=True)
46    if a.mode == 'prefill':
47        result['warmup'] = b.request(a.base, a.model, 'quote_math', QUOTE, 0)
48        a.output.write_text(json.dumps(result, indent=2), encoding='utf-8')
49        if not b.validate(result['warmup']):
50            raise RuntimeError('Warmup failed; stopping')
51        cases = [(label, recall(n), run, None, None, 'low', 1024)
52                 for label, n in [('recall_8k', 220), ('recall_28k', 780)] for run in (1, 2, 3)]
53    elif a.mode == 'recall120k':
54        cases = [('recall_120k', recall(3150), 1, None, None, 'low', 1024)]
55    else:
56        cases = [('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)]
59    for label, prompt, run, tools, fmt, effort, allowance in cases:
60        wait_idle(a.base)
61        if b.available_ram() <= 4:
62            raise RuntimeError('Less than 4 GiB available physical RAM; no next request sent')
63        row = b.request(a.base, a.model, label, prompt, run, tools, response_format=fmt,
64                        reasoning_effort=effort, max_tokens=allowance)
65        row['semantic_pass'] = b.validate(row)
66        row['strict_pass'] = b.validate(row, strict=True)
67        result['results'].append(row)
68        a.output.write_text(json.dumps(result, indent=2), encoding='utf-8')
69        print(json.dumps({k: row[k] for k in ('case', 'run', 'wall_seconds', 'semantic_pass', 'strict_pass', 'error')}), flush=True)
70        if row['error'] or not row['semantic_pass'] or row['timings'].get('cache_n') != 0:
71            raise RuntimeError('Failed or cache-reused trial preserved; stopping without retry')
72
73
74if __name__ == '__main__':
75    main()