Skip to main content

Python class

Dim

Dim

class max.graph.Dim(value)

source

Bases: object

A tensor dimension.

Dims describe the shape of tensors in a Graph. In most cases, you don’t need to construct a Dim directly. Instead, you pass dimension values directly to TensorType or BufferType constructors:

from max.graph import Dim, TensorType, DeviceRef

tensor_type = TensorType(DType.int64, ("batch", 10), device=DeviceRef.CPU())

A tensor dimension can be one of three types:

  • Static: A known size. See StaticDim.
  • Symbolic: An unknown size identified by name. See SymbolicDim.
  • Algebraic: An expression derived from symbolic dimensions. See AlgebraicDim.

Static dimensions let the graph compiler resolve shapes at compile time. This enables more aggressive optimizations than symbolic or algebraic dimensions allow. That said, when tensors share a named symbolic dimension, the compiler can leverage the implied shape equality to optimize some operations.

Converts valid input values to Dim.

Parameters:

value (DimLike)

from_mlir()

static from_mlir(attr)

source

Constructs a dimension from an mlir.Attribute.

Parameters:

attr (TypedAttr) – The MLIR Attribute to parse into a dimension.

Returns:

The dimension represented by the MLIR Attr value.

Return type:

Dim

parameters

property parameters: Iterable[SymbolicDim]

source

Lists the symbolic dimension names on which this dim depends.

to_mlir()

to_mlir()

source

Creates an mlir.Attribute representing this dimension.

This is used internally when constructing tensor MLIR types.

Returns:

An mlir.Attribute in the context representing the dimension.

Return type:

TypedAttr