From 34f4bd02dae95912e0da3f959550cb046e2ef3f1 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Thu, 5 Sep 2024 17:08:46 +0300 Subject: [PATCH] sampling : fix cloning of samplers with null ctx ggml-ci --- src/llama-grammar.cpp | 1 + src/llama-sampling.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/llama-grammar.cpp b/src/llama-grammar.cpp index 09f756fbe..353cb398a 100644 --- a/src/llama-grammar.cpp +++ b/src/llama-grammar.cpp @@ -3,6 +3,7 @@ #include "llama-vocab.h" #include "llama-sampling.h" +#include #include #include diff --git a/src/llama-sampling.cpp b/src/llama-sampling.cpp index 735992faa..8ff52dd2d 100644 --- a/src/llama-sampling.cpp +++ b/src/llama-sampling.cpp @@ -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) {