@@ -113,13 +113,14 @@ static bool common_speculative_are_compatible(
113113struct common_speculative_state {
114114 const enum common_speculative_type type;
115115
116- // TODO: rename to n_call_draft, n_gen_drafts, n_acc_drafts, n_gen_tokens, n_acc_tokens
117- // TODO: add n_call_begin, n_call_accept
118- size_t drafts_call_count = 0 ; // number of times this implementation was called.
119- size_t drafts_generated_count = 0 ; // number of times a draft or part was generated by this implementation.
120- size_t drafts_accepted_count = 0 ; // number of times a draft or part was accepted by the target model.
121- size_t drafts_generated_tokens = 0 ; // number of tokens generated by this implementation.
122- size_t drafts_accepted_tokens = 0 ; // number of tokens accepted by the target model.
116+ size_t n_call_begin = 0 ; // number of times this implementation was called for refresh.
117+ size_t n_call_draft = 0 ; // number of times this implementation was called for generation.
118+ size_t n_call_accept = 0 ; // number of times this implementation was called for accumulation.
119+
120+ size_t n_gen_drafts = 0 ; // number of times a draft or part was generated by this implementation.
121+ size_t n_acc_drafts = 0 ; // number of times a draft or part was accepted by the target model.
122+ size_t n_gen_tokens = 0 ; // number of tokens generated by this implementation.
123+ size_t n_acc_tokens = 0 ; // number of tokens accepted by the target model.
123124
124125 // TODO: track performance of most recent calls
125126 const bool gen_perf = true ; // whether to generate performance stats.
@@ -465,8 +466,6 @@ struct common_speculative_state_eagle3 : public common_speculative_state {
465466struct common_speculative_state_ngram_simple : public common_speculative_state {
466467 common_ngram_simple_config config;
467468
468- uint16_t check_id = 0 ; // used to control the frequency of generating drafts
469-
470469 common_speculative_state_ngram_simple (
471470 enum common_speculative_type type,
472471 common_ngram_simple_config config)
@@ -481,11 +480,6 @@ struct common_speculative_state_ngram_simple : public common_speculative_state {
481480 const llama_tokens & prompt_tgt,
482481 llama_token id_last,
483482 llama_tokens & result) override {
484- ++check_id;
485- if (check_id < config.check_rate ) {
486- return ;
487- }
488- check_id = 0 ;
489483
490484 result = common_ngram_simple_draft (config, prompt_tgt, id_last);
491485 GGML_UNUSED (params);
@@ -752,10 +746,9 @@ static common_ngram_map get_common_ngram_map(const common_speculative_config & c
752746 uint16_t size_key = config.params .ngram_size_n ;
753747 uint16_t size_value = config.params .ngram_size_m ;
754748 bool key_only = (config.type == COMMON_SPECULATIVE_TYPE_NGRAM_MAP_K );
755- uint16_t check_rate = config.params .ngram_check_rate ;
756749 uint16_t min_hits = config.params .ngram_min_hits ;
757750
758- return common_ngram_map (size_key, size_value, key_only, check_rate, min_hits);
751+ return common_ngram_map (size_key, size_value, key_only, min_hits);
759752}
760753
761754static common_speculative_state_ngram_cache create_state_ngram_cache (
@@ -931,12 +924,10 @@ common_speculative * common_speculative_init(
931924
932925 uint16_t ngram_size_key = ngram_map.size_key ;
933926 uint16_t mgram_size_value = ngram_map.size_value ;
934- uint16_t check_rate = ngram_map.check_rate ;
935927
936928 auto config_simple = common_ngram_simple_config {
937929 /* .size_ngram = */ ngram_size_key,
938- /* .size_mgram = */ mgram_size_value,
939- /* .check_rate = */ check_rate
930+ /* .size_mgram = */ mgram_size_value
940931 };
941932 auto state = std::make_unique<common_speculative_state_ngram_simple>(
942933 /* .type = */ config.type ,
@@ -997,6 +988,7 @@ void common_speculative_begin(common_speculative * spec, const llama_tokens & pr
997988 for (auto & impl : spec->impls ) {
998989 common_time_meas tm (impl->t_begin_us , !impl->gen_perf );
999990 impl->begin (prompt);
991+ impl->n_call_begin ++;
1000992 }
1001993}
1002994
@@ -1013,17 +1005,17 @@ llama_tokens common_speculative_draft(
10131005 {
10141006 common_time_meas tm (impl->t_draft_us , !impl->gen_perf );
10151007 impl->draft (params, prompt_tgt, id_last, result);
1016- impl->drafts_call_count ++;
1008+ impl->n_call_draft ++;
10171009 }
10181010
10191011 if (!result.empty ()) {
10201012 LOG_DBG (" %s: called impl %s, hist size = %zu, call_count = %zu, gen = %zu\n " , __func__,
10211013 common_speculative_type_to_str (impl.get ()->type ).c_str (), prompt_tgt.size (),
1022- impl.get ()->drafts_call_count , result.size ());
1014+ impl.get ()->n_call_draft , result.size ());
10231015
10241016 spec->curr_impl = impl.get (); // set current implementation for stats
1025- impl->drafts_generated_count ++;
1026- impl->drafts_generated_tokens += result.size ();
1017+ impl->n_gen_drafts ++;
1018+ impl->n_gen_tokens += result.size ();
10271019
10281020 break ; // We have a draft, so break out of the loop and return it.
10291021 }
@@ -1044,11 +1036,12 @@ void common_speculative_accept(common_speculative * spec, uint16_t n_accepted) {
10441036 {
10451037 common_time_meas tm (impl->t_accept_us , !impl->gen_perf );
10461038 if (n_accepted > 0 ) {
1047- impl->drafts_accepted_count ++;
1048- impl->drafts_accepted_tokens += n_accepted;
1039+ impl->n_acc_drafts ++;
1040+ impl->n_acc_tokens += n_accepted;
10491041 }
10501042
10511043 impl->accept (n_accepted);
1044+ impl->n_call_accept ++;
10521045 }
10531046}
10541047
@@ -1069,13 +1062,13 @@ void common_speculative_print_stats(const common_speculative * spec) {
10691062 str_perf = " " ;
10701063 }
10711064
1072- LOG_INF (" statistics %s: #calls = %zu, #gen drafts = %zu, #acc drafts = %zu, #gen tokens = %zu, #acc tokens = %zu%s\n " ,
1065+ LOG_INF (" statistics %s: #calls(b,g,a) = %zu %zu %zu, #gen drafts = %zu, #acc drafts = %zu, #gen tokens = %zu, #acc tokens = %zu%s\n " ,
10731066 common_speculative_type_to_str (impl->type ).c_str (),
1074- impl->drafts_call_count ,
1075- impl->drafts_generated_count ,
1076- impl->drafts_accepted_count ,
1077- impl->drafts_generated_tokens ,
1078- impl->drafts_accepted_tokens ,
1067+ impl->n_call_begin , impl-> n_call_draft , impl-> n_call_accept ,
1068+ impl->n_gen_drafts ,
1069+ impl->n_acc_drafts ,
1070+ impl->n_gen_tokens ,
1071+ impl->n_acc_tokens ,
10791072 str_perf.c_str ());
10801073 }
10811074}
0 commit comments