Returns 0 on success, -1 on error, and -2 on cancellation via llama_progress_callback
| 826 | |
| 827 | // Returns 0 on success, -1 on error, and -2 on cancellation via llama_progress_callback |
| 828 | static int llama_model_load(const std::string & fname, std::vector<std::string> & splits, llama_model & model, llama_model_params & params) { |
| 829 | // loading time will be recalculated after the first eval, so |
| 830 | // we take page faults deferred by mmap() into consideration |
| 831 | model.t_load_us = 0; |
| 832 | time_meas tm(model.t_load_us); |
| 833 | |
| 834 | model.t_start_us = tm.t_start_us; |
| 835 | |
| 836 | try { |
| 837 | llama_model_loader ml(fname, splits, params.use_mmap, params.use_direct_io, params.check_tensors, params.no_alloc, params.kv_overrides, params.tensor_buft_overrides); |
| 838 | |
| 839 | ml.print_info(); |
| 840 | |
| 841 | model.hparams.vocab_only = params.vocab_only; |
| 842 | model.hparams.no_alloc = params.no_alloc; |
| 843 | |
| 844 | try { |
| 845 | model.load_arch(ml); |
| 846 | } catch(const std::exception & e) { |
| 847 | throw std::runtime_error("error loading model architecture: " + std::string(e.what())); |
| 848 | } |
| 849 | try { |
| 850 | model.load_hparams(ml); |
| 851 | } catch(const std::exception & e) { |
| 852 | throw std::runtime_error("error loading model hyperparameters: " + std::string(e.what())); |
| 853 | } |
| 854 | if (model.arch == LLM_ARCH_CLIP) { |
| 855 | throw std::runtime_error("CLIP cannot be used as main model, use it with --mmproj instead"); |
| 856 | } |
| 857 | try { |
| 858 | model.load_vocab(ml); |
| 859 | } catch(const std::exception & e) { |
| 860 | throw std::runtime_error("error loading model vocabulary: " + std::string(e.what())); |
| 861 | } |
| 862 | |
| 863 | model.load_stats(ml); |
| 864 | model.print_info(); |
| 865 | |
| 866 | if (params.vocab_only) { |
| 867 | LLAMA_LOG_INFO("%s: vocab only - skipping tensors\n", __func__); |
| 868 | return 0; |
| 869 | } |
| 870 | |
| 871 | if (!model.load_tensors(ml)) { |
| 872 | return -2; |
| 873 | } |
| 874 | } catch (const std::exception & err) { |
| 875 | LLAMA_LOG_ERROR("%s: error loading model: %s\n", __func__, err.what()); |
| 876 | return -1; |
| 877 | } |
| 878 | |
| 879 | return 0; |
| 880 | } |
| 881 | |
| 882 | static struct llama_model * llama_model_load_from_file_impl( |
| 883 | const std::string & path_model, |
no test coverage detected