Skip to main content

struct

EngineTensorSpec

Describes the input and output tensor specifications of a Model.

Holds a description of the input/output tensor, given to or produced by MAX Engine. This is similar to TensorSpec in the Mojo standard library, but is specific to MAX Engine.

This is the data type returned from Model.get_model_input_metadata() and Model.get_model_output_metadata().

Implemented traits

AnyType, CollectionElement, Copyable, Movable, Stringable

Methods

__init__

__init__(inout self: Self, /, ptr: CTensorSpec, lib: DLHandle, owned session: InferenceSession)

Construct EngineTensorSpec. Do not use this function directly. Use functions from InferenceSession to create EngineTensorSpec.

Args:

  • ptr (CTensorSpec): C API pointer of TensorSpec.
  • lib (DLHandle): Handle to library.
  • session (InferenceSession): Copy of InferenceSession from which this instance was created.

__init__(inout self: Self, /, name: String, spec: TensorSpec, lib: DLHandle, owned session: InferenceSession)

Creates an instance of EngineTensorSpec. Do not use this function directly. Use functions from InferenceSession to create EngineTensorSpec.

Args:

  • name (String): Name of tensor.
  • spec (TensorSpec): Descritpion of Tensor in stdlib TensorSpec format.
  • lib (DLHandle): Handle to the library.
  • session (InferenceSession): Copy of InferenceSession from which this instance was created.

__init__(inout self: Self, /, name: String, shape: Optional[List[Optional[Int]]], dtype: DType, lib: DLHandle, owned session: InferenceSession)

Creates an instance of EngineTensorSpec. Do not use this function directly. Use functions from InferenceSession to create EngineTensorSpec. Note that this almost similar to another constructor. This accepts Int instead of Int64 shape types.

Args:

  • name (String): Name of tensor.
  • shape (Optional[List[Optional[Int]]]): Shape of the tensor.
  • dtype (DType): DataType of the tensor.
  • lib (DLHandle): Handle to the library.
  • session (InferenceSession): Copy of InferenceSession from which this instance was created.

__init__(inout self: Self, /, name: String, shape: Optional[List[Optional[SIMD[int64, 1]]]], dtype: DType, lib: DLHandle, owned session: InferenceSession)

Creates an instance of EngineTensorSpec. Do not use this function directly. Use functions from InferenceSession to create EngineTensorSpec. Note that this almost similar to another constructor. This accepts Int64 instead of Int shape types.

Args:

  • name (String): Name of tensor.
  • shape (Optional[List[Optional[SIMD[int64, 1]]]]): Shape of the tensor.
  • dtype (DType): DataType of the tensor.
  • lib (DLHandle): Handle to the library.
  • session (InferenceSession): Copy of InferenceSession from which this instance was created.

__copyinit__

__copyinit__(inout self: Self, /, other: Self)

Copy constructor for Tensor Spec.

Args:

  • other (Self): Instance of TensorSpec to be copied.

__moveinit__

__moveinit__(inout self: Self, /, owned existing: Self)

Move constructor for Tensor Spec.

Args:

  • existing (Self): Instance of TensorSpec to be moved.

__del__

__del__(owned self: Self)

Destructor for EngineTensorSpec.

__getitem__

__getitem__(self: Self, idx: Int) -> Optional[Int]

Get the dimension at the given index.

Args:

  • idx (Int): Index to get the dimension.

Returns:

Dimension as integer if dimension is static, else None.

Raises:

Raise error if spec has no static rank.

rank

rank(self: Self) -> Optional[Int]

Gets the rank of spec.

Returns:

Rank if rank is static, else None.

has_rank

has_rank(self: Self) -> Bool

Check if the spec has static rank.

Returns:

True if spec has static rank, else False.

get_as_tensor_spec

get_as_tensor_spec(self: Self) -> TensorSpec

Get the Mojo TensorSpec equivalent of Engine TensorSpec.

Raises Raise error if spec has dynamic rank.

Returns:

Spec in Mojo TensorSpec format.

get_name

get_name(self: Self) -> String

Gets the name of tensor corresponding to spec.

Returns:

Name of the Tensor as String.

get_dtype

get_dtype(self: Self) -> DType

Gets the DType of tensor corresponding to spec.

Returns:

DType of the Tensor.

get_shape

get_shape(self: Self) -> Optional[List[Optional[Int]]]

Gets the shape of tensor corresponding to spec.

Returns:

Shape of the Tensor. Returns None if rank is dynamic.

__str__

__str__(self: Self) -> String

Gets the String representation of Spec.

Returns:

Spec as string. This will be of format {name=<spec name>, spec=[None|shape]xdtype}.