forked from ggerganov/llama.cpp
-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Full DynaTemp implementation + UI #600
Merged
LostRuins
merged 21 commits into
LostRuins:concedo_experimental
from
kalomaze:dynatemp-pr-upstream
Jan 6, 2024
Merged
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2b476d4
move Dynatemp changes to new branch
kalomaze c4b4781
fix float header
kalomaze b983ae0
Properly reintroduce variable expert count
kalomaze b8551b4
first pass at DynaTemp UI
AAbushady 1d0dec4
DynaTemp UI Checkbox
AAbushady 8cf96ff
DynaTemp UI checkbox edition
AAbushady 7f11b7e
DynaTemp UI integration
kalomaze 303a32e
Remove greedy dynatemp
kalomaze 77e0f6c
Fix race condition caused by debug print
kalomaze 69e293c
Fixed broken presets and miro
AAbushady ce2e738
Merge pull request #11 from AAbushady/dynatemp-mainline
kalomaze c2d14ab
Remove debug function + HHI temp
kalomaze b753bb4
Merge branch 'dynatemp-pr-upstream' into dynatemp-mainline
kalomaze 351262a
Fix whitespace (?) for generate function
kalomaze 1470209
epic upstream renaming scheme fix
kalomaze 597f80d
fix stupid indents
kalomaze a4f8ff4
Other cleanup
kalomaze 1d9c9b5
Slight indent fix
kalomaze f61a441
revert batch pyinstaller maker to mainline
kalomaze 79aeadf
Merge Dynamic Temp UI + cleanups into dynatemp-pr-upstream
kalomaze 41d04bc
compact dynatemp into a single value dynatemp_range. This is a float …
LostRuins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -481,7 +481,7 @@ void sample_grammar(FileFormat file_format, int32_t n_vocab, llama_token_data_ar | |
} | ||
|
||
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, | ||
int mirostat, float mirostat_tau, float mirostat_eta, const std::vector<samplers> & sampler_order, llama_grammar * grammar) | ||
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) | ||
{ | ||
int id = 0; | ||
std::vector<llama_token_data> candidates; | ||
|
@@ -540,7 +540,14 @@ int mirostat, float mirostat_tau, float mirostat_eta, const std::vector<samplers | |
llama_sample_typical(nullptr, &candidates_p, typical_p,1); | ||
break; | ||
case KCPP_SAMPLER_TEMP: | ||
sample_temperature(&candidates_p, temp); | ||
if (dynatemp) | ||
{ | ||
llama_sample_entropy(nullptr, &candidates_p, temp, min_temp, max_temp); | ||
} | ||
else | ||
{ | ||
sample_temperature(&candidates_p, temp); | ||
} | ||
break; | ||
case KCPP_SAMPLER_REP_PEN: | ||
sample_rep_pen(n_ctx, rep_pen_range, rep_pen, presence_penalty, &candidates_p); | ||
|
@@ -1479,6 +1486,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs, generation_o | |
} | ||
|
||
std::string addedmemory = inputs.memory; | ||
|
||
kcpp_params->prompt = inputs.prompt; | ||
kcpp_params->seed = inputs.seed; | ||
kcpp_params->n_predict = inputs.max_length; | ||
|
@@ -1494,10 +1502,14 @@ generation_outputs gpttype_generate(const generation_inputs inputs, generation_o | |
kcpp_params->mirostat = inputs.mirostat; | ||
kcpp_params->mirostat_eta = inputs.mirostat_eta; | ||
kcpp_params->mirostat_tau = inputs.mirostat_tau; | ||
kcpp_params->dynatemp = inputs.dynatemp; | ||
kcpp_params->min_temp = inputs.min_temp; | ||
kcpp_params->max_temp = inputs.max_temp; | ||
kcpp_params->n_ctx = inputs.max_context_length; | ||
kcpp_params->n_batch = n_batch; | ||
kcpp_params->n_threads = n_threads; | ||
kcpp_params->n_threads_batch = n_blasthreads; | ||
|
||
bool stream_sse = inputs.stream_sse; | ||
|
||
bool allow_regular_prints = (debugmode!=-1 && !inputs.quiet) || debugmode >= 1; | ||
|
@@ -1888,6 +1900,9 @@ generation_outputs gpttype_generate(const generation_inputs inputs, generation_o | |
const float presence_penalty = kcpp_params->presence_penalty; | ||
const float typical_p = kcpp_params->typical_p; | ||
const float tfs_z = kcpp_params->tfs_z; | ||
const float dynatemp = kcpp_params->dynatemp; | ||
const float min_temp = kcpp_params->min_temp; | ||
const float max_temp = kcpp_params->max_temp; | ||
|
||
if (!startedsampling) | ||
{ | ||
|
@@ -1943,7 +1958,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs, generation_o | |
|
||
id = SampleLogits(logitsPtr, nctx, n_vocab, last_n_size, repeat_penalty, presence_penalty, | ||
top_k, top_a, top_p, min_p, typical_p, tfs_z, temp, rng, | ||
kcpp_params->mirostat, kcpp_params->mirostat_tau, kcpp_params->mirostat_eta, sampler_order, grammar); | ||
kcpp_params->mirostat, kcpp_params->mirostat_tau, kcpp_params->mirostat_eta, sampler_order, grammar, dynatemp, min_temp, max_temp); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @LostRuins Not related to this PR but it feels like kcpp_params should just be passed in instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, will probably refactor it soon. |
||
|
||
if (grammar != nullptr) { | ||
grammar_accept_token(file_format, n_vocab, grammar, id); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the first thing that stands out first is - I don't think a bool for toggling dynatemp is necessary. I think this can be simplified and there are 2 very good ways of doing it.
First way is to make it part of the sampler, so having
dynatemp_min
anddynatemp_max
both be 0 would leave dynatemp inactive, otherwise it would be active and applied (overriding temperature). That puts it in line with all other samplers that have an "inactive" value and an "active" value.The second option which I am strongly in support is 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 settemperature=0.4
anddynatemp_range=0.1
If you want a
dynatemp_min=0.8, dynatemp_max=2.0
, then you settemperature=1.4
anddynatemp_range=0.6
.It will work for any value of min and max
To disable, set
dynatemp_range=0
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea and it's nicely intuitive.