File size: 1,873 Bytes
4a1ea7b | 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | """Text-encoder speed vs prompt length on the GPU (random embeddings of the real scale; timing only).
Usage: python bench_te.py [--lengths 64,256,512,1024,2048] [--parts 0,1,2,3]
"""
import argparse
import json
import sys
import time
import numpy as np
sys.path.insert(0, __import__("os").path.dirname(__import__("os").path.abspath(__file__)))
from common import MODELS, WORK, hwm_gb, text_rope # noqa: E402
from ovrun import compile_model, gpu_mem, make_core # noqa: E402
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--lengths", default="64,256,512,1024,2048")
ap.add_argument("--parts", default="0")
ap.add_argument("--device", default="GPU")
ap.add_argument("--precision", default=None)
args = ap.parse_args()
core = make_core(True)
out = {}
rng = np.random.default_rng(0)
for k in [int(x) for x in args.parts.split(",")]:
cm, _ = compile_model(core, f"{MODELS}/te/te_part{k}.xml", args.device, args.precision, label=f"te_part{k}")
req = cm.create_infer_request()
for L in [int(x) for x in args.lengths.split(",")]:
cos, sin = text_rope(L)
h = (rng.standard_normal((1, L, 4096)) * 0.5).astype(np.float32)
ts = []
for _ in range(2):
t = time.time()
r = req.infer({"hidden": h, "cos": cos, "sin": sin})
ts.append(time.time() - t)
y = np.array(list(r.values())[0])
print(f"[bench] part{k} L={L}: {[round(x, 3) for x in ts]} finite={bool(np.isfinite(y).all())} absmax={float(np.abs(y).max()):.1f}", flush=True)
out[f"part{k}_L{L}"] = [round(x, 3) for x in ts]
print("[gpu mem MB]", gpu_mem(core), flush=True)
del req, cm
json.dump(out, open(f"{WORK}/bench_te_{args.device}.json", "w"), indent=1)
if __name__ == "__main__":
main()
|