From 50c680519ca5dd2cd94a0bd603d54e7b78e25dba Mon Sep 17 00:00:00 2001 From: Yifan Zhao <yifanz16@illinois.edu> Date: Tue, 16 Mar 2021 22:21:19 -0500 Subject: [PATCH] Added example for hpvm bin tuning --- README.md | 5 +++++ examples/tune_hpvm_bin.py | 36 ++++++++++++++++++++++++++++++++++++ predtuner/__init__.py | 1 + 3 files changed, 42 insertions(+) create mode 100644 examples/tune_hpvm_bin.py diff --git a/README.md b/README.md index 41c4809..a17e0fe 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,8 @@ up a working environment. If you're using conda, do conda env create -n predtuner -f env.yaml conda activate predtuner ``` + +## Tuning with HPVM Binary + +This branch (`hpvm`) contains beta support for HPVM binaries. +Please refer to `examples/tune_hpvm_bin.py` for an example with explanations. diff --git a/examples/tune_hpvm_bin.py b/examples/tune_hpvm_bin.py new file mode 100644 index 0000000..8dfffc7 --- /dev/null +++ b/examples/tune_hpvm_bin.py @@ -0,0 +1,36 @@ +import site +from pathlib import Path + +import torch +from torch.utils.data.dataloader import DataLoader +from torch.utils.data.dataset import Subset + +site.addsitedir(Path(__file__).parent.parent.absolute().as_posix()) +from predtuner import PipedBinaryApp, config_pylogger +from predtuner.model_zoo import CIFAR, VGG16Cifar10 + +# Set up logger to put log file in /tmp +msg_logger = config_pylogger(output_dir="/tmp", verbose=True) + +# TODO: fill in these 2 paths with path to binary file and path to json file, respectively: +binary_file, metadata_file = "", "" +# Create a `PipedBinaryApp` that communicates with HPVM bin. +# "TestHPVMApp" is an identifier of this app (used in logging, etc.) and can be anything. +# Other arguments: +# base_dir: which directory to run binary in (default: the dir the binary is in) +# qos_relpath: the name of accuracy file generated by the binary. +# Defaults to "final_accuracy". For HPVM apps this shouldn't change. +# model_storage_folder: where to put saved P1/P2 models. +app = PipedBinaryApp("TestHPVMApp", binary_file, metadata_file) +# Tuning procedure is exactly the same as that for PyTorch DNN. +# Please refer to `./tune_vgg16_cifar10.py` for details. +tuner = app.get_tuner() +tuner.tune(100, 3.0, 3.0, True, 50, cost_model="cost_linear") +tuner.dump_configs("configs.json") +fig = tuner.plot_configs(show_qos_loss=True) +fig.savefig("configs.png", dpi=300) +app.dump_hpvm_configs(tuner.best_configs, "hpvm_confs.txt") + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/predtuner/__init__.py b/predtuner/__init__.py index c11d18f..babe3e0 100644 --- a/predtuner/__init__.py +++ b/predtuner/__init__.py @@ -9,5 +9,6 @@ from .modeledapp import ( QoSModelP1, QoSModelP2, ) +from .pipedbin import PipedBinaryApp from .torchapp import TorchApp, TorchApproxKnob from .torchutil import accuracy -- GitLab