char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
2fb989b9e
char/aliceai-t5-moe
1#include "llama.h" 2#include "../src/llama-ext.h" 3 4#include "arg.h" 5#include "common.h" 6#include "fit.h" 7#include "log.h" 8 9#include <cinttypes> 10 11#if defined(_MSC_VER ) 12#pragma warning(disable: 4244 4267) // possible loss of data 13#endif 14 15// satisfies -Wmissing-declarations 16int llama_fit_params (int argc ,char ** argv ); 17 18int llama_fit_params (int argc ,char ** argv ) { 19common_params params ; 20 21common_init (); 22 23if (!common_params_parse (argc ,argv ,params ,LLAMA_EXAMPLE_FIT_PARAMS )) { 24return 1 ; 25 } 26 27llama_backend_init (); 28llama_numa_init (params .numa ); 29 30auto mparams = common_model_params_to_llama (params ); 31auto cparams = common_context_params_to_llama (params ); 32 33if (!params .fit_params_print ) { 34const common_params_fit_status status = common_fit_params (params .model .path .c_str (),& mparams ,& cparams , 35params .tensor_split ,params .tensor_buft_overrides .data (),params .fit_params_target .data (),params .fit_params_min_ctx , 36nullptr , 37params .verbosity >=LOG_LEVEL_DEBUG ?GGML_LOG_LEVEL_DEBUG :GGML_LOG_LEVEL_ERROR ); 38if (status != COMMON_PARAMS_FIT_STATUS_SUCCESS ) { 39LOG_ERR ("%s: failed to fit CLI arguments to free memory, exiting...\n" ,__func__ ); 40exit (1 ); 41 } 42 43LOG_INF ("%s: printing fitted CLI arguments to stdout...\n" ,__func__ ); 44common_log_flush (common_log_main ()); 45printf ("-c %" PRIu32 " -ngl %" PRIi32 ,cparams .n_ctx ,mparams .n_gpu_layers ); 46 47size_t nd = llama_max_devices (); 48while (nd > 1 && mparams .tensor_split [nd - 1 ]== 0.0f ) { 49nd -- ; 50 } 51if (nd > 1 ) { 52for (size_t id = 0 ;id < nd ;id ++ ) { 53if (id == 0 ) { 54printf (" -ts " ); 55 } 56printf ("%s%" PRIu32 ,id > 0 ?"," :"" ,uint32_t (mparams .tensor_split [id ])); 57 } 58 } 59 60const size_t ntbo = llama_max_tensor_buft_overrides (); 61bool any_tbo = false; 62for (size_t itbo = 0 ;itbo < ntbo && mparams .tensor_buft_overrides [itbo ].pattern != nullptr ;itbo ++ ) { 63if (itbo == 0 ) { 64printf (" -ot \"" ); 65 } 66printf ("%s%s=%s" ,itbo > 0 ?"," :"" ,mparams .tensor_buft_overrides [itbo ].pattern ,ggml_backend_buft_name (mparams .tensor_buft_overrides [itbo ].buft )); 67any_tbo = true; 68 } 69printf ("%s\n" ,any_tbo ?"\"" :"" ); 70 }else { 71LOG_INF ("%s: printing estimated memory in MiB to stdout (device, model, context, compute) ...\n" ,__func__ ); 72common_log_flush (common_log_main ()); 73 74common_fit_print (params .model .path .c_str (),& mparams ,& cparams ); 75 } 76 77return 0 ; 78}