Skip to main content

Python module

dtype

Provides data type definitions for tensors in MAX Engine. These data types are essential for defining the precision and memory layout of tensor data when working with machine learning models.

This module defines the DType enum, which represents all supported tensor data types in MAX Engine, including:

  • Integer types (signed and unsigned): int8 | uint8 | int16 | uint16 | int32 | uint32 | int64 | uint64
  • Floating-point types (float8 variants): float16 | bfloat16 | float32 | float64
  • Boolean type: bool

The module also provides utilities for converting between MAX Engine data types and NumPy dtypes, making it easy to interoperate with the NumPy ecosystem.

import numpy as np
from max.dtype import DType

tensor = np.zeros((2, 3), dtype=DType.float32.to_numpy())

# Convert NumPy dtype to MAX DType
array = np.ones((4, 4), dtype=np.float16)
max_dtype = DType.from_numpy(array.dtype)

# Check properties of data types
is_float = DType.float32.is_float()  # True
is_int = DType.int64.is_integral()   # True
size = DType.float64.size_in_bytes   # 8

DType​

class max.dtype.DType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

The tensor data type.

align​

property align

Returns the alignment requirement of the data type in bytes.

The alignment specifies the memory boundary that values of this data type must be aligned to for optimal performance and correctness.

bfloat16​

bfloat16 = 80

bool​

bool = 1

float16​

float16 = 79

float32​

float32 = 81

float4_e2m1fn​

float4_e2m1fn = 64

float64​

float64 = 82

float8_e4m3fn​

float8_e4m3fn = 75

float8_e4m3fnuz​

float8_e4m3fnuz = 76

float8_e5m2​

float8_e5m2 = 77

float8_e5m2fnuz​

float8_e5m2fnuz = 78

float8_e8m0fnu​

float8_e8m0fnu = 73

from_numpy()​

from_numpy()

Converts a NumPy dtype to the corresponding DType.

Parameters:

dtype (np.dtype) – The NumPy dtype to convert.

Returns:

The corresponding DType enum value.

Return type:

DType

Raises:

ValueError – If the input dtype is not supported.

from_torch()​

from_torch(_error=None)

Parameters:

Return type:

DType

int16​

int16 = 137

int32​

int32 = 139

int64​

int64 = 141

int8​

int8 = 135

is_float()​

is_float(self) → bool

Checks if the data type is a floating-point type.

is_float8()​

is_float8(self) → bool

Checks if the data type is an 8-bit floating-point type.

is_half()​

is_half(self) → bool

Checks if the data type is a half-precision floating-point type.

is_integral()​

is_integral(self) → bool

Checks if the data type is an integer type.

is_signed_integral()​

is_signed_integral(self) → bool

Checks if the data type is a signed integer type.

is_unsigned_integral()​

is_unsigned_integral(self) → bool

Checks if the data type is an unsigned integer type.

size_in_bits​

property size_in_bits

Returns the size of the data type in bits.

This indicates how many bits are required to store a single value of this data type in memory.

size_in_bytes​

property size_in_bytes

Returns the size of the data type in bytes.

This indicates how many bytes are required to store a single value of this data type in memory.

to_numpy()​

to_numpy()

Converts this DType to the corresponding NumPy dtype.

Returns:

The corresponding NumPy dtype object.

Return type:

DType

Raises:

ValueError – If the dtype is not supported.

Parameters:

self (DType)

to_torch()​

to_torch(_error=None)

Parameters:

Return type:

dtype

uint16​

uint16 = 136

uint32​

uint32 = 138

uint64​

uint64 = 140

uint8​

uint8 = 134

finfo​

class max.dtype.finfo(dtype)

Numerical properties of a floating point max.dtype.DType.

This is modeled after torch.finfo, providing bits, eps, max, min, tiny, smallest_normal, and dtype attributes for every MAX float dtype—including bfloat16, float8, and float4 types that numpy cannot represent.

Parameters:

dtype (DType) – A floating-point DType to query.

Raises:

TypeError – If dtype is not a floating-point type.

bits​

bits: int

dtype​

dtype: DType

eps​

eps: float

max​

max: float

min​

min: float

smallest_normal​

property smallest_normal: float

Alias for tiny (torch.finfo compatibility).

tiny​

tiny: float

Was this page helpful?