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

Add a PyTorch worker #212

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add a PyTorch worker #212

wants to merge 3 commits into from

Conversation

ZchiPitt
Copy link
Contributor

Summary of Changes

  • Add a PyTorch worker that can take a PT model and run the inference.
  • Test with models from PyTorch model zoo including MNIST classifer, Resnet50 etc.
  • Updated the download script and the docker scripts as well.

Closes #211

Motivation

We need to add a PyTorch worker that accepts the name of an PyTorch model file as an argument and compiles and evaluates it.

Implementation

  • Add pytorch.cpp under src/amdinfer/workers
  • Add test_pytorch.py
  • Updated related download and docker scripts

Notes

There will be a new image built with PyTorch environment

@ZchiPitt ZchiPitt requested a review from varunsh-xilinx as a code owner July 25, 2023 21:42
@gbuildx
Copy link
Collaborator

gbuildx commented Jul 25, 2023

Build failed!

1 similar comment
@gbuildx
Copy link
Collaborator

gbuildx commented Jul 26, 2023

Build failed!

src/amdinfer/pre_post/image_preprocess.hpp Outdated Show resolved Hide resolved
src/amdinfer/pre_post/mnist_postprocess.hpp Show resolved Hide resolved
src/amdinfer/workers/CMakeLists.txt Outdated Show resolved Hide resolved
src/amdinfer/workers/pytorch.cpp Outdated Show resolved Hide resolved

if (parameters->has("input_shape")) {
std::string shape_str = parameters->get<std::string>("input_shape");
this->input_shape = parseShape(shape_str, this->input_dim, ",");
Copy link
Member

Choose a reason for hiding this comment

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

how does this system work if there are multiple input or output tensors of different sizes? e.g. for yolo, there will be multiple output tensors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm considering adding this in the next PR.
That will also work with the added object-detection model test. These can be put in one PR.

For the implementation, I'm thinking passing the input shapes like "224,224,3;28,28,1". Tensors separated by ";" and each dim separated by ","

What do you think? Any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also, i'm a bit unclear about how the multiple tensors would work with the batch?
We currently define the input PT tensor as

// Initialize a PT tensor with required shape
  std::vector<int64_t> new_input_shape = {tensors};
  std::copy(this->input_shape.begin(), this->input_shape.end(),
            std::back_inserter(new_input_shape));

In this case, how would the PT tensor definition look like with multiple shapes?

Copy link
Member

Choose a reason for hiding this comment

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

The PT+ZenDNN implementation you copied here did not support multiple input/output tensors so your code will need to be updated for that. This is why I wanted a test for a non object classification model to check the generality of yours.

@gbuildx
Copy link
Collaborator

gbuildx commented Jul 29, 2023

Build failed!

ZchiPitt added 3 commits July 28, 2023 19:36
…Test with models from PyTorch model zoo including MNIST classifer, Resnet50 etc. Updated the download script and the docker scripts as well.

Signed-off-by: Chi Zhang <[email protected]>
Signed-off-by: Chi Zhang <[email protected]>
…pdate the docstring of mnist_postprocess* Gate the src/workers CMake by enabling libPytorch via the env variable ENABLE_PYTORCH* Add a device parameter for the pytorch worker

Signed-off-by: Chi Zhang <[email protected]>
@gbuildx
Copy link
Collaborator

gbuildx commented Jul 29, 2023

Build failed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a PyTorch worker
3 participants