Python class
TensorType
TensorType
class max.graph.TensorType(dtype, shape, device, _layout=None)
Bases: _TensorTypeBase[TensorType]
A symbolic tensor type.
Use TensorType to declare the expected dtype, shape, and target
device of tensor values that flow through a graph during model
execution. Unlike an eager tensor, a TensorType holds no data. It is a
purely symbolic description of a value’s type at a specific point in the
computation. The graph compiler uses this information for shape inference
and optimization during graph construction.
The following example shows how to create a tensor type and access its properties:
from max.graph import TensorType, DeviceRef
from max.dtype import DType
tensor_type = TensorType(DType.float32, (2, 3), device=DeviceRef.CPU())
print(tensor_type.dtype) # Outputs: DType.float32
print(tensor_type.shape) # Outputs: [2, 3]A shape’s dimensions can be static (integers), symbolic (strings), or algebraic (expressions over symbolic dimensions). In each case the rank is known at graph construction time.
Pass TensorType instances to load()
or Module.compile() (experimental) to define the input types of a
graph or model.
-
Parameters:
-
- dtype (DType) – The data type of the tensor elements.
- shape (Shape) – The shape of the tensor, expressed as a
Shape. - device (DeviceRef) – The device the tensor is located on. Use
DeviceRef.CPU()orDeviceRef.GPU()to create a device reference. - _layout (FilterLayout | None)
as_buffer()
as_buffer()
Returns the analogous buffer type.
-
Return type:
from_mlir()
classmethod from_mlir(type)
Constructs a tensor type from an MLIR type.
-
Parameters:
-
type (TensorType) – The MLIR Type to parse into a tensor type.
-
Returns:
-
The tensor type represented by the MLIR Type value.
-
Return type:
to_mlir()
to_mlir()
Converts to an mlir.Type instance.
-
Returns:
-
An
mlir.Typein the specified context. -
Return type:
-
TensorType
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!