Skip to main content
Ctrl+K
MLX 0.7.0 documentation - Home

Install

  • Build and Install

Usage

  • Quick Start Guide
  • Lazy Evaluation
  • Unified Memory
  • Indexing Arrays
  • Saving and Loading Arrays
  • Function Transforms
  • Compilation
  • Conversion to NumPy and Other Frameworks
  • Using Streams

Examples

  • Linear Regression
  • Multi-Layer Perceptron
  • LLM inference

Python API Reference

  • Array
    • mlx.core.array
    • mlx.core.array.astype
    • mlx.core.array.item
    • mlx.core.array.tolist
    • mlx.core.array.dtype
    • mlx.core.array.ndim
    • mlx.core.array.shape
    • mlx.core.array.size
    • mlx.core.Dtype
    • mlx.core.array.abs
    • mlx.core.array.all
    • mlx.core.array.any
    • mlx.core.array.argmax
    • mlx.core.array.argmin
    • mlx.core.array.cos
    • mlx.core.array.dtype
    • mlx.core.array.exp
    • mlx.core.array.log
    • mlx.core.array.log1p
    • mlx.core.array.logsumexp
    • mlx.core.array.max
    • mlx.core.array.mean
    • mlx.core.array.min
    • mlx.core.array.prod
    • mlx.core.array.reciprocal
    • mlx.core.array.reshape
    • mlx.core.array.round
    • mlx.core.array.rsqrt
    • mlx.core.array.sin
    • mlx.core.array.split
    • mlx.core.array.sqrt
    • mlx.core.array.square
    • mlx.core.array.sum
    • mlx.core.array.transpose
    • mlx.core.array.T
    • mlx.core.array.var
  • Devices and Streams
    • mlx.core.Device
    • mlx.core.Stream
    • mlx.core.default_device
    • mlx.core.set_default_device
    • mlx.core.default_stream
    • mlx.core.new_stream
    • mlx.core.set_default_stream
    • mlx.core.stream
  • Operations
    • mlx.core.abs
    • mlx.core.add
    • mlx.core.all
    • mlx.core.allclose
    • mlx.core.any
    • mlx.core.arange
    • mlx.core.arccos
    • mlx.core.arccosh
    • mlx.core.arcsin
    • mlx.core.arcsinh
    • mlx.core.arctan
    • mlx.core.arctanh
    • mlx.core.argmax
    • mlx.core.argmin
    • mlx.core.argpartition
    • mlx.core.argsort
    • mlx.core.array_equal
    • mlx.core.atleast_1d
    • mlx.core.atleast_2d
    • mlx.core.atleast_3d
    • mlx.core.broadcast_to
    • mlx.core.ceil
    • mlx.core.clip
    • mlx.core.concatenate
    • mlx.core.convolve
    • mlx.core.conv1d
    • mlx.core.conv2d
    • mlx.core.conv_general
    • mlx.core.cos
    • mlx.core.cosh
    • mlx.core.dequantize
    • mlx.core.diag
    • mlx.core.diagonal
    • mlx.core.divide
    • mlx.core.divmod
    • mlx.core.equal
    • mlx.core.erf
    • mlx.core.erfinv
    • mlx.core.exp
    • mlx.core.expand_dims
    • mlx.core.eye
    • mlx.core.flatten
    • mlx.core.floor
    • mlx.core.floor_divide
    • mlx.core.full
    • mlx.core.greater
    • mlx.core.greater_equal
    • mlx.core.identity
    • mlx.core.inner
    • mlx.core.isclose
    • mlx.core.isnan
    • mlx.core.isposinf
    • mlx.core.isneginf
    • mlx.core.isinf
    • mlx.core.less
    • mlx.core.less_equal
    • mlx.core.linspace
    • mlx.core.load
    • mlx.core.log
    • mlx.core.log2
    • mlx.core.log10
    • mlx.core.log1p
    • mlx.core.logaddexp
    • mlx.core.logical_not
    • mlx.core.logical_and
    • mlx.core.logical_or
    • mlx.core.logsumexp
    • mlx.core.matmul
    • mlx.core.max
    • mlx.core.maximum
    • mlx.core.mean
    • mlx.core.min
    • mlx.core.minimum
    • mlx.core.moveaxis
    • mlx.core.multiply
    • mlx.core.negative
    • mlx.core.ones
    • mlx.core.ones_like
    • mlx.core.outer
    • mlx.core.partition
    • mlx.core.pad
    • mlx.core.prod
    • mlx.core.quantize
    • mlx.core.quantized_matmul
    • mlx.core.reciprocal
    • mlx.core.repeat
    • mlx.core.reshape
    • mlx.core.round
    • mlx.core.rsqrt
    • mlx.core.save
    • mlx.core.savez
    • mlx.core.savez_compressed
    • mlx.core.save_gguf
    • mlx.core.save_safetensors
    • mlx.core.sigmoid
    • mlx.core.sign
    • mlx.core.sin
    • mlx.core.sinh
    • mlx.core.softmax
    • mlx.core.sort
    • mlx.core.split
    • mlx.core.sqrt
    • mlx.core.square
    • mlx.core.squeeze
    • mlx.core.stack
    • mlx.core.stop_gradient
    • mlx.core.subtract
    • mlx.core.sum
    • mlx.core.swapaxes
    • mlx.core.take
    • mlx.core.take_along_axis
    • mlx.core.tan
    • mlx.core.tanh
    • mlx.core.tensordot
    • mlx.core.tile
    • mlx.core.topk
    • mlx.core.transpose
    • mlx.core.tri
    • mlx.core.tril
    • mlx.core.triu
    • mlx.core.var
    • mlx.core.where
    • mlx.core.zeros
    • mlx.core.zeros_like
  • Random
    • mlx.core.random.bernoulli
    • mlx.core.random.categorical
    • mlx.core.random.gumbel
    • mlx.core.random.key
    • mlx.core.random.normal
    • mlx.core.random.randint
    • mlx.core.random.seed
    • mlx.core.random.split
    • mlx.core.random.truncated_normal
    • mlx.core.random.uniform
  • Transforms
    • mlx.core.eval
    • mlx.core.compile
    • mlx.core.disable_compile
    • mlx.core.enable_compile
    • mlx.core.grad
    • mlx.core.value_and_grad
    • mlx.core.jvp
    • mlx.core.vjp
    • mlx.core.vmap
  • FFT
    • mlx.core.fft.fft
    • mlx.core.fft.ifft
    • mlx.core.fft.fft2
    • mlx.core.fft.ifft2
    • mlx.core.fft.fftn
    • mlx.core.fft.ifftn
    • mlx.core.fft.rfft
    • mlx.core.fft.irfft
    • mlx.core.fft.rfft2
    • mlx.core.fft.irfft2
    • mlx.core.fft.rfftn
    • mlx.core.fft.irfftn
  • Linear Algebra
    • mlx.core.linalg.norm
    • mlx.core.linalg.qr
  • Metal
    • mlx.core.metal.is_available
    • mlx.core.metal.get_active_memory
    • mlx.core.metal.get_peak_memory
    • mlx.core.metal.get_cache_memory
    • mlx.core.metal.set_memory_limit
    • mlx.core.metal.set_cache_limit
  • Neural Networks
    • mlx.nn.value_and_grad
    • Module
      • mlx.nn.Module.training
      • mlx.nn.Module.state
      • mlx.nn.Module.apply
      • mlx.nn.Module.apply_to_modules
      • mlx.nn.Module.children
      • mlx.nn.Module.eval
      • mlx.nn.Module.filter_and_map
      • mlx.nn.Module.freeze
      • mlx.nn.Module.leaf_modules
      • mlx.nn.Module.load_weights
      • mlx.nn.Module.modules
      • mlx.nn.Module.named_modules
      • mlx.nn.Module.parameters
      • mlx.nn.Module.save_weights
      • mlx.nn.Module.train
      • mlx.nn.Module.trainable_parameters
      • mlx.nn.Module.unfreeze
      • mlx.nn.Module.update
      • mlx.nn.Module.update_modules
    • Layers
      • mlx.nn.ALiBi
      • mlx.nn.AvgPool1d
      • mlx.nn.AvgPool2d
      • mlx.nn.BatchNorm
      • mlx.nn.Conv1d
      • mlx.nn.Conv2d
      • mlx.nn.Dropout
      • mlx.nn.Dropout2d
      • mlx.nn.Dropout3d
      • mlx.nn.Embedding
      • mlx.nn.GELU
      • mlx.nn.GroupNorm
      • mlx.nn.GRU
      • mlx.nn.InstanceNorm
      • mlx.nn.LayerNorm
      • mlx.nn.Linear
      • mlx.nn.LSTM
      • mlx.nn.MaxPool1d
      • mlx.nn.MaxPool2d
      • mlx.nn.Mish
      • mlx.nn.MultiHeadAttention
      • mlx.nn.PReLU
      • mlx.nn.QuantizedLinear
      • mlx.nn.RMSNorm
      • mlx.nn.ReLU
      • mlx.nn.RNN
      • mlx.nn.RoPE
      • mlx.nn.SELU
      • mlx.nn.Sequential
      • mlx.nn.SiLU
      • mlx.nn.SinusoidalPositionalEncoding
      • mlx.nn.Softshrink
      • mlx.nn.Step
      • mlx.nn.Transformer
      • mlx.nn.Upsample
    • Functions
      • mlx.nn.elu
      • mlx.nn.gelu
      • mlx.nn.gelu_approx
      • mlx.nn.gelu_fast_approx
      • mlx.nn.glu
      • mlx.nn.hardswish
      • mlx.nn.leaky_relu
      • mlx.nn.log_sigmoid
      • mlx.nn.log_softmax
      • mlx.nn.mish
      • mlx.nn.prelu
      • mlx.nn.relu
      • mlx.nn.relu6
      • mlx.nn.selu
      • mlx.nn.sigmoid
      • mlx.nn.silu
      • mlx.nn.softmax
      • mlx.nn.softplus
      • mlx.nn.softshrink
      • mlx.nn.step
      • mlx.nn.tanh
    • Loss Functions
      • mlx.nn.losses.binary_cross_entropy
      • mlx.nn.losses.cosine_similarity_loss
      • mlx.nn.losses.cross_entropy
      • mlx.nn.losses.gaussian_nll_loss
      • mlx.nn.losses.hinge_loss
      • mlx.nn.losses.huber_loss
      • mlx.nn.losses.kl_div_loss
      • mlx.nn.losses.l1_loss
      • mlx.nn.losses.log_cosh_loss
      • mlx.nn.losses.margin_ranking_loss
      • mlx.nn.losses.mse_loss
      • mlx.nn.losses.nll_loss
      • mlx.nn.losses.smooth_l1_loss
      • mlx.nn.losses.triplet_loss
    • Initializers
      • mlx.nn.init.constant
      • mlx.nn.init.normal
      • mlx.nn.init.uniform
      • mlx.nn.init.identity
      • mlx.nn.init.glorot_normal
      • mlx.nn.init.glorot_uniform
      • mlx.nn.init.he_normal
      • mlx.nn.init.he_uniform
  • Optimizers
    • Optimizer
      • mlx.optimizers.Optimizer.state
      • mlx.optimizers.Optimizer.apply_gradients
      • mlx.optimizers.Optimizer.init
      • mlx.optimizers.Optimizer.update
    • Common Optimizers
      • mlx.optimizers.SGD
      • mlx.optimizers.RMSprop
      • mlx.optimizers.Adagrad
      • mlx.optimizers.Adafactor
      • mlx.optimizers.AdaDelta
      • mlx.optimizers.Adam
      • mlx.optimizers.AdamW
      • mlx.optimizers.Adamax
      • mlx.optimizers.Lion
    • Schedulers
      • mlx.optimizers.cosine_decay
      • mlx.optimizers.exponential_decay
      • mlx.optimizers.join_schedules
      • mlx.optimizers.linear_schedule
      • mlx.optimizers.step_decay
  • Tree Utils
    • mlx.utils.tree_flatten
    • mlx.utils.tree_unflatten
    • mlx.utils.tree_map

C++ API Reference

  • Operations

Further Reading

  • Developer Documentation
  • .rst

Devices and Streams

Devices and Streams#

Device

A device to run operations on.

Stream

A stream for running operations on a given device.

default_device()

Get the default device.

set_default_device(device)

Set the default device.

default_stream(device)

Get the device's default stream.

new_stream(device)

Make a new stream on the given device.

set_default_stream(stream)

Set the default stream.

stream(s)

Create a context manager to set the default device and stream.

previous

mlx.core.array.var

next

mlx.core.Device

By MLX Contributors

© Copyright 2023, MLX Contributors.