Pass pointer to params in llama_init_from_file
Especially with golang bindings, calling by value has the side-effect of values not being copied correctly. This has been observed with the bindings in https://github.com/go-skynet/go-llama.cpp/pull/105.
This commit is contained in:
parent
d411968e99
commit
200892a3a5
7 changed files with 9 additions and 8 deletions
|
@ -555,7 +555,7 @@ struct llama_context * llama_init_from_gpt_params(const gpt_params & params) {
|
||||||
lparams.logits_all = params.perplexity;
|
lparams.logits_all = params.perplexity;
|
||||||
lparams.embedding = params.embedding;
|
lparams.embedding = params.embedding;
|
||||||
|
|
||||||
llama_context * lctx = llama_init_from_file(params.model.c_str(), lparams);
|
llama_context * lctx = llama_init_from_file(params.model.c_str(), &lparams);
|
||||||
|
|
||||||
if (lctx == NULL) {
|
if (lctx == NULL) {
|
||||||
fprintf(stderr, "%s: error: failed to load model '%s'\n", __func__, params.model.c_str());
|
fprintf(stderr, "%s: error: failed to load model '%s'\n", __func__, params.model.c_str());
|
||||||
|
|
|
@ -330,7 +330,7 @@ int main(int argc, char ** argv) {
|
||||||
lparams.f16_kv = false;
|
lparams.f16_kv = false;
|
||||||
lparams.use_mlock = false;
|
lparams.use_mlock = false;
|
||||||
|
|
||||||
ctx = llama_init_from_file(params.model.c_str(), lparams);
|
ctx = llama_init_from_file(params.model.c_str(), &lparams);
|
||||||
|
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
fprintf(stderr, "%s: error: failed to load model '%s'\n", __func__, params.model.c_str());
|
fprintf(stderr, "%s: error: failed to load model '%s'\n", __func__, params.model.c_str());
|
||||||
|
|
|
@ -35,7 +35,7 @@ int main(int argc, char ** argv) {
|
||||||
auto last_n_tokens_data = std::vector<llama_token>(params.repeat_last_n, 0);
|
auto last_n_tokens_data = std::vector<llama_token>(params.repeat_last_n, 0);
|
||||||
|
|
||||||
// init
|
// init
|
||||||
auto ctx = llama_init_from_file(params.model.c_str(), lparams);
|
auto ctx = llama_init_from_file(params.model.c_str(), &lparams);
|
||||||
auto tokens = std::vector<llama_token>(params.n_ctx);
|
auto tokens = std::vector<llama_token>(params.n_ctx);
|
||||||
auto n_prompt_tokens = llama_tokenize(ctx, params.prompt.c_str(), tokens.data(), int(tokens.size()), true);
|
auto n_prompt_tokens = llama_tokenize(ctx, params.prompt.c_str(), tokens.data(), int(tokens.size()), true);
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ int main(int argc, char ** argv) {
|
||||||
llama_free(ctx);
|
llama_free(ctx);
|
||||||
|
|
||||||
// load new model
|
// load new model
|
||||||
auto ctx2 = llama_init_from_file(params.model.c_str(), lparams);
|
auto ctx2 = llama_init_from_file(params.model.c_str(), &lparams);
|
||||||
|
|
||||||
// Load state (rng, logits, embedding and kv_cache) from file
|
// Load state (rng, logits, embedding and kv_cache) from file
|
||||||
{
|
{
|
||||||
|
|
|
@ -3054,7 +3054,7 @@ int main(int argc, char ** argv) {
|
||||||
struct llama_context_params llama_params = llama_context_default_params();
|
struct llama_context_params llama_params = llama_context_default_params();
|
||||||
llama_params.vocab_only = true;
|
llama_params.vocab_only = true;
|
||||||
|
|
||||||
struct llama_context * lctx = llama_init_from_file(params.fn_vocab_model, llama_params);
|
struct llama_context * lctx = llama_init_from_file(params.fn_vocab_model, &llama_params);
|
||||||
|
|
||||||
struct llama_vocab vocab;
|
struct llama_vocab vocab;
|
||||||
{
|
{
|
||||||
|
|
|
@ -2618,8 +2618,9 @@ static void llama_model_quantize_internal(const std::string & fname_inp, const s
|
||||||
|
|
||||||
struct llama_context * llama_init_from_file(
|
struct llama_context * llama_init_from_file(
|
||||||
const char * path_model,
|
const char * path_model,
|
||||||
struct llama_context_params params) {
|
const struct llama_context_params * params_ptr) {
|
||||||
ggml_time_init();
|
ggml_time_init();
|
||||||
|
struct llama_context_params params = *params_ptr;
|
||||||
|
|
||||||
llama_context * ctx = new llama_context;
|
llama_context * ctx = new llama_context;
|
||||||
|
|
||||||
|
|
2
llama.h
2
llama.h
|
@ -142,7 +142,7 @@ extern "C" {
|
||||||
// Return NULL on failure
|
// Return NULL on failure
|
||||||
LLAMA_API struct llama_context * llama_init_from_file(
|
LLAMA_API struct llama_context * llama_init_from_file(
|
||||||
const char * path_model,
|
const char * path_model,
|
||||||
struct llama_context_params params);
|
const struct llama_context_params * params);
|
||||||
|
|
||||||
// Frees all allocated memory
|
// Frees all allocated memory
|
||||||
LLAMA_API void llama_free(struct llama_context * ctx);
|
LLAMA_API void llama_free(struct llama_context * ctx);
|
||||||
|
|
|
@ -36,7 +36,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
lparams.vocab_only = true;
|
lparams.vocab_only = true;
|
||||||
|
|
||||||
ctx = llama_init_from_file(fname.c_str(), lparams);
|
ctx = llama_init_from_file(fname.c_str(), &lparams);
|
||||||
|
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
fprintf(stderr, "%s: error: failed to load vocab '%s'\n", __func__, fname.c_str());
|
fprintf(stderr, "%s: error: failed to load vocab '%s'\n", __func__, fname.c_str());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue