add free for context
This commit is contained in:
parent
9c6117cd8d
commit
ba1f617d7d
4 changed files with 11 additions and 0 deletions
|
@ -23,6 +23,7 @@ bool eval_id(struct MyModel* mymodel, int id);
|
|||
bool eval_string(struct MyModel* mymodel, const char* str);
|
||||
const char* sampling(struct MyModel* mymodel);
|
||||
llama_token sampling_id(struct MyModel* mymodel);
|
||||
void free_mymodel(struct MyModel* mymodel);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ class MyModel:
|
|||
args_c = (c_char_p * argc)(*c_str)
|
||||
self.model = c_void_p(libc.create_mymodel(argc, args_c))
|
||||
# print("self.model", self.model)
|
||||
def __del__(self):
|
||||
libc.free_mymodel(self.model)
|
||||
|
||||
def eval_float(self, x):
|
||||
libc.eval_float(self.model, x.astype(np.float32).ctypes.data_as(POINTER(c_float)), x.shape[0])
|
||||
|
|
|
@ -101,6 +101,13 @@ struct MyModel* create_mymodel(int argc, char ** argv) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
void free_mymodel(struct MyModel* mymodel) {
|
||||
llama_context* ctx = mymodel->ctx;
|
||||
llama_print_timings(ctx);
|
||||
llama_free(ctx);
|
||||
delete mymodel;
|
||||
}
|
||||
|
||||
|
||||
bool eval_float(void* model, float* input, int N){
|
||||
MyModel* mymodel = (MyModel* )model;
|
||||
|
|
|
@ -27,5 +27,6 @@ int main(int argc, char** argv) {
|
|||
// eval_id(mymodel, id);
|
||||
}
|
||||
printf("\n");
|
||||
free_mymodel(mymodel);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue