Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSoC][TMVA][SOFIE] PyTorch Parser TMVA #8684

Merged
merged 15 commits into from
Aug 31, 2021
Merged

Conversation

sanjibansg
Copy link
Contributor

@sanjibansg sanjibansg commented Jul 15, 2021

Description

Development of the functionality for parsing a PyTorch PT file to ROOT format using the Fast Inference System SOFIE for the ROOT Storage of Deep Learning Models Project of Google Summer of Code'21.

Project Link: https://summerofcode.withgoogle.com/projects/#5424575602491392

Progress

  • Parser function for extracting the model information and weights and instantiate a RModel Object
    • Support for PyTorch nn.Module, nn.Sequential, nn.ModuleList containers.
    • Supports Linear, ReLU and Transpose Layers/operations.
    • Header file for the function
    • Function implementation

Interface

The parser requires the shape and data type of the input tensors. Shape is a mandatory parameter, whereas the function defaults to Float data-type for the input tensors, if not explicitly mentioned.

Example usage

std::vector<size_t> s1{120,1};
std::vector<std::vector<size_t>> inputShape{s1};
auto model = TMVA::Experimental::SOFIE::PyTorch::Parse("trained_model_dense.pt",inputShape);

Checklist:

  • tested changes locally
    • Parser

Tests

  • Emit Files for generating header files
  • Tests for Parser
  • CMake Configuration for tests

Documentation

  • Doxygen Docs

@phsft-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@lmoneta
Copy link
Member

lmoneta commented Aug 9, 2021

@phsft-bot build just on ROOT-ubuntu2004/default with flags -Dtmva-sofie=On

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-ubuntu2004/default with flags -Dtmva-sofie=On
How to customize builds

@phsft-bot
Copy link
Collaborator

Build failed on ROOT-ubuntu2004/default.
Running on root-ubuntu-2004-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-08-09T15:28:27.613Z] CMake Error at /home/sftnight/build/workspace/root-pullrequests-build/rootspi/jenkins/root-build.cmake:1045 (message):

@sanjibansg sanjibansg marked this pull request as ready for review August 12, 2021 08:28
@sanjibansg sanjibansg changed the title [WIP][GSoC][TMVA][SOFIE] PyTorch Parser TMVA [GSoC][TMVA][SOFIE] PyTorch Parser TMVA Aug 12, 2021
@lmoneta
Copy link
Member

lmoneta commented Aug 16, 2021

@phsft-bot build just on ROOT-ubuntu2004/default with flags -Dtmva-sofie=On

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-ubuntu2004/default with flags -Dtmva-sofie=On
How to customize builds

@phsft-bot
Copy link
Collaborator

Build failed on ROOT-ubuntu2004/default.
Running on root-ubuntu-2004-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-08-16T13:50:38.925Z] CMake Error at /home/sftnight/build/workspace/root-pullrequests-build/rootspi/jenkins/root-build.cmake:1045 (message):

@lmoneta
Copy link
Member

lmoneta commented Aug 17, 2021

@phsft-bot build just on ROOT-ubuntu2004/default with flags -Dtmva-sofie=On

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-ubuntu2004/default with flags -Dtmva-sofie=On
How to customize builds

@phsft-bot
Copy link
Collaborator

Build failed on ROOT-ubuntu2004/default.
Running on root-ubuntu-2004-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Warnings:

  • [2021-08-17T10:04:09.426Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [25, 32] from the object at ‘onnx::TensorProto_Segment_default_instance’ is out of the bounds of referenced subobject ‘onnx::TensorProto_Segment::begin’ with type ‘long int’ at offset 16 [-Warray-bounds]
  • [2021-08-17T10:04:09.426Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [25, 28] from the object at ‘onnx::TypeProto_Tensor_default_instance’ is out of the bounds of referenced subobject ‘onnx::TypeProto_Tensor::shape’ with type ‘onnx::TensorShapeProto*’ at offset 16 [-Warray-bounds]
  • [2021-08-17T10:04:09.426Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [25, 28] from the object at ‘onnx::TypeProto_Map_default_instance’ is out of the bounds of referenced subobject ‘onnx::TypeProto_Map::value_type’ with type ‘onnx::TypeProto*’ at offset 16 [-Warray-bounds]
  • [2021-08-17T10:04:09.426Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [49, 56] from the object at ‘onnx::SparseTensorProto_default_instance’ is out of the bounds of referenced subobject ‘onnx::SparseTensorProto::values’ with type ‘onnx::TensorProto*’ at offset 40 [-Warray-bounds]
  • [2021-08-17T10:04:09.426Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [73, 80] from the object at ‘onnx::TrainingInfoProto_default_instance’ is out of the bounds of referenced subobject ‘onnx::TrainingInfoProto::initialization’ with type ‘onnx::GraphProto*’ at offset 64 [-Warray-bounds]
  • [2021-08-17T10:04:09.696Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [25, 32] from the object at ‘onnx::TensorProto_Segment_default_instance’ is out of the bounds of referenced subobject ‘onnx::TensorProto_Segment::begin’ with type ‘long int’ at offset 16 [-Warray-bounds]
  • [2021-08-17T10:04:09.696Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [25, 28] from the object at ‘onnx::TypeProto_Tensor_default_instance’ is out of the bounds of referenced subobject ‘onnx::TypeProto_Tensor::shape’ with type ‘onnx::TensorShapeProto*’ at offset 16 [-Warray-bounds]
  • [2021-08-17T10:04:09.696Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [25, 28] from the object at ‘onnx::TypeProto_Map_default_instance’ is out of the bounds of referenced subobject ‘onnx::TypeProto_Map::value_type’ with type ‘onnx::TypeProto*’ at offset 16 [-Warray-bounds]
  • [2021-08-17T10:04:09.696Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [49, 56] from the object at ‘onnx::SparseTensorProto_default_instance’ is out of the bounds of referenced subobject ‘onnx::SparseTensorProto::values’ with type ‘onnx::TensorProto*’ at offset 40 [-Warray-bounds]
  • [2021-08-17T10:04:09.696Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [73, 80] from the object at ‘onnx::TrainingInfoProto_default_instance’ is out of the bounds of referenced subobject ‘onnx::TrainingInfoProto::initialization’ with type ‘onnx::GraphProto*’ at offset 64 [-Warray-bounds]

Copy link
Member

@lmoneta lmoneta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @sanjibansg for adding the documentation.
The PR is ready to be merged after the Keras converter

@lmoneta
Copy link
Member

lmoneta commented Aug 30, 2021

@phsft-bot build just on ROOT-ubuntu2004/default with flags -Dtmva-sofie=On

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-ubuntu2004/default with flags -Dtmva-sofie=On
How to customize builds

@phsft-bot
Copy link
Collaborator

Build failed on ROOT-ubuntu2004/default.
Running on root-ubuntu-2004-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Warnings:

  • [2021-08-30T09:41:34.085Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [25, 32] from the object at ‘onnx::TensorProto_Segment_default_instance’ is out of the bounds of referenced subobject ‘onnx::TensorProto_Segment::begin’ with type ‘long int’ at offset 16 [-Warray-bounds]
  • [2021-08-30T09:41:34.085Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [25, 28] from the object at ‘onnx::TypeProto_Tensor_default_instance’ is out of the bounds of referenced subobject ‘onnx::TypeProto_Tensor::shape’ with type ‘onnx::TensorShapeProto*’ at offset 16 [-Warray-bounds]
  • [2021-08-30T09:41:34.085Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [25, 28] from the object at ‘onnx::TypeProto_Map_default_instance’ is out of the bounds of referenced subobject ‘onnx::TypeProto_Map::value_type’ with type ‘onnx::TypeProto*’ at offset 16 [-Warray-bounds]
  • [2021-08-30T09:41:34.085Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [49, 56] from the object at ‘onnx::SparseTensorProto_default_instance’ is out of the bounds of referenced subobject ‘onnx::SparseTensorProto::values’ with type ‘onnx::TensorProto*’ at offset 40 [-Warray-bounds]
  • [2021-08-30T09:41:34.085Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [73, 80] from the object at ‘onnx::TrainingInfoProto_default_instance’ is out of the bounds of referenced subobject ‘onnx::TrainingInfoProto::initialization’ with type ‘onnx::GraphProto*’ at offset 64 [-Warray-bounds]
  • [2021-08-30T09:41:34.085Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [25, 32] from the object at ‘onnx::TensorProto_Segment_default_instance’ is out of the bounds of referenced subobject ‘onnx::TensorProto_Segment::begin’ with type ‘long int’ at offset 16 [-Warray-bounds]
  • [2021-08-30T09:41:34.085Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [25, 28] from the object at ‘onnx::TypeProto_Tensor_default_instance’ is out of the bounds of referenced subobject ‘onnx::TypeProto_Tensor::shape’ with type ‘onnx::TensorShapeProto*’ at offset 16 [-Warray-bounds]
  • [2021-08-30T09:41:34.085Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [25, 28] from the object at ‘onnx::TypeProto_Map_default_instance’ is out of the bounds of referenced subobject ‘onnx::TypeProto_Map::value_type’ with type ‘onnx::TypeProto*’ at offset 16 [-Warray-bounds]
  • [2021-08-30T09:41:34.085Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [49, 56] from the object at ‘onnx::SparseTensorProto_default_instance’ is out of the bounds of referenced subobject ‘onnx::SparseTensorProto::values’ with type ‘onnx::TensorProto*’ at offset 40 [-Warray-bounds]
  • [2021-08-30T09:41:34.085Z] /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: ‘void* _builtin_memset(void*, int, long unsigned int)’ offset [73, 80] from the object at ‘onnx::TrainingInfoProto_default_instance’ is out of the bounds of referenced subobject ‘onnx::TrainingInfoProto::initialization’ with type ‘onnx::GraphProto*’ at offset 64 [-Warray-bounds]

Copy link
Member

@lmoneta lmoneta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks good, we need just to apply the same fixes done in the Keras converters

tmva/pymva/inc/TMVA/RModelParser_PyTorch.h Outdated Show resolved Hide resolved
tmva/pymva/inc/TMVA/RModelParser_PyTorch.h Outdated Show resolved Hide resolved
tmva/pymva/inc/TMVA/RModelParser_PyTorch.h Outdated Show resolved Hide resolved
tmva/pymva/test/EmitFromPyTorch.cxx Show resolved Hide resolved
1) Added support for Tensors of Dynamic Axes
2) Modified Map for DType for PyTorch
1) Fix    : segmentation violation by removing the Py_XDECREF()
2) Remove : RModelParser_Common.h and moved helper functions to SOFIE_common & under namespace SOFIE::PyTorch
3) Modify : Casting and usage of PyArrayObject* (now a float* is used instead of RTensor)
4) Add    : Runtime error catch if Python String is not successfully run
5) Modify : Minor improvements and modifications in code structure and naming conventions
1) Added GTests for RModelParser_PyTorch
2) Added EmitFromPyTorch to generate header files
3) Configured CMake for tests
1. Refactor RModelParser_PyTorch
2. Call to AddBlasRoutines() while adding Gemm Node
@lmoneta
Copy link
Member

lmoneta commented Aug 30, 2021

@phsft-bot build!

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Collaborator

Build failed on mac11.0/cxx17.
Running on macphsft20.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

Copy link
Member

@lmoneta lmoneta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the changes. The PR is now ready to be merged

@lmoneta lmoneta merged commit a5541b7 into root-project:master Aug 31, 2021
@sanjibansg sanjibansg deleted the pytorch branch September 5, 2021 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants