Skip to content

Commit

Permalink
sampling : fix cloning of samplers with null ctx
Browse files Browse the repository at this point in the history
ggml-ci
  • Loading branch information
ggerganov committed Sep 5, 2024
1 parent 393f8d9 commit 6cc911a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/llama-grammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "llama-vocab.h"
#include "llama-sampling.h"

#include <cmath>
#include <algorithm>
#include <stdexcept>

Expand Down
13 changes: 12 additions & 1 deletion src/llama-sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,18 @@ void llama_sampler_reset_impl(struct llama_sampler & smpl) {
}

struct llama_sampler * llama_sampler_clone_impl(const struct llama_sampler & smpl) {
return smpl.iface->clone ? smpl.iface->clone(&smpl) : nullptr;
if (smpl.iface->clone) {
return smpl.iface->clone(&smpl);
}

if (smpl.ctx == nullptr) {
return new llama_sampler {
/* .iface = */ smpl.iface,
/* .ctx = */ nullptr,
};
}

GGML_ABORT("the sampler does not support cloning");
}

void llama_sampler_free_impl(struct llama_sampler * smpl) {
Expand Down

0 comments on commit 6cc911a

Please sign in to comment.