Skip to content

Commit 6cc911a

Browse files
committed
sampling : fix cloning of samplers with null ctx
ggml-ci
1 parent 393f8d9 commit 6cc911a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/llama-grammar.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "llama-vocab.h"
44
#include "llama-sampling.h"
55

6+
#include <cmath>
67
#include <algorithm>
78
#include <stdexcept>
89

src/llama-sampling.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,18 @@ void llama_sampler_reset_impl(struct llama_sampler & smpl) {
12581258
}
12591259

12601260
struct llama_sampler * llama_sampler_clone_impl(const struct llama_sampler & smpl) {
1261-
return smpl.iface->clone ? smpl.iface->clone(&smpl) : nullptr;
1261+
if (smpl.iface->clone) {
1262+
return smpl.iface->clone(&smpl);
1263+
}
1264+
1265+
if (smpl.ctx == nullptr) {
1266+
return new llama_sampler {
1267+
/* .iface = */ smpl.iface,
1268+
/* .ctx = */ nullptr,
1269+
};
1270+
}
1271+
1272+
GGML_ABORT("the sampler does not support cloning");
12621273
}
12631274

12641275
void llama_sampler_free_impl(struct llama_sampler * smpl) {

0 commit comments

Comments
 (0)