jwfromm opened a new pull request #7823: URL: https://github.com/apache/tvm/pull/7823
As noted in many of @CircleSpin's recent PRs, TVMC has an excellent set of utilities to make python scripting in TVM a more approachable and intuitive experience for new users. This PR introduces an object oriented approach that we believe will be a much smoother introduction to working in TVM from Python. Before jumping into the design discussion, I want to note that we were careful to make sure that the command line TVMC workflow was minimally effected by this change. In short, the goal this PR is to reduce a full TVM workflow into a small set of intuitive function calls, one example of which can be seen in `test_model.py`, which I'll include here for discussion. ``` tvmc_model = tvmc.load(onnx_resnet50) tvmc.tune(tvmc_model, target="llvm") tvmc_package = tvmc.compile(tvmc_model, "llvm") result = tvmc.run(tvmc_package, device="cpu") print(result) # Will print a pretty time estimator breakdown ``` The above code uses three new classes defined in `tvmc/model.py`: `TVMCModel`, `TVMCPackage`, and `TVMCResult`. A `TVMCModel` is a wrapper around a precompiled model in TVMC. It can be generated either by calling `tvmc.load` or by pointing it to a previously saved TVMCModel. The class itself is very straightforward and most of its functionality is for saving and loading itself from disk and producing TVMCPackages. Being able to save and load TVMCModel's directly is convenient when users dont want to have to run a relay importer everytime they start up a new python instance. Calling `tvmc.compile` on a TVMCModel now will produce a package using `export_model_library_format` which was introduced in PR #7533. This format is actually very similar to what TVMC was previously using and will likely become the standard way for saving compiled artifacts going forward. The produced package is then used to create a TVMCPackage object which contains all the information needed to run the model. The TVMCPackage is passed to `tvmc.run` which now returns a `TVMCResult`, a very simple wrapper around the runtime measurements and produced results. I'd love to hear what you guys think of this flow and design and am happy to discuss any decisions in more detail. Assuming that this work is well received, we're planning on writing a tutorial for new users based on it. Also included in this PR are a change to `auto_scheduler.HardwareParams` such that all arguments are optional. When an argument is provided as `None`, it will now extract the default value for the current target. I've also changed the default values for hardware parameters in TVMC to be None to reflect this change. This should make the default behavior of tvmc more consistent with other workflows. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
