| 157 | }; |
| 158 | |
| 159 | static void llama_params_fit_impl( |
| 160 | const char * path_model, struct llama_model_params * mparams, struct llama_context_params * cparams, |
| 161 | float * tensor_split, struct llama_model_tensor_buft_override * tensor_buft_overrides, |
| 162 | size_t * margins_s, uint32_t n_ctx_min, enum ggml_log_level log_level) { |
| 163 | constexpr int64_t MiB = 1024*1024; |
| 164 | typedef std::vector<llama_device_memory_data> dmds_t; |
| 165 | const llama_model_params default_mparams = llama_model_default_params(); |
| 166 | |
| 167 | std::vector<ggml_backend_dev_t> devs; |
| 168 | uint32_t hp_ngl = 0; // hparams.n_gpu_layers |
| 169 | uint32_t hp_nct = 0; // hparams.n_ctx_train |
| 170 | uint32_t hp_nex = 0; // hparams.n_expert |
| 171 | |
| 172 | // step 1: get data for default parameters and check whether any changes are necessary in the first place |
| 173 | |
| 174 | LLAMA_LOG_DEBUG("%s: getting device memory data for initial parameters:\n", __func__); |
| 175 | const dmds_t dmds_full = llama_get_device_memory_data(path_model, mparams, cparams, devs, hp_ngl, hp_nct, hp_nex, log_level); |
| 176 | const size_t nd = devs.size(); // number of devices |
| 177 | if (nd == 0) { |
| 178 | LLAMA_LOG_INFO("%s: no devices with dedicated memory found\n", __func__); |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | std::vector<int64_t> margins; // this function uses int64_t rather than size_t for memory sizes to more conveniently handle deficits |
| 183 | margins.reserve(nd); |
| 184 | for (size_t id = 0; id < nd; id++) { |
| 185 | margins.push_back(margins_s[id]); |
| 186 | } |
| 187 | |
| 188 | std::vector<std::string> dev_names; |
| 189 | { |
| 190 | dev_names.reserve(nd); |
| 191 | size_t max_length = 0; |
| 192 | for (ggml_backend_dev_t dev : devs) { |
| 193 | std::string name = ggml_backend_dev_name(dev); |
| 194 | name += " ("; |
| 195 | name += ggml_backend_dev_description(dev); |
| 196 | name += ")"; |
| 197 | dev_names.push_back(name); |
| 198 | max_length = std::max(max_length, name.length()); |
| 199 | } |
| 200 | for (std::string & dn : dev_names) { |
| 201 | dn.insert(dn.end(), max_length - dn.length(), ' '); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | int64_t sum_free = 0; |
| 206 | int64_t sum_projected_free = 0; |
| 207 | int64_t sum_projected_used = 0; |
| 208 | int64_t sum_projected_model = 0; |
| 209 | std::vector<int64_t> projected_free_per_device; |
| 210 | projected_free_per_device.reserve(nd); |
| 211 | |
| 212 | if (nd > 1) { |
| 213 | LLAMA_LOG_INFO("%s: projected memory use with initial parameters [MiB]:\n", __func__); |
| 214 | } |
| 215 | for (size_t id = 0; id < nd; id++) { |
| 216 | const llama_device_memory_data & dmd = dmds_full[id]; |
no test coverage detected