Returns 0 on success, -1 on error, and -2 on cancellation via llama_progress_callback
| 90 | |
| 91 | // Returns 0 on success, -1 on error, and -2 on cancellation via llama_progress_callback |
| 92 | static int llama_model_load(const std::string & fname, std::vector<std::string> & splits, llama_model & model, llama_model_params & params) { |
| 93 | // loading time will be recalculated after the first eval, so |
| 94 | // we take page faults deferred by mmap() into consideration |
| 95 | model.t_load_us = 0; |
| 96 | time_meas tm(model.t_load_us); |
| 97 | |
| 98 | model.t_start_us = tm.t_start_us; |
| 99 | |
| 100 | try { |
| 101 | llama_model_loader ml(fname, splits, params.use_mmap, params.check_tensors, params.kv_overrides, params.tensor_buft_overrides); |
| 102 | |
| 103 | ml.print_info(); |
| 104 | |
| 105 | model.hparams.vocab_only = params.vocab_only; |
| 106 | |
| 107 | try { |
| 108 | model.load_arch(ml); |
| 109 | } catch(const std::exception & e) { |
| 110 | throw std::runtime_error("error loading model architecture: " + std::string(e.what())); |
| 111 | } |
| 112 | try { |
| 113 | model.load_hparams(ml); |
| 114 | } catch(const std::exception & e) { |
| 115 | throw std::runtime_error("error loading model hyperparameters: " + std::string(e.what())); |
| 116 | } |
| 117 | try { |
| 118 | model.load_vocab(ml); |
| 119 | } catch(const std::exception & e) { |
| 120 | throw std::runtime_error("error loading model vocabulary: " + std::string(e.what())); |
| 121 | } |
| 122 | |
| 123 | model.load_stats(ml); |
| 124 | model.print_info(); |
| 125 | |
| 126 | if (params.vocab_only) { |
| 127 | LLAMA_LOG_INFO("%s: vocab only - skipping tensors\n", __func__); |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | if (!model.load_tensors(ml)) { |
| 132 | return -2; |
| 133 | } |
| 134 | } catch (const std::exception & err) { |
| 135 | LLAMA_LOG_ERROR("%s: error loading model: %s\n", __func__, err.what()); |
| 136 | return -1; |
| 137 | } |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | static struct llama_model * llama_model_load_from_file_impl( |
| 143 | const std::string & path_model, |
no test coverage detected