Skip to content

Commit 8f961ab

Browse files
committed
speculative : change default p_accept to 0.5 + CLI args (#3919)
ggml-ci
1 parent 0581602 commit 8f961ab

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

common/common.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,18 @@ bool gpt_params_parse_ex(int argc, char ** argv, gpt_params & params) {
403403
break;
404404
}
405405
params.n_sequences = std::stoi(argv[i]);
406+
} else if (arg == "--p-accept" || arg == "-pa") {
407+
if (++i >= argc) {
408+
invalid_param = true;
409+
break;
410+
}
411+
params.p_accept = std::stof(argv[i]);
412+
} else if (arg == "--p-split" || arg == "-ps") {
413+
if (++i >= argc) {
414+
invalid_param = true;
415+
break;
416+
}
417+
params.p_split = std::stof(argv[i]);
406418
} else if (arg == "-m" || arg == "--model") {
407419
if (++i >= argc) {
408420
invalid_param = true;
@@ -778,6 +790,8 @@ void gpt_print_usage(int /*argc*/, char ** argv, const gpt_params & params) {
778790
printf(" --chunks N max number of chunks to process (default: %d, -1 = all)\n", params.n_chunks);
779791
printf(" -np N, --parallel N number of parallel sequences to decode (default: %d)\n", params.n_parallel);
780792
printf(" -ns N, --sequences N number of sequences to decode (default: %d)\n", params.n_sequences);
793+
printf(" -pa N, --p-accept N speculative decoding accept probability (default: %.1f)\n", (double)params.p_accept);
794+
printf(" -ps N, --p-split N speculative decoding split probability (default: %.1f)\n", (double)params.p_split);
781795
printf(" -cb, --cont-batching enable continuous batching (a.k.a dynamic batching) (default: disabled)\n");
782796
printf(" --mmproj MMPROJ_FILE path to a multimodal projector file for LLaVA. see examples/llava/README.md\n");
783797
printf(" --image IMAGE_FILE path to an image file. use with multimodal models\n");

common/common.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ int32_t get_num_physical_cores();
4444

4545
struct gpt_params {
4646
uint32_t seed = -1; // RNG seed
47+
4748
int32_t n_threads = get_num_physical_cores();
4849
int32_t n_threads_batch = -1; // number of threads to use for batch processing (-1 = use n_threads)
4950
int32_t n_predict = -1; // new tokens to predict
@@ -54,6 +55,8 @@ struct gpt_params {
5455
int32_t n_chunks = -1; // max number of chunks to process (-1 = unlimited)
5556
int32_t n_parallel = 1; // number of parallel sequences to decode
5657
int32_t n_sequences = 1; // number of sequences to decode
58+
float p_accept = 0.5f; // speculative decoding accept probability
59+
float p_split = 0.1f; // speculative decoding split probability
5760
int32_t n_gpu_layers = -1; // number of layers to store in VRAM (-1 - use default)
5861
int32_t n_gpu_layers_draft = -1; // number of layers to store in VRAM for the draft model (-1 - use default)
5962
int32_t main_gpu = 0; // the GPU that is used for scratch and small tensors
@@ -66,7 +69,8 @@ struct gpt_params {
6669
float yarn_beta_fast = 32.0f; // YaRN low correction dim
6770
float yarn_beta_slow = 1.0f; // YaRN high correction dim
6871
int32_t yarn_orig_ctx = 0; // YaRN original context length
69-
int8_t rope_scaling_type = LLAMA_ROPE_SCALING_UNSPECIFIED;
72+
int8_t rope_scaling_type = LLAMA_ROPE_SCALING_UNSPECIFIED; // TODO: better to be int32_t for alignment
73+
// pinging @cebtenzzre
7074

7175
// // sampling parameters
7276
struct llama_sampling_params sparams;
@@ -90,7 +94,7 @@ struct gpt_params {
9094
int ppl_output_type = 0; // = 0 -> ppl output is as usual, = 1 -> ppl output is num_tokens, ppl, one per line
9195
// (which is more convenient to use for plotting)
9296
//
93-
bool hellaswag = false; // compute HellaSwag score over random tasks from datafile supplied in prompt
97+
bool hellaswag = false; // compute HellaSwag score over random tasks from datafile supplied in prompt
9498
size_t hellaswag_tasks = 400; // number of tasks to use when computing the HellaSwag score
9599

96100
bool mul_mat_q = true; // if true, use mul_mat_q kernels instead of cuBLAS

examples/speculative/speculative.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ int main(int argc, char ** argv) {
3737
// max number of parallel drafting sequences (i.e. tree branches)
3838
const int n_seq_dft = params.n_parallel;
3939

40-
// TODO: make this configurable
41-
const float p_accept = 0.80f;
42-
const float p_split = 0.10f;
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;
4345

4446
#ifndef LOG_DISABLE_LOGS
4547
log_set_target(log_filename_generator("speculative", "log"));

0 commit comments

Comments
 (0)