sampling : fix cloning of samplers with null ctx

ggml-ci
This commit is contained in:
Georgi Gerganov 2024-09-05 17:08:46 +03:00
parent 0b6dfcebb2
commit 34f4bd02da
No known key found for this signature in database
GPG key ID: 449E073F9DC10735
2 changed files with 13 additions and 1 deletions

View file

@ -3,6 +3,7 @@
#include "llama-vocab.h"
#include "llama-sampling.h"
#include <cmath>
#include <algorithm>
#include <stdexcept>

View file

@ -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) {