error handling for when model_scale and model_beta2 is zero

pull/385/head
Emil Abbasov 1 year ago
parent c990be467c
commit f887161718

@ -128,6 +128,11 @@ route_config_validate(struct route_config *config, bool *did_set)
return -1; 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) { if (did_set[route_config_member_model_num_of_param] == false) {
fprintf(stderr, "model num_of_param field is required\n"); fprintf(stderr, "model num_of_param field is required\n");
return -1; return -1;
@ -138,6 +143,11 @@ route_config_validate(struct route_config *config, bool *did_set)
return -1; 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) { if (did_set[route_config_member_model_beta2] == false) {
fprintf(stderr, "model beta2 field is required. Put zero for just default preprocessing\n"); fprintf(stderr, "model beta2 field is required. Put zero for just default preprocessing\n");
return -1; 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"); fprintf(stderr, "model_num_of_param cannot be 1 when using tenant preprocessing\n");
return -1; return -1;
} }
if (config->model_beta2 != 0) { config->model_beta2 = 1; /* This is to avoid divide-by-zero */
fprintf(stderr, "model beta2 must be zero for just default preprocessing\n");
return -1;
}
} else { } else {
/* For now we just support up to two params */ /* For now we just support up to two params */
assert(config->model_num_of_param == 2); 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"); fprintf(stderr, "model_num_of_param cannot be more than 1 when just default preprocessing\n");
return -1; return -1;
} }
if (config->model_beta2 == 0) {
fprintf(stderr, "model beta2 cannot be zero (to avoid divide by zero)\n");
return -1;
}
} }
#endif #endif
return 0; return 0;

Loading…
Cancel
Save