Skip to content

Commit

Permalink
update nnvm.runtime to tvm.contrib.graph_runtime (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
Huyuwei authored and tqchen committed May 29, 2018
1 parent 79a0603 commit 02e1099
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
1 change: 0 additions & 1 deletion nnvm/docs/api/python/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ For user

compiler
frontend
runtime
symbol
graph
top
8 changes: 0 additions & 8 deletions nnvm/docs/api/python/runtime.rst

This file was deleted.

4 changes: 2 additions & 2 deletions nnvm/python/nnvm/compiler/build_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import logging
import tvm
from tvm.contrib import graph_runtime
from . import graph_attr, graph_util
from .. import graph as _graph
from .. import runtime

OPT_PASS_LEVEL = {
"SimplifyInference": 2,
Expand Down Expand Up @@ -220,7 +220,7 @@ def _run_graph(graph, params):
_, oshape = graph_util.infer_shape(graph, **shape)
_, odtype = graph_util.infer_dtype(graph, **dtype)
graph, libmod, _ = build(graph, target, shape, dtype)
m = runtime.create(graph, libmod, ctx)
m = graph_runtime.create(graph, libmod, ctx)
set_input, run, get_output = m["set_input"], m["run"], m["get_output"]
for k, v in params.items():
set_input(k, tvm.nd.array(v))
Expand Down
22 changes: 11 additions & 11 deletions nnvm/tutorials/mobilenet_inference_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
######################################################################
# Register the NVCC Compiler Option
# ---------------------------------
# NNVM optimizes the graph and relies on TVM to generate fast
# GPU code, to get the maximum performance, we need to enable
# nvcc's compiler hook. This gives better performance than nvrtc mode.
# NNVM optimizes the graph and relies on TVM to generate fast GPU code.
# To get the maximum performance, we need to enable nvcc's compiler hook.
# This gives better performance than nvrtc mode.

@tvm.register_func
def tvm_callback_cuda_compile(code):
Expand All @@ -28,7 +28,7 @@ def tvm_callback_cuda_compile(code):
# Prepare the Benchmark
# ---------------------
# We construct a standard imagenet inference benchmark.
# We use nnvm's testing utility to produce the model description and random parameters that so the example does not
# We use nnvm's testing utility to produce the model description and random parameters so that the example does not
# depend on a specific front-end framework.
#
# .. note::
Expand All @@ -46,17 +46,17 @@ def tvm_callback_cuda_compile(code):
batch_size=1, image_shape=image_shape)

######################################################################
# Compile The Graph
# Compile the Graph
# -----------------
# NNVM needs two things to compile a deep learning model:
#
# - net which is the graph representation of the computation
# - params a dictionary of str to parameters.
# - net: the graph representation of the computation
# - params: a dictionary of str to parameters
#
# To compile the graph, we call the build function with the graph
# configuration and parameters.
# When parameters are provided, NNVM will pre-compute certain part of the graph if possible,
# the new parameter set returned as the third return value.
# When parameters are provided, NNVM will pre-compute certain part of the graph if possible (e.g. simplify batch normalization to scale shift),
# and return the updated parameters.

graph, lib, params = nnvm.compiler.build(
net, target, shape={"data": data_shape}, params=params)
Expand All @@ -65,7 +65,7 @@ def tvm_callback_cuda_compile(code):
# Run the Compiled Module
# -----------------------
#
# To deploy the module, we call :any:`tvm.contrib.graph_runtime.create` passing in the graph the lib and context.
# To deploy the module, we call :any:`tvm.contrib.graph_runtime.create` passing in the graph, the lib, and context.
# Thanks to TVM, we can deploy the compiled module to many platforms and languages.
# The deployment module is designed to contain minimum dependencies.
# This example runs on the same machine.
Expand All @@ -79,5 +79,5 @@ def tvm_callback_cuda_compile(code):
module.run()
# get output
out = module.get_output(0, tvm.nd.empty(out_shape))
# Convert to numpy
# convert to numpy
out.asnumpy()

0 comments on commit 02e1099

Please sign in to comment.