Skip to content

Commit cb44dbc

Browse files
authored
llama : catch llama_load_session_file_internal exceptions (ggml-org#2022)
* convert checks in llama_load_session_file to throw and handle them * make llama_load_session_file_internal static * address feedbacks to avoid using exceptions
1 parent 79f634a commit cb44dbc

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

llama.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -3219,7 +3219,7 @@ size_t llama_set_state_data(struct llama_context * ctx, uint8_t * src) {
32193219
return nread;
32203220
}
32213221

3222-
bool llama_load_session_file(struct llama_context * ctx, const char * path_session, llama_token * tokens_out, size_t n_token_capacity, size_t * n_token_count_out) {
3222+
static bool llama_load_session_file_internal(struct llama_context * ctx, const char * path_session, llama_token * tokens_out, size_t n_token_capacity, size_t * n_token_count_out) {
32233223
llama_file file(path_session, "rb");
32243224

32253225
// sanity checks
@@ -3269,8 +3269,15 @@ bool llama_load_session_file(struct llama_context * ctx, const char * path_sessi
32693269

32703270
llama_set_state_data(ctx, state_data.data());
32713271
}
3272+
}
32723273

3273-
return true;
3274+
bool llama_load_session_file(struct llama_context * ctx, const char * path_session, llama_token * tokens_out, size_t n_token_capacity, size_t * n_token_count_out) {
3275+
try {
3276+
return llama_load_session_file_internal(ctx, path_session, tokens_out, n_token_capacity, n_token_count_out);
3277+
} catch (const std::exception & err) {
3278+
fprintf(stderr, "error loading session file: %s\n", err.what());
3279+
return false;
3280+
}
32743281
}
32753282

32763283
bool llama_save_session_file(struct llama_context * ctx, const char * path_session, const llama_token * tokens, size_t n_token_count) {

0 commit comments

Comments
 (0)