tvm.relay.ty

The type nodes of the Relay language.

class tvm.relay.ty.FuncType(arg_types, ret_type, type_params=None, type_constraints=None)

A function type in Relay, see tvm/relay/type.h for more details.

This is the type assigned to functions in Relay. They consist of a list of type parameters which enable the definition of generic functions, a set of type constraints which we omit for the time being, a sequence of argument types, and a return type.

We informally write them as: forall (type_params), (arg_types) -> ret_type where type_constraints

Parameters:
  • arg_types (List[tvm.relay.Type]) – The argument types
  • ret_type (tvm.relay.Type) – The return type.
  • type_params (Optional[List[tvm.relay.TypeVar]]) – The type parameters
  • type_constraints (Optional[List[tvm.relay.TypeConstraint]]) – The type constraints.
class tvm.relay.ty.GlobalTypeVar(var, kind=<Kind.AdtHandle: 5>)

A global type variable in Relay. GlobalTypeVar is used to refer to the global type-level definitions stored in the environment.

class tvm.relay.ty.IncompleteType(kind=<Kind.Type: 0>)

An incomplete type.

class tvm.relay.ty.Kind

The kind of a type parameter, represents a variable shape, base type, type, or dimension.

This controls what a type parameter is allowed to be instantiated with. For example one’s of kind BaseType can only be float32, int32, and so on.

class tvm.relay.ty.RefType(value)

Reference Type in relay.

Parameters:value (Type) – The value type.
class tvm.relay.ty.TensorType(shape, dtype='float32')

A concrete TensorType in Relay.

This is the type assigned to tensor’s with a known dype and shape. For example a tensor of float32 and (5, 5).

Parameters:
  • shape (List[tvm.Expr]) – The shape of the Tensor
  • dtype (Optional[str]) – The content data type. Default to “float32”.
Returns:

tensor_type – The tensor type.

Return type:

tvm.relay.TensorType

concrete_shape

Get shape of the type as concrete tuple of int.

Returns:shape – The concrete shape of the Type.
Return type:List[int]
Raises:TypeError : If the shape is symbolic
class tvm.relay.ty.TupleType(fields)

A tuple type in Relay, see tvm/relay/type.h for more details.

Lists the type of each field in the tuple.

class tvm.relay.ty.Type

The base type for all Relay types.

same_as(other)

Compares two Relay types by referential equality.

class tvm.relay.ty.TypeCall(func, args)

Type-level function application in Relay. A type call applies argument types to a constructor (type-level function).

class tvm.relay.ty.TypeConstraint

Abstract class representing a type constraint.

class tvm.relay.ty.TypeRelation(func, args, num_inputs, attrs)

Type relation in relay.

Parameters:
  • func (EnvFunc) – User defined relation function.
  • args ([tvm.relay.Type]) – List of types to the func.
  • num_inputs (int) – Number of input arguments in args, this act as a hint for type inference.
  • attrs (Attrs) – The attribute attached to the relation information
Returns:

type_relation – The type relation.

Return type:

tvm.relay.TypeRelation

class tvm.relay.ty.TypeVar(var, kind=<Kind.Type: 0>)

A type variable used for generic types in Relay, see tvm/relay/type.h for more details.

A type variable represents a type placeholder which will be filled in later on. This allows the user to write functions which are generic over types.

tvm.relay.ty.scalar_type(dtype)

Creates a scalar type.

This function returns TensorType((), dtype)

Parameters:dtype (str) – The content data type.
Returns:s_type – The result type.
Return type:tvm.relay.TensorType
class tvm.relay.ty.Type

The base type for all Relay types.

same_as(other)

Compares two Relay types by referential equality.

class tvm.relay.ty.TensorType(shape, dtype='float32')

A concrete TensorType in Relay.

This is the type assigned to tensor’s with a known dype and shape. For example a tensor of float32 and (5, 5).

Parameters:
  • shape (List[tvm.Expr]) – The shape of the Tensor
  • dtype (Optional[str]) – The content data type. Default to “float32”.
Returns:

tensor_type – The tensor type.

Return type:

tvm.relay.TensorType

concrete_shape

Get shape of the type as concrete tuple of int.

Returns:shape – The concrete shape of the Type.
Return type:List[int]
Raises:TypeError : If the shape is symbolic
class tvm.relay.ty.Kind

The kind of a type parameter, represents a variable shape, base type, type, or dimension.

This controls what a type parameter is allowed to be instantiated with. For example one’s of kind BaseType can only be float32, int32, and so on.

class tvm.relay.ty.TypeVar(var, kind=<Kind.Type: 0>)

A type variable used for generic types in Relay, see tvm/relay/type.h for more details.

A type variable represents a type placeholder which will be filled in later on. This allows the user to write functions which are generic over types.

class tvm.relay.ty.TypeConstraint

Abstract class representing a type constraint.

class tvm.relay.ty.TupleType(fields)

A tuple type in Relay, see tvm/relay/type.h for more details.

Lists the type of each field in the tuple.

class tvm.relay.ty.FuncType(arg_types, ret_type, type_params=None, type_constraints=None)

A function type in Relay, see tvm/relay/type.h for more details.

This is the type assigned to functions in Relay. They consist of a list of type parameters which enable the definition of generic functions, a set of type constraints which we omit for the time being, a sequence of argument types, and a return type.

We informally write them as: forall (type_params), (arg_types) -> ret_type where type_constraints

Parameters:
  • arg_types (List[tvm.relay.Type]) – The argument types
  • ret_type (tvm.relay.Type) – The return type.
  • type_params (Optional[List[tvm.relay.TypeVar]]) – The type parameters
  • type_constraints (Optional[List[tvm.relay.TypeConstraint]]) – The type constraints.
class tvm.relay.ty.IncompleteType(kind=<Kind.Type: 0>)

An incomplete type.

class tvm.relay.ty.TypeRelation(func, args, num_inputs, attrs)

Type relation in relay.

Parameters:
  • func (EnvFunc) – User defined relation function.
  • args ([tvm.relay.Type]) – List of types to the func.
  • num_inputs (int) – Number of input arguments in args, this act as a hint for type inference.
  • attrs (Attrs) – The attribute attached to the relation information
Returns:

type_relation – The type relation.

Return type:

tvm.relay.TypeRelation