Skip to content
Snippets Groups Projects
README.md 4.43 KiB

PyTorch Frontend for HPVM

torch2hpvm is a PyTorch frontend for HPVM. It provides a set of API that

  • Generates a PyTorch module into HPVM-C code;
  • Exports a PyTorch dataset to ApproxHPVM dataset format;
  • Compiles the generated code into binary by invoking HPVM automatically.

Installation

pip is the recommended package manager (also available within conda). Using pip:

pip install -e ./

Getting Started

Let's look at an example that uses DNNs and weights pre-shipped with HPVM. This is found at hpvm/test/dnn_benchmarks/pytorch/test_frontend.py. Note that below we'll be working under directory hpvm/test/dnn_benchmarks/pytorch.

We'll be generating ResNet-18 into an HPVM-compiled binary. First, prepare 2 datasets for autotuning and testing.

from torch2hpvm import BinDataset
from pathlib import Path

data_dir = Path(__file__).parent / "model_params/resnet18_cifar10"
dataset_shape = 5000, 3, 32, 32
tuneset = BinDataset(data_dir / "tune_input.bin", data_dir / "tune_labels.bin", dataset_shape)
testset = BinDataset(data_dir / "test_input.bin", data_dir / "test_labels.bin", dataset_shape)