frontend: --mmproj-gpu runs the vision encoder on the card; the CPU stays the default
The first picture on the A6000 VM (Ryzen 7 1700, 12 vCPUs, AVX2) took 146 s to encode a 1920x1080 screenshot (2040 rows) on the CPU against 0.85 s of engine time. The card had 29 GB free beside the engine. --mmproj-gpu (a front-end option, not llama-server's, whose default is the GPU) puts the encoder there with mtmd's warm-up so the work buffers exist before the first request. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
d0bc0d868d
commit
1026afb266
2 files changed
+20
-7
No files matched your search
+12
-2
@@ -51,8 +51,10 @@ void usage() {
|
||||
" -m, --model FILE the GGUF the vocabulary and chat template are read from (no tensors are loaded)\n"
|
||||
" --host, --port, --api-key, --threads-http, --temp, --top-k, --top-p, --min-p, --reasoning-format,\n"
|
||||
" --chat-template-kwargs, --alias ... llama-server options (see llama-server --help)\n"
|
||||
" --mmproj FILE the model's vision projector: image_url parts are encoded here on the CPU and\n"
|
||||
" handed to the engine (Qwen family; --threads sets the encoder's threads)\n"
|
||||
" --mmproj FILE the model's vision projector: image_url parts are encoded in this process and\n"
|
||||
" handed to the engine (Qwen family); on the CPU (--threads N) unless --mmproj-gpu\n"
|
||||
" --mmproj-gpu encode on the card: about 1 GB of VRAM plus work buffers, taken before the engine\n"
|
||||
" sizes its expert cache only if the encoder loads first; for cards with room\n"
|
||||
" -- everything after it is passed to the engine; --serve is added\n"
|
||||
"\n"
|
||||
"example (Qwen3.6-35B-A3B from its GGUF):\n"
|
||||
@@ -88,6 +90,7 @@ int main(int argc, char ** argv) {
|
||||
std::string engine_exe;
|
||||
std::vector<std::string> engine_args;
|
||||
std::vector<char *> llama_argv;
|
||||
bool mmproj_gpu = false; // the vision encoder on the card: only where the engine leaves room (a 48 GB card)
|
||||
llama_argv.push_back(argv[0]);
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
const std::string a = argv[i];
|
||||
@@ -106,6 +109,10 @@ int main(int argc, char ** argv) {
|
||||
engine_exe = a.substr(9);
|
||||
continue;
|
||||
}
|
||||
if (a == "--mmproj-gpu") {
|
||||
mmproj_gpu = true;
|
||||
continue;
|
||||
}
|
||||
llama_argv.push_back(argv[i]);
|
||||
}
|
||||
if (engine_exe.empty()) {
|
||||
@@ -130,6 +137,9 @@ int main(int argc, char ** argv) {
|
||||
if (!common_params_parse((int) llama_argv.size(), llama_argv.data(), params, LLAMA_EXAMPLE_SERVER)) {
|
||||
return 1;
|
||||
}
|
||||
// llama-server encodes images on the GPU unless --no-mmproj-offload; here the card is the engine's, so the
|
||||
// encoder runs on the CPU unless --mmproj-gpu asks for the card (upstream PolyStrata's choice as well)
|
||||
params.mmproj_use_gpu = mmproj_gpu;
|
||||
if (params.model.path.empty()) {
|
||||
std::fprintf(stderr, "unbiased-strata: -m <model.gguf> is required (the vocabulary and chat template come from it)\n");
|
||||
return 2;
|
||||
|
||||
@@ -177,6 +177,7 @@ struct strata_context_impl {
|
||||
mtmd_helper_init_opt init_opt{};
|
||||
int32_t vision_width = 0; // the projector's output width, checked against the model's embedding
|
||||
int32_t image_pad_id = -1; // the token whose runs in the ids the engine replaces with picture rows
|
||||
bool p_mmproj_gpu = false;
|
||||
|
||||
server_chat_params chat_params;
|
||||
std::map<std::string, bool> chat_caps;
|
||||
@@ -435,9 +436,9 @@ struct strata_context_impl {
|
||||
// the request parser (server-common) replaces each image_url part by a marker that is random per process
|
||||
// (get_media_marker); mtmd must look for that same marker, as server-context.cpp sets it
|
||||
cp.media_marker = get_media_marker();
|
||||
cp.use_gpu = false; // the card belongs to the engine; upstream encoded on the CPU as well
|
||||
cp.use_gpu = p.mmproj_use_gpu; // CPU unless --mmproj-gpu (main.cpp): the card is the engine's
|
||||
cp.print_timings = false;
|
||||
cp.warmup = false;
|
||||
cp.warmup = p.mmproj_use_gpu; // on the card, allocate the work buffers now, not at the first picture
|
||||
cp.n_threads = p.cpuparams.n_threads > 0 ? p.cpuparams.n_threads
|
||||
: std::max(1u, std::thread::hardware_concurrency() / 2);
|
||||
if (p.image_max_tokens > 0) {
|
||||
@@ -454,8 +455,9 @@ struct strata_context_impl {
|
||||
}
|
||||
vision_width = proj_width;
|
||||
image_pad_id = pad[0];
|
||||
LOG_INF("vision: %s, rows of %d, encoder on the CPU with %d threads, image_pad=%d\n",
|
||||
p.mmproj.path.c_str(), vision_width, cp.n_threads, image_pad_id);
|
||||
p_mmproj_gpu = p.mmproj_use_gpu;
|
||||
LOG_INF("vision: %s, rows of %d, encoder on the %s (%d CPU threads), image_pad=%d\n",
|
||||
p.mmproj.path.c_str(), vision_width, cp.use_gpu ? "GPU" : "CPU", cp.n_threads, image_pad_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -534,7 +536,8 @@ struct strata_context_impl {
|
||||
ids.insert(ids.end(), (size_t) n_tok, image_pad_id);
|
||||
++n_pictures;
|
||||
const double ms = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - t0).count();
|
||||
SRV_INF("task %d: picture %d: %d rows (%dx%d) encoded in %.0f ms on the CPU\n", t.id, n_pictures, n_tok, nx, ny, ms);
|
||||
SRV_INF("task %d: picture %d: %d rows (%dx%d) encoded in %.0f ms on the %s\n", t.id, n_pictures, n_tok, nx, ny, ms,
|
||||
p_mmproj_gpu ? "GPU" : "CPU");
|
||||
i += (size_t) n_tok;
|
||||
}
|
||||
if (std::fclose(f) != 0) {
|
||||
|
||||
Reference in new issue
Block a user