Skip to content

Commit e950f88

Browse files
committed
Mtmd: add a way to select device for vision encoder
1 parent 73e53dc commit e950f88

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tools/mtmd/clip.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,16 @@ struct clip_ctx {
384384
if (!backend_cpu) {
385385
throw std::runtime_error("failed to initialize CPU backend");
386386
}
387-
backend = ctx_params.use_gpu
388-
? ggml_backend_init_by_type(GGML_BACKEND_DEVICE_TYPE_GPU, nullptr)
389-
: nullptr;
387+
backend = nullptr;
388+
auto backend_name = std::getenv("MTMD_BACKEND_DEVICE");
389+
if(backend_name != nullptr && ctx_params.use_gpu) {
390+
backend = ggml_backend_init_by_name(backend_name, nullptr);
391+
}
392+
if(!backend){
393+
backend = ctx_params.use_gpu
394+
? ggml_backend_init_by_type(GGML_BACKEND_DEVICE_TYPE_GPU, nullptr)
395+
: nullptr;
396+
}
390397

391398
if (backend) {
392399
LOG_INF("%s: CLIP using %s backend\n", __func__, ggml_backend_name(backend));

0 commit comments

Comments
 (0)