Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Apps] [RFC] Bundled interpreter demonstration #2297

Merged
merged 1 commit into from
Dec 19, 2018

Conversation

ajtulloch
Copy link
Contributor

@ajtulloch ajtulloch commented Dec 17, 2018

This is an example/RFC for a usecase mentioned at the recent TVM conference - specifically, allowing single-file deployment of TVM models ab initio, without having the predeploy the TVM runtime. This is done by building a single "bundled" shared object, prebaking the graph/params into this shared object, and exposing the user-visible functions to be invoked via dlopen/dlsym.

I'm not sure how generally useful this is, but I thought I'd put it up in case folks have thoughts on better ways to achieve the main goal, etc.

(the README.md is embedded below):

How to Bundle TVM Modules

This folder contains an example on how to bundle a TVM module (with the required
interpreter runtime modules such as runtime::GraphRuntime, the graph JSON, and
the params) into a single, self-contained shared object (bundle.so) which
exposes a C API wrapping the appropriate runtime::GraphRuntime instance.

This is useful for cases where we'd like to avoid deploying the TVM runtime
components to the target host in advance - instead, we simply deploy the bundled
shared-object to the host, which embeds both the model and the runtime
components. The bundle should only depend on libc/libc++.

It also contains an example code to load this shared object and invoke the
packaged TVM model instance.

Type the following command to run the sample code under the current folder,
after building TVM first.

make demo

This will:

  • Download the mobilenet0.25 model from the MXNet Gluon Model Zoo
  • Compile the model with NNVM
  • Build a bundle.so shared object containing the model specification and parameters
  • Build a demo executable that dlopen's bundle.so, instantiates the
    contained graph runtime, and invokes the run function on a random input.

@ajtulloch ajtulloch force-pushed the bundled-interpreter branch 2 times, most recently from e2798fa to e549ebf Compare December 17, 2018 01:25
@tqchen
Copy link
Member

tqchen commented Dec 17, 2018

Thanks, @ajtulloch ! please request reviews

@ajtulloch
Copy link
Contributor Author

cc @yidawang (might be interesting for you folks, possibly along the lines of existing deployment models where you bundle model + interpreter for trees in https://github.com/dmlc/treelite), @tqchen (author of apps/howto_deploy), @merrymercy (could be an interesting deployment model for TVM on constrained mobile devices).

@ajtulloch
Copy link
Contributor Author

@junrushao1994 this might be relevant to your comments in #2122 (comment) about:

The ability to get rid of a runtime, i.e. pure AOT. Having a heavy runtime is repeating the mistakes of previous generation of deep learning framework. What's more, any extra dependency means extra plain on edge devices. I think it could be great to just dump a binary which allows us to call a subset of computation (which contains no control flow, only dataflow), and let users themselves assemble these binarized when containing branches, loops etc.

}

int main(int argc, char **argv) {
auto *bundle = dlopen(argv[1], RTLD_LAZY | RTLD_LOCAL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest to print the usage, or describe it in README.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks for the suggestion.

@tqchen
Copy link
Member

tqchen commented Dec 18, 2018

LTGM, I will let @yzhliu moderate this and merge if he thinks it is OK

Copy link
Contributor

@yidawang yidawang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the work!

@yzhliu yzhliu merged commit 001ab52 into apache:master Dec 19, 2018
@yzhliu
Copy link
Member

yzhliu commented Dec 19, 2018

Thanks @ajtulloch @tqchen @yidawang This is now merged :)

@merrymercy
Copy link
Member

Should we add test for apps?
We have encountered the cases that some modifications broke the apps. (#2073)

@ajtulloch
Copy link
Contributor Author

@merrymercy absolutely - I’ll add a test in integration tests invoking this Makefile (ie ensuring “make test” runs and returns exit code 0) as a follow up to this diff?

@ajtulloch ajtulloch deleted the bundled-interpreter branch December 19, 2018 10:10
zhiics pushed a commit to zhiics/tvm that referenced this pull request Dec 21, 2018
FrozenGene pushed a commit to FrozenGene/tvm that referenced this pull request Dec 27, 2018
@ZihengJiang ZihengJiang mentioned this pull request Feb 1, 2019
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants