Skip to content

Commit

Permalink
Use the initial value of params.seed to determine if user supplied seed
Browse files Browse the repository at this point in the history
Display some helpful information to the user when loading a session to make it clear when the seed applies or not.
  • Loading branch information
KerfuffleV2 committed May 24, 2023
1 parent 41530b6 commit 918cec5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion examples/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ int main(int argc, char ** argv) {

fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT);

// Save the initial seed parameter before overwriting it so it's possible to determine whether
// the user supplied a seed or not. This is useful when loading saved sessions.
int32_t initial_seed = params.seed;
if (params.seed < 0) {
params.seed = time(NULL);
}
Expand Down Expand Up @@ -153,8 +156,11 @@ int main(int argc, char ** argv) {
return 1;
}
session_tokens.resize(n_token_count_out);
if (params.seed != -1) {
if (initial_seed != -1) {
fprintf(stderr, "%s: seed argument overrides session file RNG state, will now use seed: %d\n", __func__, params.seed);
llama_set_rng_seed(ctx, params.seed);
} else {
fprintf(stderr, "%s: using RNG state from loaded session file rather than seed\n", __func__);
}

fprintf(stderr, "%s: loaded a session with prompt size of %d tokens\n", __func__, (int) session_tokens.size());
Expand Down

0 comments on commit 918cec5

Please sign in to comment.