Update readme.md of shark_runner

Updated the readme.md of shark_runner and added setup.py for pip
installation.
This commit is contained in:
Prashant Kumar
2022-03-31 19:23:59 +00:00
parent d11accd6ad
commit 59485f571e
6 changed files with 57 additions and 23 deletions

11
requirements.txt Normal file
View File

@@ -0,0 +1,11 @@
-f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
--pre
numpy
torch
torchvision
# Build requirements.
pybind11
wheel

13
setup.py Normal file
View File

@@ -0,0 +1,13 @@
from setuptools import find_packages
from setuptools import setup
setup(
name="shark",
version="0.0.1",
description="The Shark Runner provides inference and training APIs to run deep learning models on Shark Runtime.",
author="Nod Labs",
author_email="stdin@nod.com",
url="https://github.com/NodLabs/dSHARK",
packages=find_packages(exclude=('dSHARK','examples')),
)

View File

@@ -4,19 +4,44 @@ The Shark Runner provides inference and training APIs to run deep learning model
# How to configure.
### Build [torch-mlir](https://github.com/llvm/torch-mlir) and [iree](https://github.com/google/iree) including [iree python bindings](https://google.github.io/iree/building-from-source/python-bindings-and-importers/#using-the-python-bindings)
## Check out the code
### Setup Python Environment
```shell
#Activate your virtual environment.
export TORCH_MLIR_BUILD_DIR=/path/to/torch-mlir/build
export IREE_BUILD_DIR=/path/to/iree-build
source set_dep_pypaths.sh
git clone https://github.com/NodLabs/dSHARK.git
cd dSHARK
```
## Setup your Python VirtualEnvironment and Dependencies
```shell
python -m venv shark_venv
source shark_venv/bin/activate
# Some older pip installs may not be able to handle the recent PyTorch deps
python -m pip install --upgrade pip
# Install latest PyTorch nightlies and build requirements.
python -m pip install -r requirements.txt
```
## Install dependent packages
```shell
# Install latest torch-mlir release.
python -m pip install --find-links https://github.com/llvm/torch-mlir/releases torch-mlir
# Install latest IREE release.
python -m pip install --find-links https://github.com/google/iree/releases iree-compiler iree-runtime
# Install functorch
python -m pip install ninja
python -m pip install "git+https://github.com/pytorch/functorch.git"
# Install shark_runner from the current path.
python -m pip install .
```
### Run a demo script
```shell
python resnet50.py
cd shark_runner/examples/
python resnet50_script.py
```
### Shark Inference API

0
shark_runner/__init__.py Normal file
View File

View File

@@ -72,7 +72,7 @@ shark_module = SharkInference(Resnet50Module(), (img,))
## Can pass any img or input to the forward module.
results = shark_module.forward((img,))
print("The top 3 results obtained via torch-mlir via iree-backend is:")
print("The top 3 results obtained via shark_runner is:")
print(top3_possibilities(torch.from_numpy(results)))
print()

View File

@@ -1,15 +0,0 @@
echo "Don't forget to activate your venv before calling this script";
export SCRIPTPATH=$(dirname "$(realpath BASH_SOURCE)");
if [ -z ${TORCH_MLIR_BUILD_DIR+x} ]; then echo "TORCH_MLIR_BUILD_DIR is unset"; exit 1; else echo "TORCH_MLIR_BUILD_DIR is set to '$TORCH_MLIR_BUILD_DIR'"; fi
if [ -z ${IREE_BUILD_DIR+x} ]; then echo "IREE_BUILD_DIR is unset"; exit 1; else echo "IREE_BUILD_DIR is set to '$IREE_BUILD_DIR'"; fi
if [ -z ${SHARK_SAMPLES_DIR+x} ]; then echo "SHARK_SAMPLES_DIR is unset, using '$SCRIPTPATH'"; export SHARK_SAMPLES_DIR=$SCRIPTPATH; else echo "SHARK_SAMPLES_DIR is set to '$SHARK_SAMPLES_DIR'"; fi
export PYTHONPATH=${PYTHONPATH}:${IREE_BUILD_DIR}/compiler-api/python_package:${IREE_BUILD_DIR}/bindings/python
export PYTHONPATH=${PYTHONPATH}:${TORCH_MLIR_BUILD_DIR}/tools/torch-mlir/python_packages/torch_mlir:${TORCH_MLIR_BUILD_DIR}/../examples
export PYTHONPATH=${PYTHONPATH}:${SHARK_SAMPLES_DIR}