Skip to content

Commit 76c7398

Browse files
committed
Use the initial value of params.seed to determine if user supplied seed
Display some helpful information to the user when loading a session to make it clear when the seed applies or not.
1 parent e1ec489 commit 76c7398

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

examples/main/main.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ int main(int argc, char ** argv) {
8585

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

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

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

0 commit comments

Comments
 (0)