Construct the necessary state for the TVM graph runtime from a Relay expression., target=None, target_host=None, params=None)

Helper function that builds a Relay function to run on TVM graph runtime.

  • func (relay.Function) – The function to build.
  • target (str,, or dict of str(i.e. device/context) –
  • to str/, optional (name)) – For heterogeneous compilation, it is a dictionary indicating context to target mapping. For homogeneous compilation, it is a build target.
  • target_host (str or, optional) – Host compilation target, if target is device. When TVM compiles device specific program such as CUDA, we also need host(CPU) side code to interact with the driver setup the dimensions and parameters correctly. target_host is used to specify the host side codegen target. By default, llvm is used if it is enabled, otherwise a stackvm intepreter is used.
  • params (dict of str to NDArray) – Input parameters to the graph that do not change during inference time. Used for constant folding.

  • graph_json (str) – The json string that can be accepted by graph runtime.
  • mod (tvm.Module) – The module containing necessary libraries.
  • params (dict) – The parameters of the final graph.


Configure the build behavior by setting config variables.

  • opt_level (int, default=2) – Optimization level. See OPT_PASS_LEVEL for level of each pass.
  • add_pass (set of str) – Optimization pass to be added regardless of optimization level.
  • disable_pass (set of str) – Optimization pass to be disabled during optimization.
  • fallback_device (str or tvm.TVMContext) – The fallback device. It is also used as the default device for operators without specified device during heterogeneous execution.

config – The build configuration

Return type:


tvm.relay.build_module.create_executor(kind='debug', mod=None, ctx=None, target='llvm')

Factory function to create an executor.

  • kind (str) – The type of executor
  • mod (Module) – The Relay module containing collection of functions
  • ctx (tvm.TVMContext) – The context to execute the code.
  • target (tvm.Target) – The corresponding context
class tvm.relay.build_module.BuildConfig(**kwargs)

Configuration scope to set a build config option.

Parameters:kwargs – Keyword arguments of configurations to set.
class tvm.relay.build_module.GraphExecutor(mod, ctx, target)

Wrapper around Executor interface.

This executor is used for debug and testing purpoes.

  • mod (Module) – The module to support the execution.
  • ctx (TVMContext) – The runtime context to run the code on.
  • target (Target) – The target option to build the function.