char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
2fb989b9e
char/aliceai-t5-moe
1#pragma once 2 3#include "ggml.h" 4#include "llama.h" 5 6#include <vector> 7 8enum common_params_fit_status { 9COMMON_PARAMS_FIT_STATUS_SUCCESS = 0 ,// found allocations that are projected to fit 10COMMON_PARAMS_FIT_STATUS_FAILURE = 1 ,// could not find allocations that are projected to fit 11COMMON_PARAMS_FIT_STATUS_ERROR = 2 ,// a hard error occurred, e.g. because no model could be found at the specified path 12}; 13 14// a second model that shares the devices of the main model, e.g. a draft model 15// - its context follows the context of the main model, so its memory is measured again whenever that context changes 16// - shares_model tells the fit that the weights are already counted in the main model, as for an MTP context 17struct common_fit_extra_model { 18const char * path_model ; 19llama_model_params * mparams ; 20llama_context_params * cparams ; 21bool shares_model ; 22}; 23 24// fits mparams and cparams to free device memory (assumes system memory is unlimited) 25// - returns true if the parameters could be successfully modified to fit device memory 26// - this function is NOT thread safe because it modifies the global llama logger state 27// - only parameters that have the same value as in llama_default_model_params are modified 28// with the exception of the context size which is modified if and only if equal to 0 29common_params_fit_status common_fit_params ( 30const char * path_model , 31llama_model_params * mparams , 32llama_context_params * cparams , 33float * tensor_split ,// writable buffer for tensor split, needs at least llama_max_devices elements 34llama_model_tensor_buft_override * tensor_buft_overrides ,// writable buffer for overrides, needs at least llama_max_tensor_buft_overrides elements 35size_t * margins ,// margins of memory to leave per device in bytes 36uint32_t n_ctx_min ,// minimum context size to set when trying to reduce memory use 37const common_fit_extra_model * extra ,// model to fit alongside the main one, nullptr if there is none 38ggml_log_level log_level );// minimum log level to print during fitting, lower levels go to debug log 39 40// print estimated memory to stdout 41void common_fit_print ( 42const char * path_model , 43llama_model_params * mparams , 44llama_context_params * cparams ); 45 46void common_memory_breakdown_print (const llama_context * ctx ); 47 48struct common_device_memory_data { 49int64_t total ; 50int64_t free ; 51size_t model ; 52size_t context ; 53size_t compute ; 54}; 55 56using common_device_memory_data_vec = std ::vector < common_device_memory_data > ; 57 58// Load a model + context with no_alloc and return the per-device memory breakdown. 59common_device_memory_data_vec common_get_device_memory_data ( 60const char * path_model , 61const llama_model_params * mparams , 62const llama_context_params * cparams , 63std ::vector < ggml_backend_dev_t > & devs , 64uint32_t & hp_ngl , 65uint32_t & hp_n_ctx_train , 66uint32_t & hp_n_expert , 67ggml_log_level log_level );