From f887161718e894fb845961c52370408b257a6d1a Mon Sep 17 00:00:00 2001 From: Emil Abbasov Date: Thu, 30 May 2024 22:20:35 -0400 Subject: [PATCH] error handling for when model_scale and model_beta2 is zero --- runtime/include/route_config.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/runtime/include/route_config.h b/runtime/include/route_config.h index 05056fff..e2fd2a4b 100644 --- a/runtime/include/route_config.h +++ b/runtime/include/route_config.h @@ -128,6 +128,11 @@ route_config_validate(struct route_config *config, bool *did_set) return -1; } + if (config->model_scale == 0) { + fprintf(stderr, "model scale cannot be zero (to avoid divide by zero)\n"); + return -1; + } + if (did_set[route_config_member_model_num_of_param] == false) { fprintf(stderr, "model num_of_param field is required\n"); return -1; @@ -138,6 +143,11 @@ route_config_validate(struct route_config *config, bool *did_set) return -1; } + if (config->model_beta1 == 0) { + fprintf(stderr, "model beta1 cannot be zero (to avoid divide by zero)\n"); + return -1; + } + if (did_set[route_config_member_model_beta2] == false) { fprintf(stderr, "model beta2 field is required. Put zero for just default preprocessing\n"); return -1; @@ -151,10 +161,7 @@ route_config_validate(struct route_config *config, bool *did_set) fprintf(stderr, "model_num_of_param cannot be 1 when using tenant preprocessing\n"); return -1; } - if (config->model_beta2 != 0) { - fprintf(stderr, "model beta2 must be zero for just default preprocessing\n"); - return -1; - } + config->model_beta2 = 1; /* This is to avoid divide-by-zero */ } else { /* For now we just support up to two params */ assert(config->model_num_of_param == 2); @@ -162,6 +169,10 @@ route_config_validate(struct route_config *config, bool *did_set) fprintf(stderr, "model_num_of_param cannot be more than 1 when just default preprocessing\n"); return -1; } + if (config->model_beta2 == 0) { + fprintf(stderr, "model beta2 cannot be zero (to avoid divide by zero)\n"); + return -1; + } } #endif return 0;