okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0479b72e9
main
1#!/usr/bin/env python3 2"""Times one reader on one picture: image-to-embedding time (median of --repeat encodes after the first) and the reader's GPU memory. 3 4python3 bench_enc.py --helper <strata-vision or strata-vision-own> --mmproj <mmproj.gguf> --model <text model or x> --image <picture> [--tower own] 5[--gpu] [--max-tokens 1024] [--repeat 8] [--out <file for the embeddings>] [--env NAME=VALUE ...] 6Prints one line: label, tokens, median ms, min ms, peak GPU MiB (nvidia-smi, by pid). Used to compare settings of the GPU tower (STRATA_VIT_ROWS, STRATA_VIT_SCORES). 7""" 8import argparse 9import os 10import statistics 11import subprocess 12import sys 13 14 15def main (): 16ap = argparse .ArgumentParser () 17ap .add_argument ("--helper" ,required = True ) 18ap .add_argument ("--mmproj" ,required = True ) 19ap .add_argument ("--model" ,default = "x" ) 20ap .add_argument ("--image" ,required = True ) 21ap .add_argument ("--tower" ,default = "own" ) 22ap .add_argument ("--gpu" ,action = "store_true" ) 23ap .add_argument ("--max-tokens" ,type = int ,default = 1024 ) 24ap .add_argument ("--repeat" ,type = int ,default = 8 ) 25ap .add_argument ("--out" ,default = "/tmp/bench_enc.sve" ) 26ap .add_argument ("--label" ,default = "" ) 27ap .add_argument ("--env" ,action = "append" ,default = []) 28a = ap .parse_args () 29args = [a .helper ,"--mmproj" ,a .mmproj ,"--model" ,a .model ,"--tower" ,a .tower ,"--max-tokens" ,str (a .max_tokens )] 30if a .gpu : 31args .append ("--gpu" ) 32env = dict (os .environ ) 33for kv in a .env : 34k ,_ ,v = kv .partition ("=" ) 35env [k ]= v 36p = subprocess .Popen (args ,stdin = subprocess .PIPE ,stdout = subprocess .PIPE ,stderr = subprocess .DEVNULL ,text = True ,env = env ) 37if not p .stdout .readline ().startswith ("READY" ): 38raise SystemExit ("reader did not start" ) 39ms ,tokens ,peak = [],"?" ,0 40for i in range (a .repeat + 1 ): 41p .stdin .write ("ENC %s %s\n" % (os .path .abspath (a .image ),a .out )) 42p .stdin .flush () 43r = p .stdout .readline ().split () 44if not r or r [0 ]!= "OK" : 45raise SystemExit ("encode failed: %s" % " " .join (r )) 46tokens = r [1 ] 47if i : 48ms .append (float (r [4 ])) 49try : 50smi = subprocess .run (["nvidia-smi" ,"--query-compute-apps=pid,used_memory" ,"--format=csv,noheader,nounits" ],capture_output = True ,text = True ,timeout = 30 ).stdout 51for line in smi .splitlines (): 52pid ,_ ,mem = line .partition ("," ) 53if pid .strip ()== str (p .pid )and mem .strip ().isdigit (): 54peak = max (peak ,int (mem .strip ())) 55except Exception :# noqa: BLE001 56pass 57p .stdin .write ("QUIT\n" ) 58p .stdin .flush () 59p .wait (timeout = 30 ) 60"%-28s tokens %s median %.0f ms min %.0f ms peak %d MiB" % (a .label or " " .join (a .env )or "default" ,tokens ,statistics .median (ms ),min (ms ),peak )) 61 62 63if __name__ == "__main__" : 64main ()