Skip to content

Commit db8dee5

Browse files
ikawrakowIwan Kawrakow
andauthored
Do not crash when there is no DRY sampler (#578)
Co-authored-by: Iwan Kawrakow <[email protected]>
1 parent ab22474 commit db8dee5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

common/sampling.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct llama_sampling_context * llama_sampling_init(const struct llama_vocab* vo
5555
c_breakers.push_back(str.c_str());
5656
}
5757
result->smpl=llama_sampler_init_dry(vocab, params.dry_multiplier, params.dry_base, params.dry_allowed_length, params.dry_penalty_last_n, c_breakers.data(), c_breakers.size());
58-
58+
5959
break;
6060
}
6161
default:
@@ -502,5 +502,7 @@ void llama_sampling_accept(
502502
if (ctx_sampling->grammar != NULL && apply_grammar) {
503503
llama_grammar_accept_token(ctx_sampling->grammar, ctx_main, id);
504504
}
505-
llama_sampler_dry_accept(ctx_sampling->smpl, id);
505+
if (ctx_sampling->smpl) {
506+
llama_sampler_dry_accept(ctx_sampling->smpl, id);
507+
}
506508
}

src/llama.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23401,6 +23401,9 @@ struct llama_sampler_dry* llama_sampler_dry_clone(struct llama_sampler_dry* smpl
2340123401
}
2340223402

2340323403
void llama_sampler_dry_accept(struct llama_sampler_dry* smpl, llama_token token) {
23404+
if (!smpl) {
23405+
return;
23406+
}
2340423407
if (smpl->dry_multiplier == 0.0f || smpl->dry_base < 1.0f || smpl->dry_penalty_last_n == 0) {
2340523408
return;
2340623409
}

0 commit comments

Comments
 (0)