]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commit
llama : add llama_sampler_init for safe usage of llama_sampler_free (#11727)
authorChristian Fillion <redacted>
Fri, 7 Feb 2025 09:33:27 +0000 (04:33 -0500)
committerGitHub <redacted>
Fri, 7 Feb 2025 09:33:27 +0000 (11:33 +0200)
commit7ee953a64a40c09438b2064539becdbc577cefd0
treea71a566d7754240d1c5ad7eb0b0a97b1422d4787
parentec3bc8270bc67b58955748d40a3e558a05b2d8f2
llama : add llama_sampler_init for safe usage of llama_sampler_free (#11727)

The C API in llama.h claims users can implement `llama_sampler_i` to
create custom `llama_sampler`. The sampler chain takes ownership and
calls `llama_sampler_free` on them. However, `llama_sampler_free` is
hard-coded to use `delete`. This is undefined behavior if the object
wasn't also allocated via `new` from libllama's C++ runtime. Callers
in C and C-compatible languages do not use C++'s `new` operator. C++
callers may not be sharing the same heap as libllama.
common/llguidance.cpp
include/llama.h
src/llama-sampling.cpp