Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFunction_MLP.cxx
Go to the documentation of this file.
2
3
9
10namespace TMVA {
11namespace Experimental {
12namespace SOFIE {
13
14RFunction_MLP::RFunction_MLP(FunctionTarget target, Int_t numLayers, Activation activation_function, bool activate_final, GraphType gType):
15 RFunction_Update(target, gType), fNumLayers(numLayers), fActivationFunction(activation_function), fActivateFinal(activate_final)
16{
17 // assuming all the linear layers has a kernel and a bias initialized tensors
18 if (fActivateFinal) {
20 throw std::runtime_error("TMVA SOFIE GNN doesn't currently supports the provided activation function for " +
21 fFuncName + " update.");
22 }
23 function_block->AddOutputTensorNameList({fFuncName + "Relu" + std::to_string(fNumLayers)});
24 } else {
25 function_block->AddOutputTensorNameList({fFuncName + "Gemm" + std::to_string(fNumLayers)});
26 }
27}
28
30
31 std::string fGemmInput;
33 std::unique_ptr<ROperator> op_concat;
34 op_concat.reset(new ROperator_Concat(fInputTensors,1,0,fFuncName+"InputConcat"));
35 function_block->AddOperator(std::move(op_concat));
36 fGemmInput = fFuncName+"InputConcat";
37
39 fGemmInput = fInputTensors[0];
40 }
41
42 std::unique_ptr<ROperator> op_gemm;
43 for(int i=0; i<fNumLayers-1; ++i) {
44 double beta = (fBiasTensors[i].empty()) ? 0. : 1.;
45 op_gemm.reset(new ROperator_Gemm<float>(1.0,beta,0,0,fGemmInput,UTILITY::Clean_name(fKernelTensors[i]),UTILITY::Clean_name(fBiasTensors[i]),fFuncName+"Gemm"+std::to_string(i)));
46 function_block->AddOperator(std::move(op_gemm));
47 fGemmInput = fFuncName+"Gemm"+i;
49 std::unique_ptr<ROperator> op_relu;
50 op_relu.reset(new ROperator_Relu<float>(fFuncName+"Gemm"+std::to_string(i), fFuncName+"Relu"+std::to_string(i)));
51 function_block->AddOperator(std::move(op_relu));
52 fGemmInput = fFuncName+"Relu"+i;
53
54 }
55 }
56 double beta = (fBiasTensors.back().empty()) ? 0. : 1.;
57 op_gemm.reset(new ROperator_Gemm<float>(1.0,beta,0,0,fGemmInput,UTILITY::Clean_name(fKernelTensors.back()),UTILITY::Clean_name(fBiasTensors.back()),fFuncName+"Gemm"+std::to_string(fNumLayers)));
58 function_block->AddOperator(std::move(op_gemm));
59 if(fActivateFinal) {
61 std::unique_ptr<ROperator> op_relu;
62 op_relu.reset(new ROperator_Relu<float>(fFuncName+"Gemm"+std::to_string(fNumLayers), fFuncName+"Relu"+std::to_string(fNumLayers)));
63 function_block->AddOperator(std::move(op_relu));
64 }
65 }
66
67
68 if(fAddlOp.size()) {
69 for(auto &i:fAddlOp) {
70 std::unique_ptr<ROperator> tmp(i);
71 function_block->AddOperator(std::move(tmp));
72 }
73 }
74}
75
76void RFunction_MLP::AddLayerNormalization(int axis, float epsilon, size_t stashType, const std::string &nameX,
77 const std::string &nameScale, const std::string &nameB, const std::string &nameY) {
78 auto op_layerNorm = new ROperator_LayerNormalization<float>(axis, epsilon, stashType, nameX,
79 nameScale, nameB, nameY, "", "");
80 fAddlOp.push_back((op_layerNorm));
81}
82
83}
84}
85}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
std::vector< std::string > fKernelTensors
RFunction_MLP(FunctionTarget target, Int_t numLayers, Activation activation_function=Activation::RELU, bool activate_final=false, GraphType gType=GraphType::GNN)
void AddLayerNormalization(int axis, float epsilon, size_t stashType, const std::string &nameX, const std::string &nameScale, const std::string &nameB, const std::string &nameY)
std::vector< std::string > fBiasTensors
std::shared_ptr< RModel > function_block
Definition RFunction.hxx:35
std::vector< std::string > fInputTensors
Definition RFunction.hxx:38
std::string Clean_name(std::string input_tensor_name)
create variable transformations