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};
61 model.OutputGenerated(
"PyTorchModel.hxx");
65 model.PrintRequiredInputTensors();
69 model.PrintInitializedTensors();
73 model.PrintIntermediateTensors();
76 std::cout <<
"\n\nTensor \"0weight\" already exist: " << std::boolalpha << model.CheckIfTensorAlreadyExist(
"0weight")
78 std::vector<size_t> tensorShape = model.GetTensorShape(
"0weight");
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\": ";
89 model.PrintGenerated();
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)