From a7b77d5d65d70d78b8570057010d3ff455d4a4c6 Mon Sep 17 00:00:00 2001 From: leondavi Date: Wed, 7 Aug 2024 18:46:58 +0300 Subject: [PATCH] [NERLPLANNER] Add loss args --- src_cpp/common/nerlWorker.cpp | 3 ++- src_cpp/common/nerlWorker.h | 3 ++- src_cpp/common/nerlWorkerFunc.h | 4 ++-- src_cpp/opennnBridge/nerlWorkerNIF.h | 20 ++++++++++------ src_cpp/opennnBridge/nerlWorkerOpenNN.cpp | 24 +++++++++++++------ src_cpp/opennnBridge/nerlWorkerOpenNN.h | 3 ++- .../src/Bridge/onnWorkers/nerlNIF.erl | 4 ++-- .../src/Bridge/onnWorkers/workerGeneric.erl | 2 +- .../src/Client/clientWorkersFunctions.erl | 4 ++-- src_py/nerlPlanner/JsonElementWorker.py | 14 +++++++---- .../JsonElementWorkerDefinitions.py | 3 +++ src_py/nerlPlanner/WinWorkerDialog.py | 14 +++++++---- .../nerlPlanner/WinWorkerDialogDefnitions.py | 1 + 13 files changed, 66 insertions(+), 33 deletions(-) diff --git a/src_cpp/common/nerlWorker.cpp b/src_cpp/common/nerlWorker.cpp index 3c721fd56..bd265e73b 100644 --- a/src_cpp/common/nerlWorker.cpp +++ b/src_cpp/common/nerlWorker.cpp @@ -4,7 +4,7 @@ using namespace nerlnet; NerlWorker::NerlWorker(int model_type, std::string &model_args_str , std::string &layer_sizes_str, std::string &layer_types_list, std::string &layers_functionality, float learning_rate, int epochs, int optimizer_type, std::string &optimizer_args_str, - int loss_method, int distributed_system_type, std::string &distributed_system_args_str) + int loss_method, std::string &loss_args_str, int distributed_system_type, std::string &distributed_system_args_str) { _model_type = model_type; _model_args_str = model_args_str; @@ -12,6 +12,7 @@ NerlWorker::NerlWorker(int model_type, std::string &model_args_str , std::string _epochs = epochs; _optimizer_type = optimizer_type; _loss_method = loss_method; + _loss_args_str = loss_args_str; _distributed_system_type = distributed_system_type; _distributed_system_args_str = distributed_system_args_str; _nerl_layers_linked_list = parse_layers_input(layer_sizes_str,layer_types_list,layers_functionality); diff --git a/src_cpp/common/nerlWorker.h b/src_cpp/common/nerlWorker.h index b6359b092..3e4fb70cf 100644 --- a/src_cpp/common/nerlWorker.h +++ b/src_cpp/common/nerlWorker.h @@ -12,7 +12,7 @@ namespace nerlnet NerlWorker(int model_type, std::string &model_args_str, std::string &layer_sizes_str, std::string &layer_types_list, std::string &layers_functionality, float learning_rate, int epochs, int optimizer_type, std::string &optimizer_args_str, - int loss_method, int distributed_system_type, std::string &distributed_system_args_str); + int loss_method, std::string &loss_args_str, int distributed_system_type, std::string &distributed_system_args_str); ~NerlWorker(); std::shared_ptr parse_layers_input(std::string &layer_sizes_str, std::string &layer_types_list, std::string &layers_functionality); @@ -35,6 +35,7 @@ namespace nerlnet int _epochs; int _optimizer_type; int _loss_method; + std::string _loss_args_str; std::string _distributed_system_args_str; std::shared_ptr> _train_labels_count; // accumulates the number of each label in the training set diff --git a/src_cpp/common/nerlWorkerFunc.h b/src_cpp/common/nerlWorkerFunc.h index 99c313ada..739bf7677 100644 --- a/src_cpp/common/nerlWorkerFunc.h +++ b/src_cpp/common/nerlWorkerFunc.h @@ -58,7 +58,7 @@ enum {KERNEL_SIZE = -1, PADDING_SIZE = -2,STRIDE_SIZE = -3 ,POOLING_SIZE= -4 , I template std::shared_ptr parse_model_params(std::string &model_type_str,std::string &model_args_str, std::string &learning_rate_str,std::string &epochs_str, - std::string &optimizer_type_str,std::string &loss_method_str,std::string &distributed_system_type_str, + std::string &optimizer_type_str,std::string &loss_method_str, std::string &loss_args_str, std::string &distributed_system_type_str, std::string &layer_sizes_str,std::string &layer_types_str,std::string &layers_functionality_str, std::string &optimizer_args_str,std::string &distributed_system_args_str) { @@ -68,7 +68,7 @@ std::shared_ptr parse_model_params(std::string &model_type_str,s int optimizer_type = std::stoi(optimizer_type_str); int loss_method = std::stoi(loss_method_str); int distributed_system_type = std::stoi(distributed_system_type_str); - return std::make_shared(model_type, model_args_str, layer_sizes_str, layer_types_str, layers_functionality_str,learning_rate, epochs, optimizer_type, optimizer_args_str, loss_method, distributed_system_type, distributed_system_args_str); + return std::make_shared(model_type, model_args_str, layer_sizes_str, layer_types_str, layers_functionality_str,learning_rate, epochs, optimizer_type, optimizer_args_str, loss_method, loss_args_str, distributed_system_type, distributed_system_args_str); } static void parse_layer_sizes_str(std::string &layer_sizes_str, std::vector &layers_types_vec, std::vector &out_layer_sizes_params) diff --git a/src_cpp/opennnBridge/nerlWorkerNIF.h b/src_cpp/opennnBridge/nerlWorkerNIF.h index 43167ef07..4f6ce7860 100644 --- a/src_cpp/opennnBridge/nerlWorkerNIF.h +++ b/src_cpp/opennnBridge/nerlWorkerNIF.h @@ -10,18 +10,18 @@ using namespace nerlnet; static std::shared_ptr create_nerlworker(std::string &model_type_str, std::string &model_args_str, std::string &learning_rate_str, - std::string &epochs_str, std::string &optimizer_type_str, std::string &loss_method_str, + std::string &epochs_str, std::string &optimizer_type_str, std::string &loss_method_str, std::string &loss_args_str, std::string &distributed_system_type_str, std::string &layer_sizes_str, std:: string &layer_types_str, std::string &layers_functionality_str, std::string &optimizer_args_str, std::string &distributed_system_args_str) //all should be const reference { - std::shared_ptr new_worker = parse_model_params(model_type_str,model_args_str,learning_rate_str,epochs_str,optimizer_type_str,loss_method_str,distributed_system_type_str,layer_sizes_str, + std::shared_ptr new_worker = parse_model_params(model_type_str,model_args_str,learning_rate_str,epochs_str,optimizer_type_str,loss_method_str, loss_args_str, distributed_system_type_str,layer_sizes_str, layer_types_str,layers_functionality_str,optimizer_args_str,distributed_system_args_str); return new_worker; } static ERL_NIF_TERM new_nerlworker_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { enum{ARG_MODEL_ID,ARG_MODEL_TYPE, ARG_MODEL_ARGS, ARG_LAYERS_SIZES, ARG_LAYERS_TYPES, ARG_LAYERS_FUNCTIONALITY_CODES, ARG_LEARNING_RATE, ARG_EPOCHS, ARG_OPTIMIZER_TYPE, - ARG_OPTIMIZER_ARGS, ARG_LOSS_METHOD, ARG_DISTRIBUTED_SYSTEM_TYPE, ARG_DISTRIBUTED_SYSTEM_ARGS}; + ARG_OPTIMIZER_ARGS, ARG_LOSS_METHOD, ARG_LOSS_ARGS, ARG_DISTRIBUTED_SYSTEM_TYPE, ARG_DISTRIBUTED_SYSTEM_ARGS}; unsigned long modelId; std::string model_type_str; @@ -34,6 +34,7 @@ static ERL_NIF_TERM new_nerlworker_nif(ErlNifEnv* env, int argc, const ERL_NIF_T std::string optimizer_type_str; std::string optimizer_args_str; std::string loss_method_str; + std::string loss_args_str; std::string distributed_system_type_str; std::string distributed_system_args_str; @@ -48,10 +49,12 @@ static ERL_NIF_TERM new_nerlworker_nif(ErlNifEnv* env, int argc, const ERL_NIF_T nifpp::get_throws(env, argv[ARG_OPTIMIZER_TYPE], optimizer_type_str); nifpp::get_throws(env, argv[ARG_OPTIMIZER_ARGS], optimizer_args_str); nifpp::get_throws(env, argv[ARG_LOSS_METHOD], loss_method_str); + nifpp::get_throws(env, argv[ARG_LOSS_ARGS], loss_args_str); nifpp::get_throws(env, argv[ARG_DISTRIBUTED_SYSTEM_TYPE], distributed_system_type_str); nifpp::get_throws(env, argv[ARG_DISTRIBUTED_SYSTEM_ARGS], distributed_system_args_str); - std::shared_ptr new_nerl_worker_ptr = create_nerlworker(model_type_str,model_args_str,learning_rate_str,epochs_str,optimizer_type_str,loss_method_str,distributed_system_type_str,layer_sizes_str, + std::shared_ptr new_nerl_worker_ptr = create_nerlworker(model_type_str,model_args_str,learning_rate_str,epochs_str,optimizer_type_str, + loss_method_str,loss_args_str,distributed_system_type_str,layer_sizes_str, layer_types_str,layers_functionality_str,optimizer_args_str,distributed_system_args_str); // Create the singleton instance BridgeController& onnBrCtrl = BridgeController::GetInstance(); @@ -65,7 +68,7 @@ static ERL_NIF_TERM new_nerlworker_nif(ErlNifEnv* env, int argc, const ERL_NIF_T static ERL_NIF_TERM test_nerlworker_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { enum{ARG_MODEL_ID,ARG_MODEL_TYPE, ARG_MODEL_ARGS , ARG_LAYERS_SIZES, ARG_LAYERS_TYPES, ARG_LAYERS_FUNCTIONALITY_CODES, ARG_LEARNING_RATE, ARG_EPOCHS, ARG_OPTIMIZER_TYPE, - ARG_OPTIMIZER_ARGS, ARG_LOSS_METHOD, ARG_DISTRIBUTED_SYSTEM_TYPE, ARG_DISTRIBUTED_SYSTEM_ARGS}; + ARG_OPTIMIZER_ARGS, ARG_LOSS_METHOD, ARG_LOSS_ARGS, ARG_DISTRIBUTED_SYSTEM_TYPE, ARG_DISTRIBUTED_SYSTEM_ARGS}; unsigned long modelId; std::string model_type_str; @@ -78,6 +81,7 @@ static ERL_NIF_TERM test_nerlworker_nif(ErlNifEnv* env, int argc, const ERL_NIF_ std::string optimizer_type_str; std::string optimizer_args_str; std::string loss_method_str; + std::string loss_args_str; std::string distributed_system_type_str; std::string distributed_system_args_str; @@ -92,10 +96,12 @@ static ERL_NIF_TERM test_nerlworker_nif(ErlNifEnv* env, int argc, const ERL_NIF_ nifpp::get_throws(env, argv[ARG_OPTIMIZER_TYPE], optimizer_type_str); nifpp::get_throws(env, argv[ARG_OPTIMIZER_ARGS], optimizer_args_str); nifpp::get_throws(env, argv[ARG_LOSS_METHOD], loss_method_str); + nifpp::get_throws(env, argv[ARG_LOSS_ARGS], loss_args_str); nifpp::get_throws(env, argv[ARG_DISTRIBUTED_SYSTEM_TYPE], distributed_system_type_str); nifpp::get_throws(env, argv[ARG_DISTRIBUTED_SYSTEM_ARGS], distributed_system_args_str); - std::shared_ptr new_nerl_worker_ptr = create_nerlworker(model_type_str,model_args_str,learning_rate_str,epochs_str,optimizer_type_str,loss_method_str,distributed_system_type_str,layer_sizes_str, - layer_types_str,layers_functionality_str,optimizer_args_str,distributed_system_args_str); + std::shared_ptr new_nerl_worker_ptr = create_nerlworker(model_type_str,model_args_str,learning_rate_str,epochs_str, + optimizer_type_str,loss_method_str,loss_args_str,distributed_system_type_str,layer_sizes_str, + layer_types_str,layers_functionality_str,optimizer_args_str,distributed_system_args_str); // Create the singleton instance BridgeController& onnBrCtrl = BridgeController::GetInstance(); // Put the model record to the map with modelId diff --git a/src_cpp/opennnBridge/nerlWorkerOpenNN.cpp b/src_cpp/opennnBridge/nerlWorkerOpenNN.cpp index cfa7d3e85..f8db3783c 100644 --- a/src_cpp/opennnBridge/nerlWorkerOpenNN.cpp +++ b/src_cpp/opennnBridge/nerlWorkerOpenNN.cpp @@ -9,9 +9,9 @@ namespace nerlnet NerlWorkerOpenNN::NerlWorkerOpenNN(int model_type, std::string &model_args_str , std::string &layer_sizes_str, std::string &layer_types_list, std::string &layers_functionality, float learning_rate, int epochs, int optimizer_type, std::string &optimizer_args_str, - int loss_method, int distributed_system_type, std::string &distributed_system_args_str) : NerlWorker(model_type, model_args_str , layer_sizes_str, layer_types_list, layers_functionality, + int loss_method, std::string &loss_args_str, int distributed_system_type, std::string &distributed_system_args_str) : NerlWorker(model_type, model_args_str , layer_sizes_str, layer_types_list, layers_functionality, learning_rate, epochs, optimizer_type, optimizer_args_str, - loss_method, distributed_system_type, distributed_system_args_str) + loss_method, loss_args_str, distributed_system_type, distributed_system_args_str) { _neural_network_ptr = std::make_shared(); generate_opennn_neural_network(); @@ -169,11 +169,13 @@ namespace nerlnet **/ void NerlWorkerOpenNN::generate_training_strategy() { - _training_strategy_ptr->set_neural_network_pointer(_neural_network_ptr.get()); // Neural network must be defined at this point - set_optimization_method(_optimizer_type,_learning_rate); - set_loss_method(_loss_method); - _training_strategy_ptr->set_maximum_epochs_number(_epochs); - _training_strategy_ptr->set_display(TRAINING_STRATEGY_SET_DISPLAY_OFF); + _training_strategy_ptr->set_neural_network_pointer(_neural_network_ptr.get()); // Neural network must be defined at this point + set_optimization_method(_optimizer_type,_learning_rate); + set_loss_method(_loss_method); + // TODO Ori add here the parsing of loss args + // _training_strategy_ptr->get_loss_index_pointer()->set_regularization_method(reg_val); + _training_strategy_ptr->set_maximum_epochs_number(_epochs); + _training_strategy_ptr->set_display(TRAINING_STRATEGY_SET_DISPLAY_OFF); } void NerlWorkerOpenNN::set_optimization_method(int optimizer_type,int learning_rate){ @@ -862,4 +864,12 @@ namespace nerlnet } } + opennn::LossIndex::RegularizationMethod NerlWorkerOpenNN::parse_loss_args(const std::string &loss_args) + { + // TODO Ori parse loss_args to find the regularization method + // use switch case to decide + // if nothing is given then NoRegularization (this enum # exist in opennn) + return opennn::LossIndex::RegularizationMethod::L1; + } + } // namespace nerlnet \ No newline at end of file diff --git a/src_cpp/opennnBridge/nerlWorkerOpenNN.h b/src_cpp/opennnBridge/nerlWorkerOpenNN.h index 20ddb675f..22a4ef9ef 100644 --- a/src_cpp/opennnBridge/nerlWorkerOpenNN.h +++ b/src_cpp/opennnBridge/nerlWorkerOpenNN.h @@ -21,7 +21,7 @@ class NerlWorkerOpenNN : public NerlWorker NerlWorkerOpenNN(int model_type, std::string &model_args_str , std::string &layer_sizes_str, std::string &layer_types_list, std::string &layers_functionality, float learning_rate, int epochs, int optimizer_type, std::string &optimizer_args_str, - int loss_method, int distributed_system_type, std::string &distributed_system_args_str); + int loss_method, std::string &loss_args_str, int distributed_system_type, std::string &distributed_system_args_str); ~NerlWorkerOpenNN(); void generate_opennn_neural_network(); @@ -82,6 +82,7 @@ class NerlWorkerOpenNN : public NerlWorker opennn::Scaler translate_unscaling_method(int scaling_method); opennn::PoolingLayer::PoolingMethod translate_pooling_method(int pooling_method); opennn::ProbabilisticLayer::ActivationFunction translate_probabilistic_activation_function(int activation_function); + opennn::LossIndex::RegularizationMethod parse_loss_args(const std::string &loss_args_str); int translate_pooling_method_int(int pooling_method); int translate_model_type(int model_type, int &custom_model); diff --git a/src_erl/NerlnetApp/src/Bridge/onnWorkers/nerlNIF.erl b/src_erl/NerlnetApp/src/Bridge/onnWorkers/nerlNIF.erl index 496b0df5c..0ab2fca73 100644 --- a/src_erl/NerlnetApp/src/Bridge/onnWorkers/nerlNIF.erl +++ b/src_erl/NerlnetApp/src/Bridge/onnWorkers/nerlNIF.erl @@ -221,7 +221,7 @@ nerltensor_scalar_multiplication_erl({NerlTensorErl, Type}, ScalarValue) -> %%%%%% NerlWorker NIF Methods %%%%%% new_nerlworker_nif(_ModelId,_ModelType, _ModelArgs , _LayersSizes, _LayersTypes, _LayersFunctionalityCodes, _LearningRate, _Epochs, _OptimizerType, -_OptimizerArgs, _LossMethod, _DistributedSystemType, _DistributedSystemArgs) -> +_OptimizerArgs, _LossMethod, _LossArgs, _DistributedSystemType, _DistributedSystemArgs) -> exit(nif_library_not_loaded). remove_nerlworker_nif(_ModelId) -> @@ -229,7 +229,7 @@ remove_nerlworker_nif(_ModelId) -> %% All of inputs must be binary strings! except for _ModelId which is an integer test_nerlworker_nif(_ModelId,_ModelType, _ModelArgs, _LayersSizes, _LayersTypes, _LayersFunctionalityCodes, _LearningRate, _Epochs, _OptimizerType, - _OptimizerArgs, _LossMethod, _DistributedSystemType, _DistributedSystemArgs) -> + _OptimizerArgs, _LossMethod, _LossArgs, _DistributedSystemType, _DistributedSystemArgs) -> exit(nif_library_not_loaded). % input - unsigned long modelId diff --git a/src_erl/NerlnetApp/src/Bridge/onnWorkers/workerGeneric.erl b/src_erl/NerlnetApp/src/Bridge/onnWorkers/workerGeneric.erl index faa88c306..e2e708da4 100644 --- a/src_erl/NerlnetApp/src/Bridge/onnWorkers/workerGeneric.erl +++ b/src_erl/NerlnetApp/src/Bridge/onnWorkers/workerGeneric.erl @@ -86,7 +86,7 @@ init({WorkerName , WorkerArgs , DistributedBehaviorFunc , DistributedWorkerData Res = nerlNIF:new_nerlworker_nif(ModelID , ModelType, ModelArgs, LayersSizes, LayersTypes, LayersFunctionalityCodes, LearningRate, Epochs, OptimizerType, - OptimizerArgs, LossMethod , DistributedSystemType , DistributedSystemArgs), + OptimizerArgs, LossMethod , LossArgs, DistributedSystemType , DistributedSystemArgs), DistributedBehaviorFunc(init,{GenWorkerEts, DistributedWorkerData}), if diff --git a/src_erl/NerlnetApp/src/Client/clientWorkersFunctions.erl b/src_erl/NerlnetApp/src/Client/clientWorkersFunctions.erl index 44b293844..072f4e9ac 100644 --- a/src_erl/NerlnetApp/src/Client/clientWorkersFunctions.erl +++ b/src_erl/NerlnetApp/src/Client/clientWorkersFunctions.erl @@ -45,7 +45,7 @@ create_workers(ClientName, ClientEtsRef , ShaToModelArgsMap , EtsStats) -> ModelID = erlang:unique_integer([positive]), WorkerStatsETS = stats:generate_workers_stats_ets(), {ok , SHA} = maps:find(WorkerName , ets:lookup_element(ClientEtsRef, workers_to_sha_map, ?DATA_IDX)), - {ModelType, ModelArgs, LayersSizes, LayersTypes, LayersFunctions, LossMethod, + {ModelType, ModelArgs, LayersSizes, LayersTypes, LayersFunctions, LossMethod, LossArgs, LearningRate, Epochs, Optimizer, OptimizerArgs, _InfraType, DistributedSystemType, DistributedSystemArgs, DistributedSystemToken} = maps:get(SHA, ShaToModelArgsMap), DistributedTypeInteger = list_to_integer(DistributedSystemType), @@ -64,7 +64,7 @@ create_workers(ClientName, ClientEtsRef , ShaToModelArgsMap , EtsStats) -> W2wComPid = w2wCom:start_link({WorkerName, MyClientPid}), % TODO Switch to monitor instead of link WorkerArgs = {ModelID , ModelType , ModelArgs , LayersSizes, LayersTypes, LayersFunctions, LearningRate , Epochs, - Optimizer, OptimizerArgs , LossMethod , DistributedSystemType , DistributedSystemToken, DistributedSystemArgs}, + Optimizer, OptimizerArgs , LossMethod , LossArgs, DistributedSystemType , DistributedSystemToken, DistributedSystemArgs}, WorkerPid = workerGeneric:start_link({WorkerName , WorkerArgs , DistributedBehaviorFunc , DistributedWorkerData , MyClientPid , WorkerStatsETS , W2wComPid}), gen_server:cast(W2wComPid, {update_gen_worker_pid, WorkerPid}), ets:insert(WorkersETS, {WorkerName, {WorkerPid, WorkerArgs}}), diff --git a/src_py/nerlPlanner/JsonElementWorker.py b/src_py/nerlPlanner/JsonElementWorker.py index 1eb033cd2..fd0d33f22 100644 --- a/src_py/nerlPlanner/JsonElementWorker.py +++ b/src_py/nerlPlanner/JsonElementWorker.py @@ -107,7 +107,7 @@ def __str__(self): class Worker(JsonElement): def __init__(self, name, layers_sizes_list_str : str, model_type_str : str, model_type : int, model_args_str, optimization_type : str, - optimizer_args : str,loss_method_str : str, loss_method : int, learning_rate : str, epochs : str, layer_functions_codes_list_str : str, + optimizer_args : str,loss_method_str : str, loss_method : int, loss_args : str, learning_rate : str, epochs : str, layer_functions_codes_list_str : str, layer_types_list_str : str, infra : str, distributed_system_type : str, distributed_args : str, distributed_system_token : str): super(Worker, self).__init__(name, WORKER_TYPE) # Update here when adding new fields to the worker @@ -119,6 +119,7 @@ def __init__(self, name, layers_sizes_list_str : str, model_type_str : str, mode self.optimizer = Optimizer(optimization_type, optimizer_args) self.LossMethodStr = loss_method_str self.LossMethod = loss_method # None + self.LossArgs = loss_args self.LearningRate = float(learning_rate) self.LayersFunctionsCodesListStr = layer_functions_codes_list_str self.LayersFunctionsCodesList = layer_functions_codes_list_str.split(',') #TODO validate @@ -180,7 +181,7 @@ def copy(self, name): return newWorker def __str__(self): - return f"layers sizes: {self.LayersSizesListStr}, model: {self.ModelTypeStr}, using optimizer: {self.optimizer.get_val_str()}, loss method: {self.LossMethodStr}, lr: {self.LearningRate}, epochs: {self.Epochs.get_value_str()}, infra: {self.Infra.get_val_str()}, distributed system type: {self.distributedSystemType.get_val_str()}, distributed system token: {self.distributedSystemToken.get_val_str()}" + return f"layers sizes: {self.LayersSizesListStr}, model: {self.ModelTypeStr}, using optimizer: {self.optimizer.get_val_str()}, loss method: {self.LossMethodStr}, loss args: {self.LossArgs} ,lr: {self.LearningRate}, epochs: {self.Epochs.get_value_str()}, infra: {self.Infra.get_val_str()}, distributed system type: {self.distributedSystemType.get_val_str()}, distributed system token: {self.distributedSystemToken.get_val_str()}" def error(self): return not self.input_validation() # + more checks @@ -208,6 +209,8 @@ def get_as_dict(self, documentation = True): (KEY_LAYERS_FUNCTIONS_SCALER_DOC, VAL_LAYERS_FUNCTIONS_SCALER_DOC), (KEY_LOSS_METHOD, self.LossMethod), (KEY_LOSS_METHOD_DOC, VAL_LOSS_METHOD_DOC), + (KEY_LOSS_ARGS, self.LossArgs), + (KEY_LOSS_ARGS_DOC, VAL_LOSS_ARGS_DOC) (KEY_LEARNING_RATE, self.LearningRate), (KEY_LEARNING_RATE_DOC, VAL_LEARNING_RATE_DOC), (KEY_EPOCHS, self.Epochs.get_value_str()), @@ -243,7 +246,7 @@ def save_as_json(self, out_file : str, documentation = True): def load_from_dict(worker_dict : dict, name = '', get_params = False): # Update here when adding new fields to the worker required_keys = [KEY_LAYER_SIZES_LIST, KEY_MODEL_TYPE, KEY_MODEL_ARGS,KEY_OPTIMIZER_TYPE, KEY_OPTIMIZER_ARGS, - KEY_LOSS_METHOD, KEY_LEARNING_RATE, KEY_EPOCHS, KEY_LAYERS_FUNCTIONS, + KEY_LOSS_METHOD, KEY_LOSS_ARGS, KEY_LEARNING_RATE, KEY_EPOCHS, KEY_LAYERS_FUNCTIONS, KEY_LAYER_TYPES_LIST, KEY_EPOCHS, KEY_INFRA_TYPE, KEY_DISTRIBUTED_SYSTEM_TYPE, KEY_DISTRIBUTED_SYSTEM_ARGS, KEY_DISTRIBUTED_SYSTEM_TOKEN] all_keys_exist = all([key in worker_dict for key in required_keys]) @@ -258,6 +261,7 @@ def load_from_dict(worker_dict : dict, name = '', get_params = False): Optimizer_args = worker_dict[KEY_OPTIMIZER_ARGS] LossMethod = int(worker_dict[KEY_LOSS_METHOD]) LossMethodStr = get_key_by_value(LossMethodMapping, worker_dict[KEY_LOSS_METHOD]) + LossArgs = worker_dict[KEY_LOSS_ARGS] LearningRate = float(worker_dict[KEY_LEARNING_RATE]) ActivationLayersList = worker_dict[KEY_LAYERS_FUNCTIONS] LayerTypesList = worker_dict[KEY_LAYER_TYPES_LIST] @@ -269,12 +273,12 @@ def load_from_dict(worker_dict : dict, name = '', get_params = False): if get_params: # Update here when adding new fields to the worker - return (LayersSizesList, ModelTypeStr, ModelType, ModelArgs , OptimizationType, Optimizer_args, LossMethodStr, LossMethod, + return (LayersSizesList, ModelTypeStr, ModelType, ModelArgs , OptimizationType, Optimizer_args, LossMethodStr, LossMethod, LossArgs, LearningRate, EpochsStr, ActivationLayersList, LayerTypesList, InfraType, DistributedSystemTypeInst, DistributedSystem_args, DistributedSystemTokenInst) # Update here when adding new fields to the worker - return Worker(name, LayersSizesList, ModelTypeStr, ModelType, ModelArgs, OptimizationType, Optimizer_args, LossMethodStr, LossMethod, LearningRate, EpochsStr, ActivationLayersList, LayerTypesList, InfraType, + return Worker(name, LayersSizesList, ModelTypeStr, ModelType, ModelArgs, OptimizationType, Optimizer_args, LossMethodStr, LossMethod, LossArgs, LearningRate, EpochsStr, ActivationLayersList, LayerTypesList, InfraType, DistributedSystemTypeInst, DistributedSystem_args, DistributedSystemTokenInst) return None \ No newline at end of file diff --git a/src_py/nerlPlanner/JsonElementWorkerDefinitions.py b/src_py/nerlPlanner/JsonElementWorkerDefinitions.py index 5e1bc975e..145661ea9 100644 --- a/src_py/nerlPlanner/JsonElementWorkerDefinitions.py +++ b/src_py/nerlPlanner/JsonElementWorkerDefinitions.py @@ -163,6 +163,8 @@ def doc_print_dict(d):#define d KEY_LAYERS_FUNCTIONS_PROBABILISTIC_DOC = "_doc_layer_functions_probabilistic" KEY_LOSS_METHOD = "lossMethod" KEY_LOSS_METHOD_DOC = "_doc_lossMethod" +KEY_LOSS_ARGS = "lossArgs" +KEY_LOSS_ARGS_DOC = "_doc_lossArgs" KEY_EPOCHS = "epochs" KEY_EPOCHS_DOC = "_doc_epochs" KEY_LEARNING_RATE = "lr" @@ -194,6 +196,7 @@ def doc_print_dict(d):#define d VAL_LEARNING_RATE_DOC = "Positve float" VAL_OPTIMIZER_TYPE_DOC = f"{doc_print_dict(OptimizerTypeMapping)}" VAL_OPTIMIZER_ARGS_DOC = "String" # Todo: fix in the future +VAL_LOSS_ARGS_DOC = "Arguments to loss function e.g., reg=L1,L2" VAL_INFRA_TYPE_DOC = f"{doc_print_dict(InfraTypeMapping)}" VAL_DISTRIBUTED_SYSTEM_TYPE_DOC = f"{doc_print_dict(DistributedSystemTypeMapping)}" VAL_DISTRIBUTED_SYSTEM_ARGS_DOC = "String" # Todo: fix in the future diff --git a/src_py/nerlPlanner/WinWorkerDialog.py b/src_py/nerlPlanner/WinWorkerDialog.py index 95b70f47d..e54c2456f 100644 --- a/src_py/nerlPlanner/WinWorkerDialog.py +++ b/src_py/nerlPlanner/WinWorkerDialog.py @@ -48,8 +48,9 @@ def WinWorkerDialog(): [sg.Text("Epochs: "), sg.InputText("1", size=(15), key=KEY_EPOCHS_INPUT, enable_events=True)], [sg.Text("Optimizer Type: "), sg.Combo(list(OptimizerTypeMapping.keys()),enable_events=True, key=KEY_OPTIMIZER_TYPE_LIST_BOX), sg.Text(" Optimizer Args:"), sg.InputText(key=KEY_OPTIMIZER_ARGS_INPUT, size=(15), enable_events=True, expand_x=True)], - [sg.Text("Loss Method: "), sg.Combo(list(LossMethodMapping.keys()),enable_events=True, key=KEY_LOSS_METHOD_LIST_BOX)] - ] + [sg.Text("Loss Method: "), sg.Combo(list(LossMethodMapping.keys()),enable_events=True, key=KEY_LOSS_METHOD_LIST_BOX), + sg.Text(" Loss Args:"), sg.InputText(key=KEY_LOSS_ARGS_INPUT, size=(15), enable_events=True, expand_x=True)]] + OptimizerDefinitionsFrame = sg.Frame("Optimizer Definitions", layout=OptimizerDefinitionsLayout, expand_x=True) InfraTypeLayout = [[ sg.Text("Infra Type: "), sg.Combo(list(InfraTypeMapping.keys()),default_value=list(InfraTypeMapping.keys())[0], enable_events=True, key=KEY_INFRA_TYPE_LIST_BOX)], @@ -74,6 +75,7 @@ def WinWorkerDialog(): OptimizationArgs = "none" LossMethodStr = "" LossMethod = None # None + LossArgs = "none" LearningRate = None Epochs = "1" LayersFunctionsList = "" @@ -93,6 +95,7 @@ def ui_update_all_values(WorkerWindow): WorkerWindow[KEY_OPTIMIZER_ARGS_INPUT].update(OptimizationArgs) WorkerWindow[KEY_INFRA_TYPE_LIST_BOX].update(InfraType) WorkerWindow[KEY_LOSS_METHOD_LIST_BOX].update(LossMethodStr) + WorkerWindow[KEY_LOSS_ARGS_INPUT].update(LossArgs) WorkerWindow[KEY_LEARNING_RATE_INPUT].update(LearningRate) WorkerWindow[KEY_EPOCHS_INPUT].update(Epochs) WorkerWindow[KEY_LAYER_FUNCTIONS_CODES_INPUT].update(LayersFunctionsList) @@ -182,7 +185,7 @@ def ui_update_all_values(WorkerWindow): if event == KEY_OPTIMIZER_ARGS_INPUT: OptimizationArgs = values[event] - + if event == KEY_INFRA_TYPE_LIST_BOX: InfraType = values[event] @@ -206,6 +209,9 @@ def ui_update_all_values(WorkerWindow): if event == KEY_LOSS_METHOD_LIST_BOX: LossMethodStr = values[event] LossMethod = LossMethodMapping[LossMethodStr] + + if event == KEY_LOSS_ARGS_INPUT: + LossArgs = values[event] if event == KEY_CHECKBOX_WORKER_WITH_DOCUMENTATION: WithDocumentation = values[KEY_CHECKBOX_WORKER_WITH_DOCUMENTATION] @@ -223,7 +229,7 @@ def ui_update_all_values(WorkerWindow): first_element_condition = bool(LayerTypesList[0] != "3") if worker_parameters_conditions and filepath_condition and first_element_condition: # Update here when adding new fields to the worker - newWorker = Worker("new",LayersSizesList, ModelTypeStr, ModelType, ModelArgsStr, OptimizationType, OptimizationArgs , LossMethodStr, LossMethod, + newWorker = Worker("new",LayersSizesList, ModelTypeStr, ModelType, ModelArgsStr, OptimizationType, OptimizationArgs , LossMethodStr, LossArgs, LossMethod, LearningRate, Epochs, LayersFunctionsList, LayerTypesList, InfraType, DistributedSystemType, DistributedSystemArgs, DistributedSystemToken) newWorker.save_as_json(FilePath.as_posix(), WithDocumentation) sg.popup_auto_close("Successfully Created", keep_on_top=True) diff --git a/src_py/nerlPlanner/WinWorkerDialogDefnitions.py b/src_py/nerlPlanner/WinWorkerDialogDefnitions.py index a4a69864b..72adbbdd4 100644 --- a/src_py/nerlPlanner/WinWorkerDialogDefnitions.py +++ b/src_py/nerlPlanner/WinWorkerDialogDefnitions.py @@ -29,6 +29,7 @@ KEY_OPTIMIZER_TYPE_LIST_BOX = '-OPTIMIZER-TYPE-LIST-BOX-' KEY_OPTIMIZER_ARGS_INPUT = '-OPTIMIZER-ARGS-INPUT-' KEY_LOSS_METHOD_LIST_BOX = '-LOSS-METHOD-LIST-BOX-' +KEY_LOSS_ARGS_INPUT = '-LOSS-ARGS-INPUT-' KEY_EPOCHS_INPUT = '-WORKER-EPOCHS-INPUT-' # Distributed System and Infra keys