File size: 1,079 Bytes
f5a2109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""Batch cap sweep on laya's own numbers: rows/pass is the knob, not max_len."""
import json, sys, time
import numpy as np, pandas as pd, torch
import laya_opt
from ekman_questions import EKMAN_QUESTIONS
from bench_speedup import texts
agent = laya_opt.load_agent()
tx = texts(48)
q = {"ekman": EKMAN_QUESTIONS["ekman"]}
base = None
for budget in [1, 512, 1024, 2048, 4096, 6144, 12288]:
    if budget == 1:   # one state per pass == laya's own predict semantics
        t0 = time.time()
        for t in tx:
            agent.predict(t, q)
        dt = time.time() - t0
        rows_pp, tag = 1.0, "stock predict (1 state/pass)"
    else:
        _, st = laya_opt.score_texts(agent, q, tx, max_len=256, head_max_len=144,
                                     token_budget=budget, log=lambda *a: None)
        dt, rows_pp, tag = st["seconds"], st["rows"]/st["forward_passes"], "budget=%d" % budget
    ms = dt/len(tx)*1000
    if base is None: base = ms
    print("%-28s %6.1f ms/doc  rows/pass=%5.1f  speedup vs stock=%.2fx" % (tag, ms, rows_pp, base/ms))
    sys.stdout.flush()