torch.mps — PyTorch 2.7 documentation (original) (raw)

This package enables an interface for accessing MPS (Metal Performance Shaders) backend in Python. Metal is Apple’s API for programming metal GPU (graphics processor unit). Using MPS means that increased performance can be achieved, by running work on the metal GPU(s). See https://developer.apple.com/documentation/metalperformanceshaders for more details.

device_count Returns the number of available MPS devices.
synchronize Waits for all kernels in all streams on a MPS device to complete.
get_rng_state Returns the random number generator state as a ByteTensor.
set_rng_state Sets the random number generator state.
manual_seed Sets the seed for generating random numbers.
seed Sets the seed for generating random numbers to a random number.
empty_cache Releases all unoccupied cached memory currently held by the caching allocator so that those can be used in other GPU applications.
set_per_process_memory_fraction Set memory fraction for limiting process's memory allocation on MPS device.
current_allocated_memory Returns the current GPU memory occupied by tensors in bytes.
driver_allocated_memory Returns total GPU memory allocated by Metal driver for the process in bytes.
recommended_max_memory Returns recommended max Working set size for GPU memory in bytes.
compile_shader Compiles compute shader from source and allows one to invoke kernels defined there from the comfort of Python runtime Example.

MPS Event