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.
add()
max.experimental.functional.add(lhs, rhs)
Adds two tensors element-wise.
See max.graph.ops.add()
for details.
-
Parameters:
-
Return type:
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.
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.
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:
-
- x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue)
- ascending (bool)
-
Return type:
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.
atanh()
max.experimental.functional.atanh(x)
Computes the inverse hyperbolic tangent element-wise.
See max.graph.ops.atanh()
for details.
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:
-
- input (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- kernel_size (tuple[int | str | Dim | integer[Any], int | str | Dim | integer[Any]])
- stride (int | tuple[int, int])
- dilation (int | tuple[int, int])
- padding (int | tuple[int, int])
- ceil_mode (bool)
- count_boundary (bool)
-
Return type:
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.
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.
cast()
max.experimental.functional.cast(x, dtype)
Casts a tensor to a different data type.
See max.graph.ops.cast()
for details.
-
Parameters:
-
- x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue)
- dtype (DType)
-
Return type:
chunk()
max.experimental.functional.chunk(x, chunks, axis=0)
Splits a tensor into chunks along a dimension.
See max.graph.ops.chunk()
for details.
constant()
max.experimental.functional.constant(value, dtype, device)
Creates a constant tensor.
See max.graph.ops.constant()
for details.
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:
-
- name (str)
- type (TensorType)
-
Return type:
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:
-
- x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- filter (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- stride (tuple[int, int])
- dilation (tuple[int, int])
- padding (tuple[int, int, int, int])
- groups (int)
- bias (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]] | None)
- input_layout (ConvInputLayout)
- filter_layout (FilterLayout)
-
Return type:
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:
-
- x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- filter (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- stride (tuple[int, int])
- dilation (tuple[int, int])
- padding (tuple[int, int, int, int])
- output_paddings (tuple[int, int])
- bias (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]] | None)
- input_layout (ConvInputLayout)
- filter_layout (FilterLayout)
-
Return type:
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:
-
- x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- filter (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- stride (tuple[int, int, int])
- dilation (tuple[int, int, int])
- padding (tuple[int, int, int, int, int, int])
- groups (int)
- bias (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]] | None)
- input_layout (ConvInputLayout)
- filter_layout (FilterLayout)
-
Return type:
cos()
max.experimental.functional.cos(x)
Computes the cosine element-wise.
See max.graph.ops.cos()
for details.
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.
custom()
max.experimental.functional.custom(name, device, values, out_types, parameters=None)
Applies a custom operation.
See max.graph.ops.custom()
for details.
div()
max.experimental.functional.div(lhs, rhs)
Divides two tensors element-wise.
See max.graph.ops.div()
for details.
-
Parameters:
-
Return type:
equal()
max.experimental.functional.equal(lhs, rhs)
Computes element-wise equality comparison.
See max.graph.ops.equal()
for details.
-
Parameters:
-
Return type:
erf()
max.experimental.functional.erf(x)
Computes the error function element-wise.
See max.graph.ops.erf()
for details.
exp()
max.experimental.functional.exp(x)
Computes the exponential element-wise.
See max.graph.ops.exp()
for details.
flatten()
max.experimental.functional.flatten(x, start_dim=0, end_dim=-1)
Flattens a tensor.
See max.graph.ops.flatten()
for details.
floor()
max.experimental.functional.floor(x)
Computes the floor element-wise.
See max.graph.ops.floor()
for details.
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:
-
- input (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- output_size (tuple[int | str | Dim | integer[Any], int | str | Dim | integer[Any]])
- kernel_size (tuple[int | str | Dim | integer[Any], int | str | Dim | integer[Any]])
- stride (int | tuple[int, int])
- dilation (int | tuple[int, int])
- padding (int | tuple[int, int])
-
Return type:
functional()
max.experimental.functional.functional(op)
Decorator that converts a graph operation to support multiple tensor types.
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:
-
- input (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- indices (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- axis (int)
-
Return type:
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:
-
- input (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- indices (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- batch_dims (int)
-
Return type:
gelu()
max.experimental.functional.gelu(x, approximate='none')
Applies the Gaussian Error Linear Unit (GELU) activation.
See max.graph.ops.gelu()
for details.
-
Parameters:
-
- x (TensorValue)
- approximate (str)
greater()
max.experimental.functional.greater(lhs, rhs)
Computes element-wise greater-than comparison.
See max.graph.ops.greater()
for details.
-
Parameters:
-
Return type:
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:
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:
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.
is_inf()
max.experimental.functional.is_inf(x)
Checks for infinite values element-wise.
See max.graph.ops.is_inf()
for details.
is_nan()
max.experimental.functional.is_nan(x)
Checks for NaN values element-wise.
See max.graph.ops.is_nan()
for details.
layer_norm()
max.experimental.functional.layer_norm(input, gamma, beta, epsilon)
Applies layer normalization.
See max.graph.ops.layer_norm()
for details.
-
Parameters:
-
- input (TensorValue)
- gamma (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- beta (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- epsilon (float)
-
Return type:
log()
max.experimental.functional.log(x)
Computes the natural logarithm element-wise.
See max.graph.ops.log()
for details.
log1p()
max.experimental.functional.log1p(x)
Computes log(1 + x) element-wise.
See max.graph.ops.log1p()
for details.
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:
logical_not()
max.experimental.functional.logical_not(x)
Computes element-wise logical NOT.
See max.graph.ops.logical_not()
for details.
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:
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:
logsoftmax()
max.experimental.functional.logsoftmax(x)
Applies the log softmax function.
See max.graph.ops.logsoftmax()
for details.
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:
-
- input (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- mask (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- updates (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- out_dim (int | str | Dim | integer[Any])
-
Return type:
matmul()
max.experimental.functional.matmul(lhs, rhs)
Performs matrix multiplication.
See max.graph.ops.matmul()
for details.
-
Parameters:
-
Return type:
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:
-
- x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- y (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]] | None)
- axis (int | None)
-
Return type:
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:
-
- input (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- kernel_size (tuple[int | str | Dim | integer[Any], int | str | Dim | integer[Any]])
- stride (int | tuple[int, int])
- dilation (int | tuple[int, int])
- padding (int | tuple[int, int])
- ceil_mode (bool)
-
Return type:
mean()
max.experimental.functional.mean(x, axis=-1)
Computes the mean along specified axes.
See max.graph.ops.mean()
for details.
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:
-
- x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- y (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]] | None)
- axis (int | None)
-
Return type:
mod()
max.experimental.functional.mod(lhs, rhs)
Computes the modulo operation element-wise.
See max.graph.ops.mod()
for details.
-
Parameters:
-
Return type:
mul()
max.experimental.functional.mul(lhs, rhs)
Multiplies two tensors element-wise.
See max.graph.ops.mul()
for details.
-
Parameters:
-
Return type:
negate()
max.experimental.functional.negate(x)
Negates a tensor element-wise.
See max.graph.ops.negate()
for details.
nonzero()
max.experimental.functional.nonzero(x, out_dim)
Returns the indices of non-zero elements.
See max.graph.ops.nonzero()
for details.
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:
outer()
max.experimental.functional.outer(lhs, rhs)
Computes the outer product of two vectors.
See max.graph.ops.outer()
for details.
-
Parameters:
-
Return type:
pad()
max.experimental.functional.pad(input, paddings, mode='constant', value=0)
Pads a tensor.
See max.graph.ops.pad()
for details.
-
Parameters:
-
- input (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- paddings (Iterable[int])
- mode (Literal['constant'])
- value (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
-
Return type:
permute()
max.experimental.functional.permute(x, dims)
Permutes the dimensions of a tensor.
See max.graph.ops.permute()
for details.
pow()
max.experimental.functional.pow(lhs, rhs)
Raises tensor elements to a power.
See max.graph.ops.pow()
for details.
-
Parameters:
-
Return type:
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:
-
- start (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- stop (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- step (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- out_dim (int | str | Dim | integer[Any] | None)
- dtype (DType)
- device (Device | DeviceRef)
-
Return type:
relu()
max.experimental.functional.relu(x)
Applies the ReLU activation function.
See max.graph.ops.relu()
for details.
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.
reshape()
max.experimental.functional.reshape(x, shape)
Reshapes a tensor to a new shape.
See max.graph.ops.reshape()
for details.
round()
max.experimental.functional.round(x)
Rounds tensor values element-wise.
See max.graph.ops.round()
for details.
rsqrt()
max.experimental.functional.rsqrt(x)
Computes the reciprocal square root element-wise.
See max.graph.ops.rsqrt()
for details.
scatter()
max.experimental.functional.scatter(input, updates, indices, axis=-1)
Scatters values along an axis.
See max.graph.ops.scatter()
for details.
-
Parameters:
-
- input (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- updates (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- indices (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- axis (int)
-
Return type:
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:
-
- input (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- updates (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- indices (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
-
Return type:
sigmoid()
max.experimental.functional.sigmoid(x)
Applies the sigmoid activation function.
See max.graph.ops.sigmoid()
for details.
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.
slice_tensor()
max.experimental.functional.slice_tensor(x, indices)
Slices a tensor along specified dimensions.
See max.graph.ops.slice_tensor()
for details.
-
Parameters:
-
- x (TensorValue)
- indices (SliceIndices)
-
Return type:
softmax()
max.experimental.functional.softmax(x)
Applies the softmax function.
See max.graph.ops.softmax()
for details.
split()
max.experimental.functional.split(x, split_sizes, axis=0)
Splits a tensor into multiple tensors.
See max.graph.ops.split()
for details.
sqrt()
max.experimental.functional.sqrt(x)
Computes the square root element-wise.
See max.graph.ops.sqrt()
for details.
squeeze()
max.experimental.functional.squeeze(x, axis)
Removes dimensions of size 1.
See max.graph.ops.squeeze()
for details.
stack()
max.experimental.functional.stack(values, axis=0)
Stacks tensors along a new dimension.
See max.graph.ops.stack()
for details.
sub()
max.experimental.functional.sub(lhs, rhs)
Subtracts two tensors element-wise.
See max.graph.ops.sub()
for details.
-
Parameters:
-
Return type:
sum()
max.experimental.functional.sum(x, axis=-1)
Computes the sum along specified axes.
See max.graph.ops.sum()
for details.
tanh()
max.experimental.functional.tanh(x)
Computes the hyperbolic tangent element-wise.
See max.graph.ops.tanh()
for details.
tile()
max.experimental.functional.tile(x, repeats)
Tiles a tensor by repeating it.
See max.graph.ops.tile()
for details.
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.
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:
-
- x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue)
- device (Device | DeviceRef)
-
Return type:
transpose()
max.experimental.functional.transpose(x, axis_1, axis_2)
Transposes a tensor.
See max.graph.ops.transpose()
for details.
trunc()
max.experimental.functional.trunc(x)
Truncates tensor values element-wise.
See max.graph.ops.trunc()
for details.
unsqueeze()
max.experimental.functional.unsqueeze(x, axis)
Adds dimensions of size 1.
See max.graph.ops.unsqueeze()
for details.
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:
-
- condition (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- x (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
- y (Value[TensorType] | TensorValue | Shape | Dim | HasTensorValue | int | float | integer[Any] | floating[Any] | ndarray[Any, dtype[number[Any]]])
-
Return type:
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!