From fb27a45f54831ec21440da51355c0eedc9d89d5c Mon Sep 17 00:00:00 2001 From: mendax0110 Date: Sat, 9 Sep 2023 18:51:32 +0200 Subject: [PATCH] fixed potential memory leak in the `load_model` function , deleted semicolons --- StarCoderApp/starcoderlib/generate.cpp | 3 +++ convert-hf-to-ggml.py | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/StarCoderApp/starcoderlib/generate.cpp b/StarCoderApp/starcoderlib/generate.cpp index 76d8d2c..e48c2a6 100644 --- a/StarCoderApp/starcoderlib/generate.cpp +++ b/StarCoderApp/starcoderlib/generate.cpp @@ -714,6 +714,9 @@ extern const StarcoderModel * load_model(const char * model_path) { if (!starcoder_model_load(model_path, model->model, model->vocab)) { fprintf(stderr, "%s: failed to load model from '%s'\n", __func__, model_path); + + // free the mem, allocated for 'model' before returning + delete model; return NULL; } diff --git a/convert-hf-to-ggml.py b/convert-hf-to-ggml.py index 20b9b4c..75b1570 100644 --- a/convert-hf-to-ggml.py +++ b/convert-hf-to-ggml.py @@ -160,10 +160,10 @@ def bytes_to_unicode(): print(" Skipping variable: " + name) continue - n_dims = len(data.shape); + n_dims = len(data.shape) # ftype == 0 -> float32, ftype == 1 -> float16 - ftype = 0; + ftype = 0 if use_f16: if (name == "model/wte" or name == "model/lm_head" or name[-2:] == "/g" or name[-2:] == "/w") and n_dims == 2: print(" Converting to float16") @@ -201,7 +201,7 @@ def bytes_to_unicode(): fout.write(struct.pack("iii", n_dims, len(str), ftype)) for i in range(n_dims): fout.write(struct.pack("i", data.shape[n_dims - 1 - i])) - fout.write(str); + fout.write(str) # data data.tofile(fout)