15import torch.nn as nn\n\
17model = nn.Sequential(\n\
24criterion = nn.MSELoss()\n\
25optimizer = torch.optim.SGD(model.parameters(),lr=0.01)\n\
30for i in range(500):\n\
32 loss = criterion(y_pred,y)\n\
33 optimizer.zero_grad()\n\
38m = torch.jit.script(model)\n\
39torch.jit.save(m,'PyTorchModel.pt')\n";
42void TMVA_SOFIE_PyTorch(){
48 m.SaveSource(
"make_pytorch_model.py");
49 gSystem->Exec(
"python3 make_pytorch_model.py");
53 std::vector<size_t> inputTensorShapeSequential{2, 32};
54 std::vector<std::vector<size_t>> inputShapesSequential{inputTensorShapeSequential};
79 std::cout <<
"Shape of tensor \"0weight\": ";
80 for (
auto &it : tensorShape) {
81 std::cout << it <<
",";
83 std::cout<<
"\n\nData type of tensor \"0weight\": ";
R__EXTERN TSystem * gSystem
void PrintGenerated(std::ostream &os=std::cout)
std::vector< size_t > GetTensorShape(const std::string &name) const
void PrintIntermediateTensors() const
bool CheckIfTensorAlreadyExist(std::string tensor_name)
void OutputGenerated(std::string filename="", bool append=false)
void PrintRequiredInputTensors() const
void Generate(std::underlying_type_t< Options > options, int batchSize=-1, long pos=0, bool verbose=false)
void PrintInitializedTensors() const
ETensorType GetTensorType(std::string name) const
Class supporting a collection of lines with C++ code.
RModel Parse(std::string filepath, std::vector< std::vector< size_t > > inputShapes, std::vector< ETensorType > dtype)
Parser function for translating PyTorch .pt model into a RModel object.
std::string ConvertTypeToString(ETensorType type)