@@ -26,7 +26,7 @@ class common_params_fit_exception : public std::runtime_error {
2626 using std::runtime_error::runtime_error;
2727};
2828
29- std::vector<llama_device_memory_data> common_get_device_memory_data (
29+ static std::vector<llama_device_memory_data> common_get_device_memory_data_impl (
3030 const char * path_model,
3131 const llama_model_params * mparams,
3232 const llama_context_params * cparams,
@@ -150,6 +150,29 @@ std::vector<llama_device_memory_data> common_get_device_memory_data(
150150 return ret;
151151}
152152
153+ common_device_memory_data_vec common_get_device_memory_data (
154+ const char * path_model,
155+ const llama_model_params * mparams,
156+ const llama_context_params * cparams,
157+ std::vector<ggml_backend_dev_t > & devs,
158+ uint32_t & hp_ngl,
159+ uint32_t & hp_n_ctx_train,
160+ uint32_t & hp_n_expert,
161+ ggml_log_level log_level) {
162+ std::vector<llama_device_memory_data> impl = common_get_device_memory_data_impl (
163+ path_model, mparams, cparams, devs, hp_ngl, hp_n_ctx_train, hp_n_expert, log_level);
164+
165+ common_device_memory_data_vec ret (impl.size ());
166+ for (size_t i = 0 ; i < impl.size (); i++) {
167+ ret[i].total = impl[i].total ;
168+ ret[i].free = impl[i].free ;
169+ ret[i].model = impl[i].mb .model ;
170+ ret[i].context = impl[i].mb .context ;
171+ ret[i].compute = impl[i].mb .compute ;
172+ }
173+ return ret;
174+ }
175+
153176static void common_params_fit_impl (
154177 const char * path_model, struct llama_model_params * mparams, struct llama_context_params * cparams,
155178 float * tensor_split, struct llama_model_tensor_buft_override * tensor_buft_overrides,
@@ -169,7 +192,7 @@ static void common_params_fit_impl(
169192 // step 1: get data for default parameters and check whether any changes are necessary in the first place
170193
171194 LOG_TRC (" %s: getting device memory data for initial parameters:\n " , __func__);
172- const dmds_t dmds_full = common_get_device_memory_data (path_model, mparams, cparams, devs, hp_ngl, hp_nct, hp_nex, log_level);
195+ const dmds_t dmds_full = common_get_device_memory_data_impl (path_model, mparams, cparams, devs, hp_ngl, hp_nct, hp_nex, log_level);
173196 const size_t nd = devs.size (); // number of devices
174197
175198 std::vector<int64_t > margins; // this function uses int64_t rather than size_t for memory sizes to more conveniently handle deficits
@@ -304,7 +327,7 @@ static void common_params_fit_impl(
304327
305328 int64_t sum_projected_used_min_ctx = 0 ;
306329 cparams->n_ctx = n_ctx_min;
307- const dmds_t dmds_min_ctx = common_get_device_memory_data (path_model, mparams, cparams, devs, hp_ngl, hp_nct, hp_nex, log_level);
330+ const dmds_t dmds_min_ctx = common_get_device_memory_data_impl (path_model, mparams, cparams, devs, hp_ngl, hp_nct, hp_nex, log_level);
308331 if (nd == 0 ) {
309332 sum_projected_used_min_ctx = dmds_min_ctx.back ().mb .total ();
310333 } else {
@@ -482,7 +505,7 @@ static void common_params_fit_impl(
482505 llama_model_params mparams_copy = *mparams;
483506 set_ngl_tensor_split_tbo (ngl_per_device, overflow_bufts, mparams_copy);
484507
485- const dmds_t dmd_nl = common_get_device_memory_data (
508+ const dmds_t dmd_nl = common_get_device_memory_data_impl (
486509 path_model, &mparams_copy, cparams, devs, hp_ngl, hp_nct, hp_nex, log_level);
487510
488511 LOG_TRC (" %s: memory for test allocation by device:\n " , func_name);
@@ -510,7 +533,7 @@ static void common_params_fit_impl(
510533 mparams->tensor_buft_overrides = tensor_buft_overrides;
511534
512535 LOG_TRC (" %s: getting device memory data with all MoE tensors moved to system memory:\n " , __func__);
513- const dmds_t dmds_cpu_moe = common_get_device_memory_data (
536+ const dmds_t dmds_cpu_moe = common_get_device_memory_data_impl (
514537 path_model, mparams, cparams, devs, hp_ngl, hp_nct, hp_nex, log_level);
515538
516539 for (size_t id = 0 ; id < nd; id++) {
@@ -940,7 +963,7 @@ void common_fit_print(
940963 uint32_t hp_nct = 0 ; // hparams.n_ctx_train
941964 uint32_t hp_nex = 0 ; // hparams.n_expert
942965
943- auto dmd = common_get_device_memory_data (path_model, mparams, cparams, devs, hp_ngl, hp_nct, hp_nex, GGML_LOG_LEVEL_ERROR );
966+ auto dmd = common_get_device_memory_data_impl (path_model, mparams, cparams, devs, hp_ngl, hp_nct, hp_nex, GGML_LOG_LEVEL_ERROR );
944967 GGML_ASSERT (dmd.size () == devs.size () + 1 );
945968
946969 for (size_t id = 0 ; id < devs.size (); id++) {
0 commit comments