File size: 1,057 Bytes
c8fd141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import json, subprocess, os, sys
W=os.path.expanduser('~/evalhf_work')
T=open(W+'/ds/0shot.txt',encoding='utf-8',newline='').read()
d=json.load(open(W+'/ds/LongBench-v2/data.json',encoding='utf-8'))
print(len(d), list(d[0].keys()), file=sys.stderr)
def render(r):
    return T.replace('$DOC$',r['context'].strip()).replace('$Q$',r['question'].strip()).replace('$C_A$',r['choice_A'].strip()).replace('$C_B$',r['choice_B'].strip()).replace('$C_C$',r['choice_C'].strip()).replace('$C_D$',r['choice_D'].strip())
TOK='llama-tokenize'
M=os.path.expanduser('~/qwen38-bench/models/swift15/ATX-Swift-1.5-Qwen3.8-27B-Uncensored-IQ4_XS-M.gguf')
out={}
for i,r in enumerate(d):
    p=render(r)
    if len(p)<400000 or len(p)>5_000_000: continue   # 196K tokens needs >=~400K chars even for dense text? checked below via ratio
    o=subprocess.run([TOK,'-m',M,'--no-bos','--ids','--stdin'],input=p.encode(),capture_output=True)
    n=o.stdout.count(b',')+1 if o.stdout.strip() else -1
    out[i]=n; print(i,len(p),n,flush=True)
json.dump(out,open(W+'/lb_tok.json','w'))