test-model-load-cancel.cpp 768 B

123456789101112131415161718192021222324252627
  1. #include "llama.h"
  2. #include "get-model.h"
  3. #include <cstdlib>
  4. int main(int argc, char *argv[] ) {
  5. auto * model_path = get_model_or_exit(argc, argv);
  6. auto * file = fopen(model_path, "r");
  7. if (file == nullptr) {
  8. fprintf(stderr, "no model at '%s' found\n", model_path);
  9. return EXIT_FAILURE;
  10. }
  11. fprintf(stderr, "using '%s'\n", model_path);
  12. fclose(file);
  13. llama_backend_init(false);
  14. auto params = llama_model_params{};
  15. params.use_mmap = false;
  16. params.progress_callback = [](float progress, void * ctx){
  17. (void) ctx;
  18. return progress > 0.50;
  19. };
  20. auto * model = llama_load_model_from_file(model_path, params);
  21. llama_backend_free();
  22. return model == nullptr ? EXIT_SUCCESS : EXIT_FAILURE;
  23. }