MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / main

Function main

examples/speculative/speculative.cpp:25–457  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23};
24
25int main(int argc, char ** argv) {
26 gpt_params params;
27
28 if (gpt_params_parse(argc, argv, params) == false) {
29 return 1;
30 }
31
32 if (params.model_draft.empty()) {
33 fprintf(stderr, "%s: error: --model-draft is required\n", __func__);
34 return 1;
35 }
36
37 // max number of parallel drafting sequences (i.e. tree branches)
38 const int n_seq_dft = params.n_parallel;
39
40 // probability threshold for accepting a token from the draft model
41 const float p_accept = params.p_accept;
42
43 // probability threshold for splitting a draft branch (only for n_seq_dft > 1)
44 const float p_split = params.p_split;
45
46#ifndef LOG_DISABLE_LOGS
47 log_set_target(log_filename_generator("speculative", "log"));
48 LOG_TEE("Log start\n");
49 log_dump_cmdline(argc, argv);
50#endif // LOG_DISABLE_LOGS
51
52 // init llama.cpp
53 llama_backend_init(params.numa);
54
55 llama_model * model_tgt = NULL;
56 llama_model * model_dft = NULL;
57
58 llama_context * ctx_tgt = NULL;
59 llama_context * ctx_dft = NULL;
60
61 // load the target model
62 params.logits_all = true;
63 std::tie(model_tgt, ctx_tgt) = llama_init_from_gpt_params(params);
64
65 // load the draft model
66 params.model = params.model_draft;
67 params.n_gpu_layers = params.n_gpu_layers_draft;
68 std::tie(model_dft, ctx_dft) = llama_init_from_gpt_params(params);
69
70 {
71 const int n_vocab_tgt = llama_n_vocab(model_tgt);
72 const int n_vocab_dft = llama_n_vocab(model_dft);
73 const int vocab_diff = n_vocab_tgt > n_vocab_dft
74 ? n_vocab_tgt - n_vocab_dft
75 : n_vocab_dft - n_vocab_tgt;
76
77 if (vocab_diff > SPEC_VOCAB_MAX_SIZE_DIFFERENCE) {
78 fprintf(stderr, "%s: error: draft model vocab must closely match target model to use speculation but ", __func__);
79 fprintf(stderr, "target vocab size %d does not match draft vocab size %d - difference %d, max allowed %d\n",
80 n_vocab_tgt, llama_n_vocab(model_dft), vocab_diff, SPEC_VOCAB_MAX_SIZE_DIFFERENCE);
81 return 1;
82 }

Callers

nothing calls this directly

Calls 15

gpt_params_parseFunction · 0.85
fprintfFunction · 0.85
minFunction · 0.85
llama_sampling_initFunction · 0.85
LOG_TOKENS_TOSTR_PRETTYFunction · 0.85
llama_sampling_sampleFunction · 0.85
llama_sampling_acceptFunction · 0.85
printfFunction · 0.85
llama_kv_cache_seq_keepFunction · 0.85
llama_kv_cache_seq_cpFunction · 0.85
llama_kv_cache_seq_rmFunction · 0.85

Tested by

no test coverage detected