Skip to content

Relay References

The TVM codebase is large and can be very confusing to reference. Things are not always placed where'd you expect them to be. The two classes below aim to aid the developer or user in the navigation and referencing of TVM's codebase.


forge.relay.relay.Relay

Bases: Enum

An enumeration of Relay objects.

Provides a flattened reference of Relay objects. This allows one to more easily navigate TVM's codebase of objects without in-depth knowledge of TVM's codebase structure.

Examples: .. code-block:: python

Relay.Var.help()            # Print the docstring of the TVM Var object
Relay.Var.str               # Get the string of the TVM object - 'Var'
Relay.Var.obj               # Reference to the TVM Var object
Relay.Var(*args, **kwargs)  # Invoke the constructor

Methods:

Name Description
help

Print the docstrings of the enumerated TVM object

__call__

Invocation of the enumerated TVM object's constructor

Attributes:

Name Type Description
str str

String of the enumerated TVM object

obj Any

Reference to the enumerated TVM object

Function
Call
Var
Constant
Tuple
TupleGetItem
GlobalVar
Op
Attrs
NDArray
ADT
Node
Clause
Match
TypeData
Constructor
PatternConstructor
PatternVar
PatternWildcard
PatternTuple
Array
Map
Span
SourceName
Let
If
RefCreate
RefRead
RefWrite
TupleWrapper
TypeVar
IncompleteType
TensorType
FuncType
TupleType
TypeRelation
RefType
GlobalTypeVar
TypeCall
Any
IntImm
String

str property

str: str

String of the enumerated TVM object

obj property

obj: Any

Reference to the enumerated TVM object

help

help() -> None

Print the docstrings of the enumerated TVM object

__call__

__call__(*args, **kwargs) -> Any

Invocation of the enumerated TVM object's constructor

Use the member help() method to get details on correct usage.

Parameters:

Name Type Description Default
*args *Any

Positional arguments for the constructor

()
**kwargs **Any

Keyword arguments for the constructor

{}

Returns:

Type Description
Any

TVM object

Examples: .. code-block:: python

var = Relay.Var("data", shape=(100,), dtype="float32")
mod = Relay.IRModule(var)

Function class-attribute instance-attribute

Function = Function

Call class-attribute instance-attribute

Call = Call

Var class-attribute instance-attribute

Var = Var

Constant class-attribute instance-attribute

Constant = Constant

Tuple class-attribute instance-attribute

Tuple = Tuple

TupleGetItem class-attribute instance-attribute

TupleGetItem = TupleGetItem

GlobalVar class-attribute instance-attribute

GlobalVar = GlobalVar

Op class-attribute instance-attribute

Op = Op

Attrs class-attribute instance-attribute

Attrs = Attrs

NDArray class-attribute instance-attribute

NDArray = NDArray

ADT class-attribute instance-attribute

ADT = ADT

Node class-attribute instance-attribute

Node = Node

Clause class-attribute instance-attribute

Clause = Clause

Match class-attribute instance-attribute

Match = Match

TypeData class-attribute instance-attribute

TypeData = TypeData

Constructor class-attribute instance-attribute

Constructor = Constructor

PatternConstructor class-attribute instance-attribute

PatternConstructor = PatternConstructor

PatternVar class-attribute instance-attribute

PatternVar = PatternVar

PatternWildcard class-attribute instance-attribute

PatternWildcard = PatternWildcard

PatternTuple class-attribute instance-attribute

PatternTuple = PatternTuple

Array class-attribute instance-attribute

Array = Array

Map class-attribute instance-attribute

Map = Map

Span class-attribute instance-attribute

Span = Span

SourceName class-attribute instance-attribute

SourceName = SourceName

Let class-attribute instance-attribute

Let = Let

If class-attribute instance-attribute

If = If

RefCreate class-attribute instance-attribute

RefCreate = RefCreate

RefRead class-attribute instance-attribute

RefRead = RefRead

RefWrite class-attribute instance-attribute

RefWrite = RefWrite

TupleWrapper class-attribute instance-attribute

TupleWrapper = TupleWrapper

TypeVar class-attribute instance-attribute

TypeVar = TypeVar

IncompleteType class-attribute instance-attribute

IncompleteType = IncompleteType

TensorType class-attribute instance-attribute

TensorType = TensorType

FuncType class-attribute instance-attribute

FuncType = FuncType

TupleType class-attribute instance-attribute

TupleType = TupleType

TypeRelation class-attribute instance-attribute

TypeRelation = TypeRelation

RefType class-attribute instance-attribute

RefType = RefType

GlobalTypeVar class-attribute instance-attribute

GlobalTypeVar = GlobalTypeVar

TypeCall class-attribute instance-attribute

TypeCall = TypeCall

Any class-attribute instance-attribute

Any = Any

IntImm class-attribute instance-attribute

IntImm = IntImm

String class-attribute instance-attribute

String = String

forge.relay.relay.RelayOp

RelayOp(op_name: str)

Provide a quick reference to TVM's python API of Relay Operators via the identifying op-name string. This is a very useful since all the operators are encoded as strings in Forge. Additionally, there is a minor quirk the the structure of the TVM operator codebase such that QNN operators are not placed in the codebase in a path that matches its string-form, e.g. 'qnn.conv2d' sits at tvm.relay.qnn.op.conv2d. This class resolves this quirk.

Lookup and reference the TVM operator function by operator's name string

Provided a valid operator name string, the returned instance is ready to be called as if it were the referenced TVM operator function. When a TVM operator function is called correctly, a Relay expression is formed.

Examples: .. code-block:: python

RelayOp("nn.conv2d")                   # Get the `tvm.relay.nn.conv2d` function
RelayOp("nn.conv2d")(*args, **kwargs)  # Invoke operator and get a 'conv2d' expression
RelayOp("nn.conv2d").help()            # Print the TVM operator function docstring
RelayOp.list_op_names()                # Get a list of all op-name strings

Methods:

Name Description
__call__

Invoke the referenced TVM operator function

help

Print the docstrings of the TVM operator function

list_op_names

Returns a sorted list of op-name strings

Functions

__call__

__call__(*args, **kwargs) -> obj

Invoke the referenced TVM operator function

Use the instance help() method to get details on correct usage.

Parameters:

Name Type Description Default
*args *Any

Positional arguments for the TVM operator function

()
**kwargs **Any

Keyword arguments for the TVM operator function

{}

Returns:

Type Description
obj

TVM Relay expression

help

help() -> None

Print the docstrings of the TVM operator function

list_op_names staticmethod

list_op_names() -> List[str]

Returns a sorted list of op-name strings

Note

This list contains more functions than there are actually 'valid' for invocation, i.e. not all function strings are invocable.

Returns:

Type Description
List[str]

Operator names