#!/usr/bin/env python3 """GPU probe of short and recursive-chunk paths; no benchmark data required.""" import argparse,copy,json from pathlib import Path p=argparse.ArgumentParser();p.add_argument('--checkpoint',type=Path,required=True);p.add_argument('--device',default='cuda:0');a=p.parse_args() from serve_312k import LemonDeciderHFService s=LemonDeciderHFService(a.checkpoint,a.device,None) short=json.loads((Path(__file__).resolve().parents[1]/'examples/request.json').read_text()) long={'state':'Synthetic chunk-planning regression.','questions':{str(i):{'type':'choice','instructions':'Choose one.','criteria':{'a':'alpha '*80,'b':'beta '*80}} for i in range(64)}} reports=[] for body,split in [(short,False),(long,True)]: before=copy.deepcopy(body) rows=[{'state':body['state'],'question':q,'images':[]} for q in body['questions'].values()] chunks=s.plan(rows) assert (len(chunks)>1)==split assert [r for c in chunks for r in c]==rows assert all(s.joint.unit_lengths(s.processor,s.model.config,[c])[0]<=8192 for c in chunks) actual=s.predict(body);answers=[];tokens=0 for c in chunks: result=s.predict_joint(s.model,s.processor,c);answers.extend(result['answers']);tokens+=result['input_tokens'] assert list(actual['answers'].values())==answers assert actual['usage']['input_tokens']==tokens and list(actual['answers'])==list(body['questions']) assert body==before reports.append({'split':split,'chunk_sizes':[len(c) for c in chunks],'native_per_chunk_parity':True,'input_tokens':tokens}) try:s.predict({'state':'hello '*20000,'questions':{'q':short['questions']['intent']}}) except ValueError as e:assert 'exceeds' in str(e) and 'truncated' in str(e) else:raise AssertionError('Oversized singleton was not rejected') print(json.dumps({'passed':True,'cases':reports,'singleton_rejected':True},indent=2))