Skip to main content

Python module

functional

Provides experimental functional APIs for tensor operations.

WARNING

This module contains experimental APIs that are subject to change or removal in future versions. Use with caution in production environments.

This module provides functional-style tensor operations that work seamlessly with both MAX Graph construction and eager Tensor execution. All operations are wrapped versions of the core graph operations that automatically handle different execution contexts. These operations can be used in both graph construction and eager execution.

abs()

max.experimental.functional.abs(x)

Computes the absolute value element-wise. See max.graph.ops.abs() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

add()

max.experimental.functional.add(lhs, rhs)

Adds two tensors element-wise. See max.graph.ops.add() for details.

Parameters:

Return type:

TensorValue

argmax()

max.experimental.functional.argmax(x, axis=-1)

Returns the indices of the maximum values along an axis. See max.graph.ops.argmax() for details.

Parameters:

Return type:

TensorValue

argmin()

max.experimental.functional.argmin(x, axis=-1)

Returns the indices of the minimum values along an axis. See max.graph.ops.argmin() for details.

Parameters:

Return type:

TensorValue

argsort()

max.experimental.functional.argsort(x, ascending=True)

Returns the indices that would sort a tensor along an axis. See max.graph.ops.argsort() for details.

Parameters:

Return type:

TensorValue

as_interleaved_complex()

max.experimental.functional.as_interleaved_complex(x)

Converts a tensor to interleaved complex representation. See max.graph.ops.as_interleaved_complex() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

atanh()

max.experimental.functional.atanh(x)

Computes the inverse hyperbolic tangent element-wise. See max.graph.ops.atanh() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

avg_pool2d()

max.experimental.functional.avg_pool2d(input, kernel_size, stride=1, dilation=1, padding=0, ceil_mode=False, count_boundary=True)

Applies 2D average pooling. See max.graph.ops.avg_pool2d() for details.

Parameters:

Return type:

TensorValue

band_part()

max.experimental.functional.band_part(x, num_lower=None, num_upper=None, exclude=False)

Copies a tensor setting everything outside a central band to zero. See max.graph.ops.band_part() for details.

Parameters:

Return type:

TensorValue

broadcast_to()

max.experimental.functional.broadcast_to(x, shape, out_dims=None)

Broadcasts a tensor to a new shape. See max.graph.ops.broadcast_to() for details.

Parameters:

Return type:

TensorValue

cast()

max.experimental.functional.cast(x, dtype)

Casts a tensor to a different data type. See max.graph.ops.cast() for details.

Parameters:

Return type:

TensorValue

chunk()

max.experimental.functional.chunk(x, chunks, axis=0)

Splits a tensor into chunks along a dimension. See max.graph.ops.chunk() for details.

Parameters:

Return type:

list[TensorValue]

constant()

max.experimental.functional.constant(value, dtype, device)

Creates a constant tensor. See max.graph.ops.constant() for details.

Parameters:

Return type:

TensorValue

constant_external()

max.experimental.functional.constant_external(name, type)

Creates a constant tensor from external data. See max.graph.ops.constant_external() for details.

Parameters:

Return type:

TensorValue

conv2d()

max.experimental.functional.conv2d(x, filter, stride=(1, 1), dilation=(1, 1), padding=(0, 0, 0, 0), groups=1, bias=None, input_layout=ConvInputLayout.NHWC, filter_layout=FilterLayout.RSCF)

Applies 2D convolution. See max.graph.ops.conv2d() for details.

Parameters:

Return type:

TensorValue

conv2d_transpose()

max.experimental.functional.conv2d_transpose(x, filter, stride=(1, 1), dilation=(1, 1), padding=(0, 0, 0, 0), output_paddings=(0, 0), bias=None, input_layout=ConvInputLayout.NHWC, filter_layout=FilterLayout.RSCF)

Applies 2D transposed convolution. See max.graph.ops.conv2d_transpose() for details.

Parameters:

Return type:

TensorValue

conv3d()

max.experimental.functional.conv3d(x, filter, stride=(1, 1, 1), dilation=(1, 1, 1), padding=(0, 0, 0, 0, 0, 0), groups=1, bias=None, input_layout=ConvInputLayout.NHWC, filter_layout=FilterLayout.QRSCF)

Applies 3D convolution. See max.graph.ops.conv3d() for details.

Parameters:

Return type:

TensorValue

cos()

max.experimental.functional.cos(x)

Computes the cosine element-wise. See max.graph.ops.cos() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

cumsum()

max.experimental.functional.cumsum(x, axis=-1, exclusive=False, reverse=False)

Computes the cumulative sum along an axis. See max.graph.ops.cumsum() for details.

Parameters:

Return type:

TensorValue

custom()

max.experimental.functional.custom(name, device, values, out_types, parameters=None)

Applies a custom operation. See max.graph.ops.custom() for details.

Parameters:

Return type:

list[Value[Any]]

div()

max.experimental.functional.div(lhs, rhs)

Divides two tensors element-wise. See max.graph.ops.div() for details.

Parameters:

Return type:

TensorValue

equal()

max.experimental.functional.equal(lhs, rhs)

Computes element-wise equality comparison. See max.graph.ops.equal() for details.

Parameters:

Return type:

TensorValue

erf()

max.experimental.functional.erf(x)

Computes the error function element-wise. See max.graph.ops.erf() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

exp()

max.experimental.functional.exp(x)

Computes the exponential element-wise. See max.graph.ops.exp() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

flatten()

max.experimental.functional.flatten(x, start_dim=0, end_dim=-1)

Flattens a tensor. See max.graph.ops.flatten() for details.

Parameters:

Return type:

TensorValue

floor()

max.experimental.functional.floor(x)

Computes the floor element-wise. See max.graph.ops.floor() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

fold()

max.experimental.functional.fold(input, output_size, kernel_size, stride=1, dilation=1, padding=0)

Performs tensor folding operation. See max.graph.ops.fold() for details.

Parameters:

Return type:

TensorValue

functional()

max.experimental.functional.functional(op)

Decorator that converts a graph operation to support multiple tensor types.

Parameters:

op (Callable[[~Args], Result])

Return type:

Callable[[~Args], Result]

gather()

max.experimental.functional.gather(input, indices, axis=-1)

Gathers values along an axis specified by indices. See max.graph.ops.gather() for details.

Parameters:

Return type:

TensorValue

gather_nd()

max.experimental.functional.gather_nd(input, indices, batch_dims=0)

Gathers values using multi-dimensional indices. See max.graph.ops.gather_nd() for details.

Parameters:

Return type:

TensorValue

gelu()

max.experimental.functional.gelu(x, approximate='none')

Applies the Gaussian Error Linear Unit (GELU) activation. See max.graph.ops.gelu() for details.

Parameters:

greater()

max.experimental.functional.greater(lhs, rhs)

Computes element-wise greater-than comparison. See max.graph.ops.greater() for details.

Parameters:

Return type:

TensorValue

greater_equal()

max.experimental.functional.greater_equal(lhs, rhs)

Computes element-wise greater-than-or-equal comparison. See max.graph.ops.greater_equal() for details.

Parameters:

Return type:

TensorValue

hann_window()

max.experimental.functional.hann_window(window_length, device, periodic=True, dtype=float32)

Creates a Hann window. See max.graph.ops.hann_window() for details.

Parameters:

Return type:

TensorValue

irfft()

max.experimental.functional.irfft(input_tensor, n=None, axis=-1, normalization=Normalization.BACKWARD, input_is_complex=False, buffer_size_mb=512)

Computes the inverse real FFT. See max.graph.ops.irfft() for details.

Parameters:

  • input_tensor (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue)
  • n (int | None)
  • axis (int)
  • normalization (Normalization | str)
  • input_is_complex (bool)
  • buffer_size_mb (int)

is_inf()

max.experimental.functional.is_inf(x)

Checks for infinite values element-wise. See max.graph.ops.is_inf() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

is_nan()

max.experimental.functional.is_nan(x)

Checks for NaN values element-wise. See max.graph.ops.is_nan() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

layer_norm()

max.experimental.functional.layer_norm(input, gamma, beta, epsilon)

Applies layer normalization. See max.graph.ops.layer_norm() for details.

Parameters:

Return type:

TensorValue

log()

max.experimental.functional.log(x)

Computes the natural logarithm element-wise. See max.graph.ops.log() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

log1p()

max.experimental.functional.log1p(x)

Computes log(1 + x) element-wise. See max.graph.ops.log1p() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

logical_and()

max.experimental.functional.logical_and(lhs, rhs)

Computes element-wise logical AND. See max.graph.ops.logical_and() for details.

Parameters:

Return type:

TensorValue

logical_not()

max.experimental.functional.logical_not(x)

Computes element-wise logical NOT. See max.graph.ops.logical_not() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

logical_or()

max.experimental.functional.logical_or(lhs, rhs)

Computes element-wise logical OR. See max.graph.ops.logical_or() for details.

Parameters:

Return type:

TensorValue

logical_xor()

max.experimental.functional.logical_xor(lhs, rhs)

Computes element-wise logical XOR. See max.graph.ops.logical_xor() for details.

Parameters:

Return type:

TensorValue

logsoftmax()

max.experimental.functional.logsoftmax(x)

Applies the log softmax function. See max.graph.ops.logsoftmax() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

masked_scatter()

max.experimental.functional.masked_scatter(input, mask, updates, out_dim)

Scatters values according to a mask. See max.graph.ops.masked_scatter() for details.

Parameters:

Return type:

TensorValue

matmul()

max.experimental.functional.matmul(lhs, rhs)

Performs matrix multiplication. See max.graph.ops.matmul() for details.

Parameters:

Return type:

TensorValue

max()

max.experimental.functional.max(x, y=None, /, axis=None)

Returns the maximum values along an axis. See max.graph.ops.max() for details.

Parameters:

Return type:

TensorValue

max_pool2d()

max.experimental.functional.max_pool2d(input, kernel_size, stride=1, dilation=1, padding=0, ceil_mode=False)

Applies 2D max pooling. See max.graph.ops.max_pool2d() for details.

Parameters:

Return type:

TensorValue

mean()

max.experimental.functional.mean(x, axis=-1)

Computes the mean along specified axes. See max.graph.ops.mean() for details.

Parameters:

Return type:

TensorValue

min()

max.experimental.functional.min(x, y=None, /, axis=None)

Returns the minimum values along an axis. See max.graph.ops.min() for details.

Parameters:

Return type:

TensorValue

mod()

max.experimental.functional.mod(lhs, rhs)

Computes the modulo operation element-wise. See max.graph.ops.mod() for details.

Parameters:

Return type:

TensorValue

mul()

max.experimental.functional.mul(lhs, rhs)

Multiplies two tensors element-wise. See max.graph.ops.mul() for details.

Parameters:

Return type:

TensorValue

negate()

max.experimental.functional.negate(x)

Negates a tensor element-wise. See max.graph.ops.negate() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

nonzero()

max.experimental.functional.nonzero(x, out_dim)

Returns the indices of non-zero elements. See max.graph.ops.nonzero() for details.

Parameters:

Return type:

TensorValue

not_equal()

max.experimental.functional.not_equal(lhs, rhs)

Computes element-wise inequality comparison. See max.graph.ops.not_equal() for details.

Parameters:

Return type:

TensorValue

outer()

max.experimental.functional.outer(lhs, rhs)

Computes the outer product of two vectors. See max.graph.ops.outer() for details.

Parameters:

Return type:

TensorValue

pad()

max.experimental.functional.pad(input, paddings, mode='constant', value=0)

Pads a tensor. See max.graph.ops.pad() for details.

Parameters:

Return type:

TensorValue

permute()

max.experimental.functional.permute(x, dims)

Permutes the dimensions of a tensor. See max.graph.ops.permute() for details.

Parameters:

Return type:

TensorValue

pow()

max.experimental.functional.pow(lhs, rhs)

Raises tensor elements to a power. See max.graph.ops.pow() for details.

Parameters:

Return type:

TensorValue

range()

max.experimental.functional.range(start, stop, step=1, out_dim=None, *, dtype, device)

Creates a tensor with evenly spaced values. See max.graph.ops.range() for details.

Parameters:

Return type:

TensorValue

relu()

max.experimental.functional.relu(x)

Applies the ReLU activation function. See max.graph.ops.relu() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

repeat_interleave()

max.experimental.functional.repeat_interleave(x, repeats, axis=None, out_dim=None)

Repeats elements of a tensor. See max.graph.ops.repeat_interleave() for details.

Parameters:

Return type:

TensorValue

reshape()

max.experimental.functional.reshape(x, shape)

Reshapes a tensor to a new shape. See max.graph.ops.reshape() for details.

Parameters:

Return type:

TensorValue

round()

max.experimental.functional.round(x)

Rounds tensor values element-wise. See max.graph.ops.round() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

rsqrt()

max.experimental.functional.rsqrt(x)

Computes the reciprocal square root element-wise. See max.graph.ops.rsqrt() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

scatter()

max.experimental.functional.scatter(input, updates, indices, axis=-1)

Scatters values along an axis. See max.graph.ops.scatter() for details.

Parameters:

Return type:

TensorValue

scatter_nd()

max.experimental.functional.scatter_nd(input, updates, indices)

Scatters values using multi-dimensional indices. See max.graph.ops.scatter_nd() for details.

Parameters:

Return type:

TensorValue

sigmoid()

max.experimental.functional.sigmoid(x)

Applies the sigmoid activation function. See max.graph.ops.sigmoid() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

silu()

max.experimental.functional.silu(x)

Applies the SiLU (Swish) activation function. See max.graph.ops.silu() for details.

Parameters:

x (TensorValue)

sin()

max.experimental.functional.sin(x)

Computes the sine element-wise. See max.graph.ops.sin() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

slice_tensor()

max.experimental.functional.slice_tensor(x, indices)

Slices a tensor along specified dimensions. See max.graph.ops.slice_tensor() for details.

Parameters:

Return type:

TensorValue

softmax()

max.experimental.functional.softmax(x)

Applies the softmax function. See max.graph.ops.softmax() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

split()

max.experimental.functional.split(x, split_sizes, axis=0)

Splits a tensor into multiple tensors. See max.graph.ops.split() for details.

Parameters:

Return type:

list[TensorValue]

sqrt()

max.experimental.functional.sqrt(x)

Computes the square root element-wise. See max.graph.ops.sqrt() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

squeeze()

max.experimental.functional.squeeze(x, axis)

Removes dimensions of size 1. See max.graph.ops.squeeze() for details.

Parameters:

Return type:

TensorValue

stack()

max.experimental.functional.stack(values, axis=0)

Stacks tensors along a new dimension. See max.graph.ops.stack() for details.

Parameters:

Return type:

TensorValue

sub()

max.experimental.functional.sub(lhs, rhs)

Subtracts two tensors element-wise. See max.graph.ops.sub() for details.

Parameters:

Return type:

TensorValue

sum()

max.experimental.functional.sum(x, axis=-1)

Computes the sum along specified axes. See max.graph.ops.sum() for details.

Parameters:

Return type:

TensorValue

tanh()

max.experimental.functional.tanh(x)

Computes the hyperbolic tangent element-wise. See max.graph.ops.tanh() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

tile()

max.experimental.functional.tile(x, repeats)

Tiles a tensor by repeating it. See max.graph.ops.tile() for details.

Parameters:

Return type:

TensorValue

top_k()

max.experimental.functional.top_k(input, k, axis=-1)

Returns the k largest elements along an axis. See max.graph.ops.top_k() for details.

Parameters:

Return type:

tuple[TensorValue, TensorValue]

transfer_to()

max.experimental.functional.transfer_to(x, device)

Transfers a tensor to a specified device. See max.graph.ops.transfer_to() for details.

Parameters:

Return type:

TensorValue

transpose()

max.experimental.functional.transpose(x, axis_1, axis_2)

Transposes a tensor. See max.graph.ops.transpose() for details.

Parameters:

Return type:

TensorValue

trunc()

max.experimental.functional.trunc(x)

Truncates tensor values element-wise. See max.graph.ops.trunc() for details.

Parameters:

x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])

Return type:

TensorValue

unsqueeze()

max.experimental.functional.unsqueeze(x, axis)

Adds dimensions of size 1. See max.graph.ops.unsqueeze() for details.

Parameters:

Return type:

TensorValue

where()

max.experimental.functional.where(condition, x, y)

Selects elements from two tensors based on a condition. See max.graph.ops.where() for details.

Parameters:

Return type:

TensorValue