mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
tools/vision: --tower auto uses our GPU tower on every CUDA class when the reader starts with --max-tokens above 1,024 (the default GPU limit), whatever the speed: at 16,384 tokens mtmd-GPU reads 0.81 to 0.83 against mtmd-CPU (A4000 0.813, RTX PRO 5000 0.834, P100 0.834), ours 0.9996 to 0.99998, at a time cost on Pascal (P100, Qwen3.8, 16,384 tokens: 196.6 s against mtmd-GPU 129.0 s); at or below 1,024 the speed rules stay (Pascal with F16 matrices and cc 6.1 / 6.2 keep mtmd); AMD gfx1151 and Metal unchanged; own_reader_supported and prefer_mtmd take max_tokens; unit test
This commit is contained in:
1 parent
87d9715922
commit
88fc47ccf0
7 files changed
+27
-12
No files matched your search
@@ -34,7 +34,7 @@ bool parse_enc(const std::string& line, std::string& img, std::string& out) {
|
||||
|
||||
} // namespace
|
||||
|
||||
bool own_reader_supported(const std::string& mmproj, bool gpu, std::string& why) {
|
||||
bool own_reader_supported(const std::string& mmproj, bool gpu, int max_tokens, std::string& why) {
|
||||
if (gpu) {
|
||||
#ifdef STRATA_VIT_GPU
|
||||
bool bf16 = false; // the layer matrices' type decides on Pascal (vit_gpu.h)
|
||||
@@ -44,7 +44,7 @@ bool own_reader_supported(const std::string& mmproj, bool gpu, std::string& why)
|
||||
if (g0.open(mmproj, e0))
|
||||
if (const GgufTensorInfo* t = g0.tensor("v.blk.0.attn_qkv.weight")) bf16 = t->type == GT_BF16;
|
||||
}
|
||||
if (!VitGpu::available(why) || VitGpu::prefer_mtmd(bf16, why)) return false;
|
||||
if (!VitGpu::available(why) || VitGpu::prefer_mtmd(bf16, max_tokens, why)) return false;
|
||||
#else
|
||||
why = "this build has no GPU backend for the own tower";
|
||||
return false;
|
||||
|
||||
@@ -17,7 +17,7 @@ struct OwnReaderOptions {
|
||||
};
|
||||
|
||||
// True when our tower can read this mmproj with this backend; otherwise `why` says what is missing (`--tower auto` falls back to mtmd then).
|
||||
bool own_reader_supported(const std::string& mmproj, bool gpu, std::string& why);
|
||||
bool own_reader_supported(const std::string& mmproj, bool gpu, int max_tokens, std::string& why); // max_tokens: --max-tokens (0: not given)
|
||||
|
||||
// Runs the reader on stdin/stdout; returns the process exit code (0 after QUIT or end of input).
|
||||
int own_reader_run(const OwnReaderOptions& o);
|
||||
|
||||
@@ -37,9 +37,15 @@ static uint16_t f32_to_f16(float f) { // good enough for the values used here
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// --- 0. the GPU classes where `--tower auto` keeps mtmd (vit_gpu.h) ---
|
||||
CHECK(vit_gpu_slower_nvidia(6, 0, false) && vit_gpu_slower_nvidia(6, 1, false) && vit_gpu_slower_nvidia(6, 1, true) && vit_gpu_slower_nvidia(6, 2, true));
|
||||
CHECK(!vit_gpu_slower_nvidia(6, 0, true));
|
||||
CHECK(!vit_gpu_slower_nvidia(5, 2, false) && !vit_gpu_slower_nvidia(7, 0, false) && !vit_gpu_slower_nvidia(8, 6, true) && !vit_gpu_slower_nvidia(12, 0, false));
|
||||
for (int mt : {0, 300, 1024}) { // at or below the default limit: the speed rule (Pascal keeps mtmd, except cc 6.0 with BF16 matrices)
|
||||
CHECK(vit_gpu_slower_nvidia(6, 0, false, mt) && vit_gpu_slower_nvidia(6, 1, false, mt) && vit_gpu_slower_nvidia(6, 1, true, mt) && vit_gpu_slower_nvidia(6, 2, true, mt));
|
||||
CHECK(!vit_gpu_slower_nvidia(6, 0, true, mt));
|
||||
CHECK(!vit_gpu_slower_nvidia(5, 2, false, mt) && !vit_gpu_slower_nvidia(7, 0, false, mt) && !vit_gpu_slower_nvidia(8, 6, true, mt) && !vit_gpu_slower_nvidia(12, 0, false, mt));
|
||||
}
|
||||
for (int mt : {1025, 4096, 16384}) { // above it: ours on every CUDA class
|
||||
CHECK(!vit_gpu_slower_nvidia(6, 0, false, mt) && !vit_gpu_slower_nvidia(6, 1, false, mt) && !vit_gpu_slower_nvidia(6, 1, true, mt) && !vit_gpu_slower_nvidia(6, 2, true, mt));
|
||||
CHECK(!vit_gpu_slower_nvidia(6, 0, true, mt) && !vit_gpu_slower_nvidia(8, 6, true, mt) && !vit_gpu_slower_nvidia(12, 0, false, mt));
|
||||
}
|
||||
CHECK(vit_gpu_slower_amd("gfx1151") && vit_gpu_slower_amd("gfx1151:xnack-"));
|
||||
CHECK(!vit_gpu_slower_amd("gfx1150") && !vit_gpu_slower_amd("gfx1201") && !vit_gpu_slower_amd("gfx11510") && !vit_gpu_slower_amd("gfx115") && !vit_gpu_slower_amd(""));
|
||||
const std::string tmp = std::string(std::getenv("TMPDIR") ? std::getenv("TMPDIR") : ".") + "/strata_own_test_" + std::to_string((long) std::rand()) + ".gguf";
|
||||
|
||||
@@ -470,10 +470,11 @@ bool VitGpu::available(std::string& why) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VitGpu::prefer_mtmd(bool bf16_matrices, std::string& why) {
|
||||
bool VitGpu::prefer_mtmd(bool bf16_matrices, int max_tokens, std::string& why) {
|
||||
#if defined(STRATA_VIT_HIP)
|
||||
hipDeviceProp_t p;
|
||||
(void) bf16_matrices;
|
||||
(void) max_tokens;
|
||||
if (hipGetDeviceProperties(&p, 0) != hipSuccess) { (void) hipGetLastError(); return false; }
|
||||
if (vit_gpu_slower_amd(p.gcnArchName)) {
|
||||
why = std::string(p.gcnArchName) + ": rocBLAS has only fallback kernels there, the own GPU tower is slower than mtmd";
|
||||
@@ -483,7 +484,7 @@ bool VitGpu::prefer_mtmd(bool bf16_matrices, std::string& why) {
|
||||
#else
|
||||
cudaDeviceProp p;
|
||||
if (cudaGetDeviceProperties(&p, 0) != cudaSuccess) { (void) cudaGetLastError(); return false; }
|
||||
if (vit_gpu_slower_nvidia(p.major, p.minor, bf16_matrices)) {
|
||||
if (vit_gpu_slower_nvidia(p.major, p.minor, bf16_matrices, max_tokens)) {
|
||||
why = "compute capability " + std::to_string(p.major) + "." + std::to_string(p.minor) + " (Pascal)" + (bf16_matrices ? "" : " with F16 matrices") +
|
||||
": the own GPU tower is slower than mtmd there";
|
||||
return true;
|
||||
|
||||
@@ -25,7 +25,14 @@ struct VitGpuImpl;
|
||||
// F16-accumulating variant of ours was as fast but missed rule 1: 0.9972), so with F16 matrices (Qwen3.6) ours stays slower (P100: at best 1.10 of mtmd-GPU,
|
||||
// RESULTS-OWN-3V.md 16.1). With BF16 matrices (Qwen3.8) mtmd multiplies in float32 too, and ours (BF16 held as F16, the larger score chunk) passes the whole
|
||||
// gate on a P100 (cc 6.0: 0.31 to 0.99 of mtmd-GPU's time, 16.1). Other Pascal chips (6.1, 6.2: GTX 10xx, Jetson TX2) are not measured: mtmd stays there.
|
||||
inline bool vit_gpu_slower_nvidia(int cc_major, int cc_minor, bool bf16_matrices) { return cc_major == 6 && !(cc_minor == 0 && bf16_matrices); }
|
||||
// Above the default GPU limit of 1,024 image tokens the speed rule gives way to correctness: mtmd's GPU reader drifts from mtmd's CPU path as pictures
|
||||
// grow (global cosine 0.983 at 2,116 tokens, 0.81 to 0.83 at 16,384 on the A4000, RTX PRO 5000 and P100), ours stays at 0.9996 to 0.99998 (RESULTS-OWN-3V.md
|
||||
// 16.7), so a reader started with --max-tokens above 1,024 takes our tower on every CUDA class, however slow (P100 at 16,384 tokens: 196.6 s against 129.0 s).
|
||||
// max_tokens 0 (not given) counts as the default. AMD gfx1151 keeps its rule (no large-picture data there yet).
|
||||
constexpr int kVitGpuDefaultLimit = 1024;
|
||||
inline bool vit_gpu_slower_nvidia(int cc_major, int cc_minor, bool bf16_matrices, int max_tokens) {
|
||||
return max_tokens <= kVitGpuDefaultLimit && cc_major == 6 && !(cc_minor == 0 && bf16_matrices);
|
||||
}
|
||||
// AMD gfx1151 (Strix Halo, Radeon 8060S): the ROCm package's rocBLAS ships only its generic "fallback" Tensile kernels for gfx1151, so every hipBLAS product runs
|
||||
// untuned (Windows, Strix: 1.73 to 3.03 of mtmd-HIP's time; the weight products alone 730 ms of a 1,024-token picture against mtmd-HIP's 690 ms for all of it;
|
||||
// RESULTS-OWN-3V.md 12.14). Windows and Linux alike until a Linux gfx1151 box is measured. `gfx` is the device's arch name (hipDeviceProp_t::gcnArchName,
|
||||
@@ -45,7 +52,7 @@ public:
|
||||
// True on a GPU class where this tower is known to be slower than mtmd's GPU reader, so `--tower auto` keeps mtmd there (`--tower own` still runs
|
||||
// this tower): NVIDIA Pascal (compute capability 6.x: no tensor cores; mtmd's F16 products accumulate in F16 at twice the float32 rate, ours in float32;
|
||||
// measured on a P100, RESULTS-OWN-3V.md 12.1). `why` says which.
|
||||
static bool prefer_mtmd(bool bf16_matrices, std::string& why); // bf16_matrices: the mmproj's layer matrices are BF16
|
||||
static bool prefer_mtmd(bool bf16_matrices, int max_tokens, std::string& why); // bf16_matrices: the mmproj's layer matrices are BF16; max_tokens: --max-tokens (0: not given)
|
||||
|
||||
// Uploads the weights to `device` and sizes the work buffers for pictures of up to `max_patches` patches (grown by encode when a picture
|
||||
// needs more). `g` must be supported().
|
||||
|
||||
@@ -414,8 +414,9 @@ bool VitGpu::available(std::string& why) {
|
||||
return pick_gpu(d, why);
|
||||
}
|
||||
|
||||
bool VitGpu::prefer_mtmd(bool bf16_matrices, std::string& why) {
|
||||
bool VitGpu::prefer_mtmd(bool bf16_matrices, int max_tokens, std::string& why) {
|
||||
(void) bf16_matrices;
|
||||
(void) max_tokens;
|
||||
(void) why;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ int main(int argc, char** argv) {
|
||||
// auto: our tower where it can read this file on this backend, else mtmd
|
||||
if (tower == "auto") {
|
||||
std::string why;
|
||||
tower = !mmproj.empty() && strata_vit::own_reader_supported(mmproj, gpu, why) ? "own" : "mtmd";
|
||||
tower = !mmproj.empty() && strata_vit::own_reader_supported(mmproj, gpu, max_tokens, why) ? "own" : "mtmd";
|
||||
}
|
||||
if (mmproj.empty() || (model.empty() && tower != "own")) { // our tower needs no text model: it never tokenizes
|
||||
std::fprintf(stderr, "usage: strata-vision --mmproj <mmproj.gguf> --model <model.gguf> [--gpu] [--threads N] "
|
||||
|
||||
Reference in new issue
Block a user