Skip to content

Commit 123b805

Browse files
committed
ml: don't try to convert weights if CPU backend is not available
* old CPUs may not be able to load ggml-cpu backend * fp16 -> fp32 conversion for old GPU may not be needed * GPU without native fp16 can usually still emulate it, might be slow
1 parent b8bb09d commit 123b805

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/visp/ml.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,16 @@ struct tensor_converter {
359359
dst_type = src_type;
360360
}
361361

362+
backend.reset(ggml_backend_init_by_type(GGML_BACKEND_DEVICE_TYPE_CPU, nullptr));
363+
if (!backend && whcn_to_cwhn) {
364+
// cpu instruction set not supported, but we must do layout conversion
365+
throw except("Cannot use CPU for tensor conversion: hardware not supported");
366+
} else if (!backend) {
367+
// don't convert, hope the backend can deal with the model as-is (might be slow)
368+
dst_type = GGML_TYPE_COUNT;
369+
return;
370+
}
371+
362372
ggml_init_params ctx_params{
363373
.mem_size = ggml_tensor_overhead() + ggml_graph_overhead(),
364374
.mem_buffer = nullptr,
@@ -380,8 +390,6 @@ struct tensor_converter {
380390

381391
gallocr.reset(ggml_gallocr_new(ggml_backend_cpu_buffer_type()));
382392
ggml_gallocr_reserve(gallocr.get(), graph);
383-
384-
backend.reset(ggml_backend_init_by_type(GGML_BACKEND_DEVICE_TYPE_CPU, nullptr));
385393
}
386394

387395
ggml_type target_type(ggml_tensor const* t) const {

0 commit comments

Comments
 (0)