okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
870ea9763
main
1// tools/vision/own/own_reader.h - strata-vision's reader loop on our own tower (`--tower own`): the same protocol as the mtmd one. 2// 3// prints "READY <out_dim> own", then per stdin line ENC <image> <output> -> "OK <n_tokens> <nx> <ny> <ms>" or "ERR <message>"; QUIT ends. 4// The output file is int32 {0x31455653 'SVE1', n_tokens, nx, ny, n_embd} then float32 [n_tokens][n_embd] (row i at x = i % nx, y = i / nx). 5#pragma once 6 7#include "cpu_caps.h" 8#include "vit_geometry.h" 9 10#include <string> 11 12namespace strata_vit { 13 14struct OwnReaderOptions { 15std ::string mmproj ; 16bool gpu = false; 17int threads = 0 ;// CPU threads (<= 0: half the hardware threads, at most 16, as the mtmd reader) 18int max_tokens = 0 ;// the helper's --max-tokens (0: the tower's own limit); a picture over it by more than an eighth is refused 19int min_tokens = 0 ; 20// `auto` (the default): a failure before READY (no GPU, the load, the warm-up) prints nothing on stdout; own_reader_run returns kOwnStartFailed with the 21// reason in *start_error, and strata-vision starts mtmd's reader in its place. Null: the failure is an "ERR ..." line, as with `--tower own`. 22std ::string * start_error = nullptr; 23}; 24 25// The tower when no --tower is given: STRATA_VISION_TOWER's value (env, may be null) if it is mtmd, own or auto, else auto; `note` gets a line for a value that 26// is none of these. 27std ::string vision_tower_default (const char * env ,std ::string & note ); 28 29// own_reader_run's return when start_error is set and our tower did not reach READY 30constexprint kOwnStartFailed = 100 ; 31 32// Test hook (STRATA_VIT_TEST_FAIL=gpu|load|warmup): our tower fails at that point before READY, as if there were no GPU, the load had failed, or the warm-up had 33// run out of memory, so the fallback to mtmd can be checked on a box where ours would start. True when `point` is the one named. 34bool own_reader_inject_failure (const char * point ); 35 36// True when our tower can read this mmproj with this backend; otherwise `why` says what is missing (`--tower auto` falls back to mtmd then). 37bool own_reader_supported (const std ::string & mmproj ,bool gpu ,int max_tokens ,std ::string & why );// max_tokens: --max-tokens (0: not given) 38 39// The CPU half of that decision, for a tower of geometry `g` on a CPU whose best kernel tier is `isa`: true for every tier (the no-AVX2 exception is gone), false 40// only when the tower itself uses an operation this code does not have (`why`). 41bool own_cpu_reader_supported (const VitGeometry & g ,quant ::Isa isa ,std ::string & why ); 42 43// The reader a tower setting gives: "mtmd" and "own" as asked (an explicit setting is never overruled), "auto" gives "own" when `own_ok`, else "mtmd". 44std ::string vision_tower_resolve (const std ::string & tower ,bool own_ok ); 45 46// Runs the reader on stdin/stdout; returns the process exit code (0 after QUIT or end of input). 47int own_reader_run (const OwnReaderOptions & o ); 48 49}// namespace strata_vit