Skip to content

Commit

Permalink
Merge pull request #368 from leondavi/add_tiles_dist_sys
Browse files Browse the repository at this point in the history
[NERLPLANNER] add distributed type tiles
  • Loading branch information
leondavi authored Jul 13, 2024
2 parents b280e56 + 9dbc55b commit d2b6830
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src_cpp/common/worker_definitions_ag.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ enum ModelTypeEnum{MODEL_TYPE_NN=0,MODEL_TYPE_APPROXIMATION=1,MODEL_TYPE_CLASSIF
enum OptimizerEnum{OPTIMIZER_GD=0,OPTIMIZER_CGD=1,OPTIMIZER_SGD=2,OPTIMIZER_QUASINEUTON=3,OPTIMIZER_LVM=4,OPTIMIZER_ADAM=5};
enum LossMethodEnum{LOSS_METHOD_SSE=1,LOSS_METHOD_MSE=2,LOSS_METHOD_NSE=3,LOSS_METHOD_MINKOWSKIE=4,LOSS_METHOD_WSE=5,LOSS_METHOD_CEE=6};
enum InfraTypeEnum{INFRA_TYPE_OPENNN=0,INFRA_TYPE_WOLFENGINE=1};
enum WorkerDistributedSystemTypeEnum{WORKER_DISTRIBUTED_SYSTEM_TYPE_NONE=0,WORKER_DISTRIBUTED_SYSTEM_TYPE_FEDCLIENTAVG=1,WORKER_DISTRIBUTED_SYSTEM_TYPE_FEDSERVERAVG=2,WORKER_DISTRIBUTED_SYSTEM_TYPE_FEDCLIENTWEIGHTEDAVGCLASSIFICATION=3,WORKER_DISTRIBUTED_SYSTEM_TYPE_FEDSERVERWEIGHTEDAVGCLASSIFICATION=4,WORKER_DISTRIBUTED_SYSTEM_TYPE_FEDCLIENTAE=5,WORKER_DISTRIBUTED_SYSTEM_TYPE_FEDSERVERAE=6};
enum WorkerDistributedSystemTypeEnum{WORKER_DISTRIBUTED_SYSTEM_TYPE_NONE=0,WORKER_DISTRIBUTED_SYSTEM_TYPE_FEDCLIENTAVG=1,WORKER_DISTRIBUTED_SYSTEM_TYPE_FEDSERVERAVG=2,WORKER_DISTRIBUTED_SYSTEM_TYPE_FEDCLIENTWEIGHTEDAVGCLASSIFICATION=3,WORKER_DISTRIBUTED_SYSTEM_TYPE_FEDSERVERWEIGHTEDAVGCLASSIFICATION=4,WORKER_DISTRIBUTED_SYSTEM_TYPE_FEDCLIENTAE=5,WORKER_DISTRIBUTED_SYSTEM_TYPE_FEDSERVERAE=6,WORKER_DISTRIBUTED_SYSTEM_TYPE_TILES=7};

} // namespace nerlnet
19 changes: 11 additions & 8 deletions src_erl/NerlnetApp/src/Bridge/nerlTests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ run_tests()->
NerlworkerTestFunc = fun(_Rounds) -> Performance = 0, nerlworker_test(NeuralNetworkTestingModelList, Performance) end,
NerlworkerTestName = "nerlworker_test",
test_envelope_nif_performance(NerlworkerTestFunc, NerlworkerTestName, length(NeuralNetworkTestingModelList) ),
nerltest_print("count label test"),

CountLabelTestName = "test_count_label",
CountLabelTestFunc = fun(_Rounds) -> test_count_label_nif() end,
CountLabelTestFunc = fun(_Rounds) -> count_label_nif_test() end,
test_envelope(CountLabelTestFunc, CountLabelTestName, 1 ),
nerltest_print("Tests Completed"),
ok.
Expand Down Expand Up @@ -305,7 +305,10 @@ nerlworker_test_generate_data(LayersSizes, LayerTypes, NumOfSamples) -> %% Ask D
{NerlTensor , Type} = nerlNIF:nerltensor_conversion({ErlDataTensor,erl_float} , float),
{NerlTensor , Type , ErlDataTensor , erl_float , NumOfFeatures , NumOfLabels}.

test_count_label_nif() ->
count_label_nif_test() ->
% TODO - Ori please move the network configuration to neural_networks_testing_models.hrl
% Please add performance evaluation - Run this test 10-20 rounds and accumulate performance of nif
% By adding tic toc before and after the NIF
ModelId = erlang:unique_integer([positive]),
ModelType = "0",
ModelArgs = "",
Expand All @@ -315,7 +318,7 @@ test_count_label_nif() ->
OptimizerType = "2",
OptimizerArgs = "",
LossMethod = "2",
DistributedSystemType = "3",
DistributedSystemType = "3", % TODO this should be derived from AG macro
DistributedSystemArg = "",
DimMaxDimX = ?NERLWORKER_DISTRIBUTED_FED_WEIGHTED_AVG_CLASSIFIER_DATA_DIM_X,
DimMinDimX = ?NERLWORKER_DISTRIBUTED_FED_WEIGHTED_AVG_CLASSIFIER_DATA_MIN_DIM_X,
Expand All @@ -333,8 +336,8 @@ test_count_label_nif() ->
LenActualDataIf = LenActualData
end,
DataRand = generate_nerltensor(float,?TEST_LABEL_COUNT_NUMOF_SAMPLES,LenActualDataIf,1),
LayersSizes = nerl:string_format("~p,~p",[LenActualDataIf-LenActualLabels,LenActualLabels]),
LayersTypes = "1,3",
LayersSizes = nerl:string_format("~p,~p",[LenActualDataIf-LenActualLabels,LenActualLabels]),
LayersTypes = "1,3",% Please move it to neural_networks_testing_models.hrl as part of NN configuration
nerlNIF:test_nerlworker_nif(ModelId,ModelType,ModelArgs,LayersSizes, LayersTypes,
LayersFunctionalityCodes, LearningRate, Epochs, OptimizerType,
OptimizerArgs, LossMethod, DistributedSystemType, DistributedSystemArg),
Expand All @@ -346,11 +349,11 @@ test_count_label_nif() ->
{_,DataRandRes} = lists:split(3, DataRand),
Sum = get_label_count(LenActualLabels,LenActualDataIf,SumInit,DataRandRes,0) ,
{_,LabelCountRes} = lists:split(3, LabelCountFloat),
nerlNIF:remove_nerlworker_nif(ModelId),
if
(Sum == LabelCountRes) -> nerltest_print("Label count test passed");
true -> throw(nerl:string_format("Label count test failed ~n Sum: ~p ~n LabelCount: ~p",[Sum,LabelCountRes]))
end,
nerlNIF:remove_nerlworker_nif(ModelId).
end.


get_label_count(LenLabel,LenData,Sum,Data,N) ->
Expand Down
3 changes: 3 additions & 0 deletions src_erl/NerlnetApp/src/Client/clientWorkersFunctions.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

get_distributed_worker_behavior(ClientEtsRef, DistributedSystemType , WorkerName , DistributedSystemArgs , DistributedSystemToken) ->
case DistributedSystemType of
?DC_DISTRIBUTED_SYSTEM_TYPE_TILES_IDX_STR ->
DistributedBehaviorFunc = fun workerNN:controller/2,
DistributedWorkerData = {tiles, DistributedSystemArgs, DistributedSystemToken};
?DC_DISTRIBUTED_SYSTEM_TYPE_NONE_IDX_STR ->
DistributedBehaviorFunc = fun workerNN:controller/2,
DistributedWorkerData = none;
Expand Down
3 changes: 3 additions & 0 deletions src_erl/NerlnetApp/src/worker_definitions_ag.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
-define(DC_DISTRIBUTED_SYSTEM_TYPE_FEDSERVERWEIGHTEDAVGCLASSIFICATION_KEY_ATOM,fedServerWeightedAvgClassification).
-define(DC_DISTRIBUTED_SYSTEM_TYPE_FEDCLIENTAE_KEY_ATOM,fedClientAE).
-define(DC_DISTRIBUTED_SYSTEM_TYPE_FEDSERVERAE_KEY_ATOM,fedServerAE).
-define(DC_DISTRIBUTED_SYSTEM_TYPE_TILES_KEY_ATOM,tiles).

-define(DC_DISTRIBUTED_SYSTEM_TYPE_NONE_IDX_STR,"0").
-define(DC_DISTRIBUTED_SYSTEM_TYPE_FEDCLIENTAVG_IDX_STR,"1").
Expand All @@ -46,6 +47,7 @@
-define(DC_DISTRIBUTED_SYSTEM_TYPE_FEDSERVERWEIGHTEDAVGCLASSIFICATION_IDX_STR,"4").
-define(DC_DISTRIBUTED_SYSTEM_TYPE_FEDCLIENTAE_IDX_STR,"5").
-define(DC_DISTRIBUTED_SYSTEM_TYPE_FEDSERVERAE_IDX_STR,"6").
-define(DC_DISTRIBUTED_SYSTEM_TYPE_TILES_IDX_STR,"7").

-define(DC_DISTRIBUTED_SYSTEM_TYPE_NONE_IDX,0).
-define(DC_DISTRIBUTED_SYSTEM_TYPE_FEDCLIENTAVG_IDX,1).
Expand All @@ -54,6 +56,7 @@
-define(DC_DISTRIBUTED_SYSTEM_TYPE_FEDSERVERWEIGHTEDAVGCLASSIFICATION_IDX,4).
-define(DC_DISTRIBUTED_SYSTEM_TYPE_FEDCLIENTAE_IDX,5).
-define(DC_DISTRIBUTED_SYSTEM_TYPE_FEDSERVERAE_IDX,6).
-define(DC_DISTRIBUTED_SYSTEM_TYPE_TILES_IDX,7).

-define(DC_INFRA_TYPE_OPENNN_KEY_ATOM,opennn).
-define(DC_INFRA_TYPE_WOLFENGINE_KEY_ATOM,wolfengine).
Expand Down
3 changes: 2 additions & 1 deletion src_py/nerlPlanner/JsonElementWorkerDefinitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
("FedClientWeightedAvgClassification" , "3"),
("FedServerWeightedAvgClassification" , "4"),
("FedClientAE" , "5"),
("FedServerAE" , "6")
("FedServerAE" , "6"),
("tiles", "7")
])

InfraTypeMapping = OrderedDict([
Expand Down
3 changes: 2 additions & 1 deletion tests/NerlnetNifTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ COMPILE_NERLTENSOR="compile:file(\"nerlTensor.erl\")"

COMPILE_FILES="$COMPILE_NERL,$COMPILE_NERLNIF,$COMPILE_NERLTEST,$COMPILE_NERLTENSOR"

erl -noshell -eval "$COMPILE_FILES, nerlTests:run_tests()." -s init stop > "$NERLNET_TEST_DIR/$LOG_FILE" #TODO fix
erl -noshell -eval "$COMPILE_FILES, nerlTests:run_tests()." -s init stop > "$NERLNET_TEST_DIR/$LOG_FILE"
rc=$(echo $?)
cat "$NERLNET_TEST_DIR/$LOG_FILE"
cd -

echo "Test returned: $rc"
exit $rc

0 comments on commit d2b6830

Please sign in to comment.