char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
5594d1322
char/aliceai-t5-moe
1#include "arg.h" 2#include "common.h" 3#include "debug.h" 4#include "log.h" 5#include "llama.h" 6 7#include <clocale> 8#include <string> 9#include <vector> 10 11static bool run (llama_context * ctx ,const common_params & params ) { 12const llama_model * model = llama_get_model (ctx ); 13const llama_vocab * vocab = llama_model_get_vocab (model ); 14 15const bool add_bos = llama_vocab_get_add_bos (vocab ); 16 17 std::vector < llama_token > tokens = common_tokenize (ctx ,params .prompt ,add_bos , true); 18 19if (tokens .empty ()) { 20LOG_ERR ("%s : there are not input tokens to process - (try to provide a prompt with '-p')\n" ,__func__ ); 21return false; 22 } 23 24LOG_INF ("number of input tokens = %zu\n" ,tokens .size ()); 25for (size_t i = 0 ;i < tokens .size ();++ i ) { 26LOG_INF (" %d\n" ,tokens [i ]); 27 } 28 29if (llama_decode (ctx ,llama_batch_get_one (tokens .data (),tokens .size ()))) { 30LOG_ERR ("%s : failed to eval\n" ,__func__ ); 31return false; 32 } 33 34return true; 35} 36 37int main (int argc ,char ** argv ) { 38 std::setlocale (LC_NUMERIC ,"C" ); 39 40common_debug_cb_user_data cb_data ; 41 42common_params params ; 43 44common_init (); 45 46if (!common_params_parse (argc ,argv ,params ,LLAMA_EXAMPLE_COMMON )) { 47return 1 ; 48 } 49 50llama_backend_init (); 51llama_numa_init (params .numa ); 52 53// pass the callback to the backend scheduler 54// it will be executed for each node during the graph computation 55params .cb_eval = common_debug_cb_eval ; 56params .cb_eval_user_data = & cb_data ; 57params .warmup = false; 58 59// init 60auto llama_init = common_init_from_params (params ); 61 62auto * model = llama_init -> model (); 63auto * ctx = llama_init -> context (); 64 65if (model == nullptr || ctx == nullptr ) { 66LOG_ERR ("%s : failed to init\n" ,__func__ ); 67return 1 ; 68 } 69 70// print system information 71 { 72LOG_INF ("\n" ); 73LOG_INF ("%s\n" ,common_params_get_system_info (params ).c_str ()); 74LOG_INF ("\n" ); 75 } 76 77bool OK = run (ctx ,params ); 78if (!OK ) { 79return 1 ; 80 } 81 82LOG ("\n" ); 83llama_perf_context_print (ctx ); 84 85llama_backend_free (); 86 87return 0 ; 88}