emotweetid-ekman7 / bench_batch.py
mahalisyarifuddin's picture
EmoTweetID unified under Ekman's 7 universal emotions: human labels kept, anger pool split into anger/contempt by laya
f5a2109 verified
Raw History Blame Contribute Delete
1.08 kB
"""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()