Skip to content

Commit cd6f698

Browse files
committed
[aux] Test full load from disk
This change adds an additional automated test loading from disk, to ensure the existing functionallity does not break.
1 parent ca481ed commit cd6f698

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ llama_build_and_test(test-gguf.cpp)
197197
llama_build_and_test(test-backend-ops.cpp)
198198

199199
llama_build_and_test(test-model-load-cancel.cpp LABEL "model")
200+
llama_build_and_test(test-model-load-disk.cpp LABEL "model")
200201
llama_build_and_test(test-autorelease.cpp LABEL "model")
201202

202203
if (NOT GGML_BACKEND_DL)

tests/test-model-load-disk.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <cstdlib>
2+
3+
#include "get-model.h"
4+
#include "llama.h"
5+
6+
int main(int argc, char * argv[]) {
7+
auto * model_path = get_model_or_exit(argc, argv);
8+
auto * file = fopen(model_path, "r");
9+
if (file == nullptr) {
10+
fprintf(stderr, "no model at '%s' found\n", model_path);
11+
return EXIT_FAILURE;
12+
}
13+
14+
fprintf(stderr, "using '%s'\n", model_path);
15+
fclose(file);
16+
17+
llama_backend_init();
18+
auto params = llama_model_params{};
19+
params.use_mmap = false;
20+
params.progress_callback = [](float progress, void * ctx) {
21+
(void) ctx;
22+
fprintf(stderr, "%.2f%% ", progress * 100.0f);
23+
// true means: Don't cancel the load
24+
return true;
25+
};
26+
auto * model = llama_model_load_from_file(model_path, params);
27+
28+
// Add newline after progress output
29+
fprintf(stderr, "\n");
30+
31+
if (model == nullptr) {
32+
fprintf(stderr, "Failed to load model\n");
33+
llama_backend_free();
34+
return EXIT_FAILURE;
35+
}
36+
37+
fprintf(stderr, "Model loaded successfully\n");
38+
llama_model_free(model);
39+
llama_backend_free();
40+
return EXIT_SUCCESS;
41+
}

0 commit comments

Comments
 (0)