For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Python function
default_device
default_device()
max.experimental.tensor.default_device(device)
Context manager for setting the default device for tensor creation.
Sets the default device used for tensor creation within the context. All tensors created inside the context block without an explicit device parameter will use this device.
from max.experimental import tensor
from max.driver import CPU
with tensor.default_device(CPU()):
x = tensor.Tensor.ones((2, 3)) # Created on CPU
y = tensor.Tensor.zeros((2, 3)) # Also on CPUThe default can also be a
DeviceMesh. Tensors created inside
the block are then replicated across the mesh.
-
Parameters:
-
device (Device | DeviceMesh | DeviceRef) – The device or mesh to use as the default for tensor creation within the context.
-
Returns:
-
A context manager that sets the default device, and yields it as a
DeviceMesh. -
Return type: