From e08b9077607b03490f26c9ea00249c9669c7d9e4 Mon Sep 17 00:00:00 2001 From: Tejaakshaykumar <147340353+Tejaakshaykumar@users.noreply.github.com> Date: Wed, 18 Sep 2024 15:57:22 +0530 Subject: [PATCH] Update clip.cpp used try-catch block. validation is made by checking all the hyperparameters are are positive and logs an error if they are not. included detailed logging of hyperparameters if needed for debugging. --- examples/llava/clip.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/examples/llava/clip.cpp b/examples/llava/clip.cpp index 3327cb266dc58..c2969504f6442 100644 --- a/examples/llava/clip.cpp +++ b/examples/llava/clip.cpp @@ -1270,6 +1270,7 @@ struct clip_ctx * clip_model_load(const char * fname, const int verbosity = 1) { // load vision model auto & vision_model = new_clip->vision_model; auto & hparams = vision_model.hparams; + try{ hparams.hidden_size = get_u32(ctx, format(KEY_N_EMBD, "vision")); hparams.n_head = get_u32(ctx, format(KEY_N_HEAD, "vision")); hparams.n_intermediate = get_u32(ctx, format(KEY_N_FF, "vision")); @@ -1278,11 +1279,24 @@ struct clip_ctx * clip_model_load(const char * fname, const int verbosity = 1) { hparams.patch_size = get_u32(ctx, KEY_PATCH_SIZE); hparams.projection_dim = get_u32(ctx, format(KEY_PROJ_DIM, "vision")); hparams.eps = get_f32(ctx, format(KEY_LAYER_NORM_EPS, "vision")); - if (hparams.hidden_size == 0 || hparams.n_head == 0 || hparams.n_layer == 0 || hparams.n_intermediate == 0 || hparams.image_size == 0 || hparams.patch_size == 0 || hparams.projection_dim == 0 || hparams.eps == 0) { - fprintf(stderr, "Error: Invalid hyperparameter values\n"); + if (hparams.hidden_size <= 0 || hparams.n_head <= 0 || hparams.n_layer <= 0 || hparams.n_intermediate <= 0 || hparams.image_size <= 0 || hparams.patch_size <= 0 || hparams.projection_dim <= 0 || hparams.eps <= 0) { + LOG_TEE("Error: Invalid hyperparameter values\n"); return false; } - } + // Optionally log loaded hyperparameters for debugging + LOG_TEE("Loaded hyperparameters:\n"); + LOG_TEE("Hidden size: %d\n", hparams.hidden_size); + LOG_TEE("Number of heads: %d\n", hparams.n_head); + LOG_TEE("Number of intermediate units: %d\n", hparams.n_intermediate); + LOG_TEE("Number of layers: %d\n", hparams.n_layer); + LOG_TEE("Image size: %d\n", hparams.image_size); + LOG_TEE("Patch size: %d\n", hparams.patch_size); + LOG_TEE("Projection dimension: %d\n", hparams.projection_dim); + LOG_TEE("Layer norm epsilon: %f\n", hparams.eps); + } catch (const std::exception& e) { + LOG_TEE("Error while loading hyperparameters: %s\n", e.what()); +     } + try { int idx = get_key_idx(ctx, KEY_IMAGE_GRID_PINPOINTS); int n = gguf_get_arr_n(ctx, idx);