Add PyTorch TorchScript backend for vision benchmarks#2578
Open
amd-arsuresh wants to merge 1 commit into
Open
Conversation
Add a new backend (pytorch-torchscript) that loads TorchScript models exported via torch.jit.trace or torch.jit.script. This enables running inference with pre-traced PyTorch models (.pt files) without requiring ONNX conversion. Changes: - Add backend_pytorch_torchscript.py with BackendPytorchTorchScript class - Register the new backend in main.py get_backend() - Fix resnet50-pytorch profile: change backend from 'tensorflow' (incorrect) to 'pytorch-torchscript'
Contributor
|
MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a new
pytorch-torchscriptbackend for the vision classification and detection benchmarks that loads TorchScript models exported viatorch.jit.traceortorch.jit.script.Problem
The existing
resnet50-pytorchprofile inSUPPORTED_PROFILESincorrectly sets"backend": "tensorflow", making it non-functional. Thepytorch-nativebackend usestorch.load()and then tries to access ONNX graph attributes (model.graph.initializer,model.graph.input), which fails on TorchScript models; and thepytorchbackend uses caffe2/ONNX, requiring an ONNX model file rather than a native PyTorch format.There is no backend that can load standard TorchScript
.ptfiles (the most common way to serialize PyTorch models for deployment).Changes
vision/classification_and_detection/python/backend_pytorch_torchscript.pyBackendPytorchTorchScriptclass that usestorch.jit.load()to load TorchScript modelsvision/classification_and_detection/python/main.pypytorch-torchscriptinget_backend()resnet50-pytorchprofile: change backend fromtensorflowtopytorch-torchscriptUsage
Testing
Tested with resnet50 TorchScript model on CPU - loads and runs inference correctly.