MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / load_model

Function load_model

subprojects/llama.cpp/tests/test-backend-sampler.cpp:30–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28};
29
30static llama_model_ptr load_model(const test_args & args) {
31 auto mparams = llama_model_default_params();
32
33 ggml_backend_dev_t devs[2] = { nullptr, nullptr };
34
35 if (args.device != "auto") {
36 if (args.device == "gpu") {
37 devs[0] = ggml_backend_dev_by_type(GGML_BACKEND_DEVICE_TYPE_GPU);
38
39 if (devs[0] == nullptr) {
40 fprintf(stderr, "Error: GPU requested but not available\n");
41 return nullptr;
42 }
43
44 mparams.n_gpu_layers = 999;
45 } else if (args.device == "cpu") {
46 devs[0] = ggml_backend_dev_by_type(GGML_BACKEND_DEVICE_TYPE_CPU);
47
48 mparams.n_gpu_layers = 0;
49 } else {
50 fprintf(stderr, "Error: invalid device '%s'\n", args.device.c_str());
51 return nullptr;
52 }
53
54 mparams.devices = devs;
55
56 fprintf(stderr, "Using device: %s\n", ggml_backend_dev_name(devs[0]));
57 }
58
59 llama_model_ptr res;
60
61 res.reset(llama_model_load_from_file(args.model.c_str(), mparams));
62
63 if (!res) {
64 fprintf(stderr, "Warning: failed to load model '%s', skipping test\n", args.model.c_str());
65 return nullptr;
66 }
67
68 return res;
69}
70
71struct test_context {
72 llama_context_ptr ctx;

Callers 2

mainFunction · 0.70
loadMethod · 0.50

Calls 5

ggml_backend_dev_by_typeFunction · 0.85
ggml_backend_dev_nameFunction · 0.85
resetMethod · 0.65

Tested by

no test coverage detected