Skip to content

Commit 41d04bc

Browse files
committed
compact dynatemp into a single value dynatemp_range. This is a float which represents the allowed deviation from the min and max temperature when using dynatemp. Thus, if we want a value of dynatemp_min=0.3, dynatemp_max=0.5, then we would simply set temperature=0.4 and dynatemp_range=0.1. Functionally dynatemp would operate the same, but it would simplify usage and make it a single easy to adjust value.
1 parent 79aeadf commit 41d04bc

8 files changed

+38
-89
lines changed

common/common.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ struct gpt_params {
8282
float mirostat_eta = 0.10f; // learning rate
8383

8484
// DynaTemp!
85-
bool dynatemp = false; // enable DynaTemp
86-
float min_temp = 0.00f; // minimum temperature
87-
float max_temp = 2.00f; // maximum temperature
85+
float dynatemp_range = 0.0f; // enables DynaTemp if greater than 0. dynatemp_min = temperature - dt_range, dynatemp_max = temperature + dt_range
8886

8987
// // sampling parameters
9088
struct llama_sampling_params sparams;

common/sampling.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ typedef struct llama_sampling_params {
2525
int32_t mirostat = 0; // 0 = disabled, 1 = mirostat, 2 = mirostat 2.0
2626
float mirostat_tau = 5.00f; // target entropy
2727
float mirostat_eta = 0.10f; // learning rate
28-
bool dynatemp = false; // dynamic temperature
29-
float min_temp = 0.00f; // minimum temperature
30-
float max_temp = 2.00f; // maximum temperature
28+
bool dynatemp_range = 0.00f; // dynamic temperature range
3129
bool penalize_nl = true; // consider newlines as a repeatable token
3230
std::string samplers_sequence = "kfypmt"; // top_k, tail_free, typical_p, top_p, min_p, temp
3331

expose.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ struct generation_inputs
8181
const char * grammar;
8282
const bool grammar_retain_state;
8383
const bool quiet = false;
84-
const bool dynatemp = false;
85-
const float min_temp;
86-
const float max_temp;
84+
const float dynatemp_range = 0.0f;
8785
const logit_bias logit_biases[logit_bias_max];
8886

8987
};

gpttype_adapter.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ void sample_grammar(FileFormat file_format, int32_t n_vocab, llama_token_data_ar
481481
}
482482

483483
int SampleLogits(const float * logits, int n_ctx, int n_vocab, int rep_pen_range, float rep_pen, float presence_penalty, float top_k, float top_a, float top_p, float min_p, float typical_p, float tfs, float temp, std::mt19937 & rng,
484-
int mirostat, float mirostat_tau, float mirostat_eta, const std::vector<samplers> & sampler_order, llama_grammar * grammar, bool dynatemp, float min_temp, float max_temp)
484+
int mirostat, float mirostat_tau, float mirostat_eta, const std::vector<samplers> & sampler_order, llama_grammar * grammar, float dynatemp_range)
485485
{
486486
int id = 0;
487487
std::vector<llama_token_data> candidates;
@@ -540,9 +540,14 @@ int mirostat, float mirostat_tau, float mirostat_eta, const std::vector<samplers
540540
llama_sample_typical(nullptr, &candidates_p, typical_p,1);
541541
break;
542542
case KCPP_SAMPLER_TEMP:
543-
if (dynatemp)
543+
if (dynatemp_range>0)
544544
{
545-
llama_sample_entropy(nullptr, &candidates_p, temp, min_temp, max_temp);
545+
float dynatemp_min = temp - dynatemp_range;
546+
float dynatemp_max = temp + dynatemp_range;
547+
//do not allow negative values
548+
dynatemp_min = dynatemp_min<0?0:dynatemp_min;
549+
dynatemp_max = dynatemp_max<0?0:dynatemp_max;
550+
llama_sample_entropy(nullptr, &candidates_p, temp, dynatemp_min, dynatemp_max);
546551
}
547552
else
548553
{
@@ -1502,9 +1507,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs, generation_o
15021507
kcpp_params->mirostat = inputs.mirostat;
15031508
kcpp_params->mirostat_eta = inputs.mirostat_eta;
15041509
kcpp_params->mirostat_tau = inputs.mirostat_tau;
1505-
kcpp_params->dynatemp = inputs.dynatemp;
1506-
kcpp_params->min_temp = inputs.min_temp;
1507-
kcpp_params->max_temp = inputs.max_temp;
1510+
kcpp_params->dynatemp_range = inputs.dynatemp_range;
15081511
kcpp_params->n_ctx = inputs.max_context_length;
15091512
kcpp_params->n_batch = n_batch;
15101513
kcpp_params->n_threads = n_threads;
@@ -1900,9 +1903,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs, generation_o
19001903
const float presence_penalty = kcpp_params->presence_penalty;
19011904
const float typical_p = kcpp_params->typical_p;
19021905
const float tfs_z = kcpp_params->tfs_z;
1903-
const float dynatemp = kcpp_params->dynatemp;
1904-
const float min_temp = kcpp_params->min_temp;
1905-
const float max_temp = kcpp_params->max_temp;
1906+
const float dynatemp_range = kcpp_params->dynatemp_range;
19061907

19071908
if (!startedsampling)
19081909
{
@@ -1958,7 +1959,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs, generation_o
19581959

19591960
id = SampleLogits(logitsPtr, nctx, n_vocab, last_n_size, repeat_penalty, presence_penalty,
19601961
top_k, top_a, top_p, min_p, typical_p, tfs_z, temp, rng,
1961-
kcpp_params->mirostat, kcpp_params->mirostat_tau, kcpp_params->mirostat_eta, sampler_order, grammar, dynatemp, min_temp, max_temp);
1962+
kcpp_params->mirostat, kcpp_params->mirostat_tau, kcpp_params->mirostat_eta, sampler_order, grammar, dynatemp_range);
19621963

19631964
if (grammar != nullptr) {
19641965
grammar_accept_token(file_format, n_vocab, grammar, id);

kcpp_docs.embd

+3-12
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,9 @@
139139
"description": "If true, prevents the EOS token from being generated (Ban EOS). For unbantokens, set this to false.",
140140
"type": "boolean"
141141
},
142-
"dynatemp": {
143-
"default": false,
144-
"description": "If true, uses dynamic temperature. If false, uses static temperature.",
145-
"type": "boolean"
146-
},
147-
"min_temp": {
148-
"description": "Dynatemp Minimum temperature value.",
149-
"exclusiveMinimum": 0,
150-
"type": "number"
151-
},
152-
"max_temp": {
153-
"description": "Maximum temperature value.",
142+
"dynatemp_range": {
143+
"default": 0,
144+
"description": "If greater than 0, uses dynamic temperature. Dynamic temperature range will be between Temp+Range and Temp-Range. If less or equal to 0 , uses static temperature.",
154145
"exclusiveMinimum": 0,
155146
"type": "number"
156147
},

0 commit comments

Comments
 (0)