Expand description
Unofficial rust bindings for the MLX framework.
§Table of Contents
§Threading
Array values may move between threads. MLX 0.32.2 keeps default streams per thread, so each
worker must perform operations through its own default or thread-local scoped override.
Stream and compiled closures are thread-affine and cannot move or be shared across threads.
The scoped Rust override is thread-local, not asynchronous task-local, and does not propagate
across .await.
§Quick Start
See also MLX python documentation
§Basics
use mlx_rs::{array, Dtype};
let a = array!([1, 2, 3, 4]);
assert_eq!(a.shape(), &[4]);
assert_eq!(a.dtype(), Dtype::Int32);
let b = array!([1.0, 2.0, 3.0, 4.0]);
assert_eq!(b.dtype(), Dtype::Float32);Operations in MLX are lazy. Use Array::eval to evaluate the the output
of an operation. Operations are also automatically evaluated when inspecting
an array with Array::item_exact or Array::item_cast, printing an array, or attempting to obtain
the underlying data with Array::as_slice.
use mlx_rs::{array, transforms::eval};
let a = array!([1, 2, 3, 4]);
let b = array!([1.0, 2.0, 3.0, 4.0]);
let c = &a + &b; // c is not evaluated
c.eval().unwrap(); // evaluates c
let d = &a + &b;
println!("{:?}", d); // evaluates d
let e = &a + &b;
let e_slice: &[f32] = e.as_slice(); // evaluates eSee Lazy Evaluation for more details.
§Function and Graph Transformations
TODO: https://github.com/oxiglade/mlx-rs/issues/214
TODO: also document that all Array in the args for function
transformations
§Lazy Evaluation
See also MLX python documentation
§Why Lazy Evaluation
When you perform operations in MLX, no computation actually happens. Instead
a compute graph is recorded. The actual computation only happens if an
Array::eval is performed.
MLX uses lazy evaluation because it has some nice features, some of which we describe below.
§Transforming Compute Graphs
Lazy evaluation lets us record a compute graph without actually doing any
computations. This is useful for function transformations like
transforms::grad and graph optimizations.
Currently, MLX does not compile and rerun compute graphs. They are all generated dynamically. However, lazy evaluation makes it much easier to integrate compilation for future performance enhancements.
§Only Compute What You Use
In MLX you do not need to worry as much about computing outputs that are never used. For example:
fn fun(x: &Array) -> (Array, Array) {
let a = cheap_fun(x);
let b = expensive_fun(x);
(a, b)
}
let (y, _) = fun(&x);Here, we never actually compute the output of expensive_fun. Use this
pattern with care though, as the graph of expensive_fun is still built,
and that has some cost associated to it.
Similarly, lazy evaluation can be beneficial for saving memory while keeping
code simple. Say you have a very large model Model implementing
module::Module. You can instantiate this model with let model = Model::new(). Typically, this will initialize all of the weights as
float32, but the initialization does not actually compute anything until
you perform an eval(). If you update the model with float16 weights,
your maximum consumed memory will be half that required if eager computation
was used instead.
This pattern is simple to do in MLX thanks to lazy computation:
let mut model = Model::new();
model.load_safetensors("model.safetensors").unwrap();§When to Evaluate
A common question is when to use eval(). The trade-off is between letting
graphs get too large and not batching enough useful work.
For example
let mut a = array!([1, 2, 3, 4]);
let mut b = array!([1.0, 2.0, 3.0, 4.0]);
for _ in 0..100 {
a = a + b;
a.eval()?;
b = b * 2.0;
b.eval()?;
}This is a bad idea because there is some fixed overhead with each graph evaluation. On the other hand, there is some slight overhead which grows with the compute graph size, so extremely large graphs (while computationally correct) can be costly.
Luckily, a wide range of compute graph sizes work pretty well with MLX: anything from a few tens of operations to many thousands of operations per evaluation should be okay.
Most numerical computations have an iterative outer loop (e.g. the iteration
in stochastic gradient descent). A natural and usually efficient place to
use eval() is at each iteration of this outer loop.
Here is a concrete example:
for batch in dataset {
// Nothing has been evaluated yet
let (loss, grad) = value_and_grad_fn(&mut model, batch)?;
// Still nothing has been evaluated
optimizer.update(&mut model, grad)?;
// Evaluate the loss and the new parameters which will
// run the full gradient computation and optimizer update
eval_params(model.parameters())?;
}An important behavior to be aware of is when the graph will be implicitly
evaluated. Anytime you print an array, or otherwise access its memory via
Array::as_slice, the graph will be evaluated. Saving arrays via
Array::save_numpy or Array::save_safetensors (or any other MLX
saving functions) will also evaluate the array.
Calling Array::item_exact or Array::item_cast on a scalar array will also evaluate it. In the
example above, printing the loss (println!("{:?}", loss)) or pushing the
loss scalar to a Vec (losses.push(loss.item_exact::<f32>())) would cause a
graph evaluation. If these lines are before evaluating the loss and module
parameters, then this will be a partial evaluation, computing only the
forward pass.
Also, calling eval() on an array or set of arrays multiple times is
perfectly fine. This is effectively a no-op.
Warning: Using scalar arrays for control-flow will cause an evaluation.
fn fun(x: &Array) -> Array {
let (h, y) = first_layer(x);
if y.gt(array!(0.5)).unwrap().item_exact() {
second_layer_a(h)
} else {
second_layer_b(h)
}
}Using arrays for control flow should be done with care. The above example works and can even be used with gradient transformations. However, this can be very inefficient if evaluations are done too frequently.
§Unified Memory
See also MLX python documentation
Apple silicon has a unified memory architecture. The CPU and GPU have direct access to the same memory pool. MLX is designed to take advantage of that.
Concretely, when you make an array in MLX you don’t have to specify its location:
let a = mlx_rs::random::normal::<f32>(&[100], None, None, None).unwrap();
let b = mlx_rs::random::normal::<f32>(&[100], None, None, None).unwrap();Both a and b live in unified memory.
In MLX, rather than moving arrays to devices, you specify the device when
you run the operation. Any device can perform any operation on a and b
without needing to move them from one memory location to another. For
example:
mlx_rs::with_device(mlx_rs::Device::cpu(), || mlx_rs::ops::add(&a, &b)).unwrap();
mlx_rs::with_device(mlx_rs::Device::gpu(), || mlx_rs::ops::add(&a, &b)).unwrap();In the above, both the CPU and the GPU will perform the same add operation.
TODO: The remaining python documentations states that the stream can be used to parallelize operations without worrying about racing conditions. We should check if this is true given that we’ve already observed data racing when executing unit tests in parallel.
§Indexing Arrays
See also MLX python documentation
Please refer to the indexing modules (ops::indexing) for more details.
§Saving and Loading
See also MLX python documentation
mlx-rs supports loading from .npy and .safetensors files and saving to
.safetensors files. Module parameters and optimizer states can also be saved
and loaded from .safetensors files.
§Function Transforms
See also MLX python documentation
Please refer to the transforms module (transforms) for more details.
§Compilation
See also MLX python documentation
Please refer to the compilation module (transforms::compile) for more
details.
Modules§
- builder
- Defines helper traits for builder pattern
- error
- Custom error types and handler for the c ffi
- fast
- Fast implementations of commonly used multi-op functions.
- fft
- Fast Fourier Transform (FFT) and its inverse (IFFT) for one, two, and
Ndimensions. - io
- GGUF container loading, inspection, construction, and saving.
- linalg
- Linear algebra operations.
- losses
- Loss functions
- macros
- Macros for mlx-rs.
- memory
- Process-global MLX allocator controls and observations.
- metal
- Metal-specific runtime configuration.
- module
- This mod defines the traits for neural network modules and parameters.
- nested
- Implements a nested hashmap
- nn
- Neural network support for MLX
- ops
- Operations
- optimizers
- Trait and implementations for optimizers.
- quantization
- Traits for quantization
- random
- Collection of functions related to random number generation
- transforms
- Function transforms
- utils
- Utility functions and types.
Macros§
- abs
Deprecated - Macro generated for the function
crate::ops::abs. See the function documentation for more details. - acos
Deprecated - Macro generated for the function
crate::ops::acos. See the function documentation for more details. - acosh
Deprecated - Macro generated for the function
crate::ops::acosh. See the function documentation for more details. - add
Deprecated - Macro generated for the function
crate::ops::add. See the function documentation for more details. - addmm
Deprecated - Macro generated for the function
crate::ops::addmm. See the function documentation for more details. - all
Deprecated - Macro generated for the function
crate::ops::all. See the function documentation for more details. - all_
axes Deprecated - Macro generated for the function
crate::ops::all_axes. See the function documentation for more details. - all_
axis Deprecated - Macro generated for the function
crate::ops::all_axis. See the function documentation for more details. - all_
close Deprecated - Macro generated for the function
crate::ops::all_close. See the function documentation for more details. - any
Deprecated - Macro generated for the function
crate::ops::any. See the function documentation for more details. - any_
axes Deprecated - Macro generated for the function
crate::ops::any_axes. See the function documentation for more details. - any_
axis Deprecated - Macro generated for the function
crate::ops::any_axis. See the function documentation for more details. - arange
Deprecated - Macro generated for the function
crate::ops::arange. See the function documentation for more details. - argmax
Deprecated - Macro generated for the function
crate::ops::indexing::argmax. See the function documentation for more details. - argmax_
axis Deprecated - Macro generated for the function
crate::ops::indexing::argmax_axis. See the function documentation for more details. - argmin
Deprecated - Macro generated for the function
crate::ops::indexing::argmin. See the function documentation for more details. - argmin_
axis Deprecated - Macro generated for the function
crate::ops::indexing::argmin_axis. See the function documentation for more details. - argpartition
Deprecated - Macro generated for the function
crate::ops::argpartition. See the function documentation for more details. - argpartition_
axis Deprecated - Macro generated for the function
crate::ops::argpartition_axis. See the function documentation for more details. - argsort
Deprecated - Macro generated for the function
crate::ops::argsort. See the function documentation for more details. - argsort_
axis Deprecated - Macro generated for the function
crate::ops::argsort_axis. See the function documentation for more details. - array
- A helper macro to create an array with up to 3 dimensions.
- array_
eq Deprecated - Macro generated for the function
crate::ops::array_eq. See the function documentation for more details. - as_
strided Deprecated - Macro generated for the function
crate::ops::as_strided. See the function documentation for more details. - asin
Deprecated - Macro generated for the function
crate::ops::asin. See the function documentation for more details. - asinh
Deprecated - Macro generated for the function
crate::ops::asinh. See the function documentation for more details. - assert_
array_ eq - Asserts that two arrays are equal.
- at_
least_ 1d Deprecated - Macro generated for the function
crate::ops::at_least_1d. See the function documentation for more details. - at_
least_ 2d Deprecated - Macro generated for the function
crate::ops::at_least_2d. See the function documentation for more details. - at_
least_ 3d Deprecated - Macro generated for the function
crate::ops::at_least_3d. See the function documentation for more details. - atan
Deprecated - Macro generated for the function
crate::ops::atan. See the function documentation for more details. - atan2
Deprecated - Macro generated for the function
crate::ops::atan2. See the function documentation for more details. - atanh
Deprecated - Macro generated for the function
crate::ops::atanh. See the function documentation for more details. - bernoulli
Deprecated - Macro generated for the function
crate::random::bernoulli. See the function documentation for more details. - block_
masked_ mm Deprecated - Macro generated for the function
crate::ops::block_masked_mm. See the function documentation for more details. - broadcast_
arrays Deprecated - Macro generated for the function
crate::ops::broadcast_arrays. See the function documentation for more details. - broadcast_
to Deprecated - Macro generated for the function
crate::ops::broadcast_to. See the function documentation for more details. - categorical
Deprecated - Macro generated for the function
crate::random::categorical. See the function documentation for more details. - ceil
Deprecated - Macro generated for the function
crate::ops::ceil. See the function documentation for more details. - cholesky
Deprecated - Macro generated for the function
crate::linalg::cholesky. See the function documentation for more details. - cholesky_
inv Deprecated - Macro generated for the function
crate::linalg::cholesky_inv. See the function documentation for more details. - clip
Deprecated - Macro generated for the function
crate::ops::clip. See the function documentation for more details. - concatenate
Deprecated - Macro generated for the function
crate::ops::concatenate. See the function documentation for more details. - concatenate_
axis Deprecated - Macro generated for the function
crate::ops::concatenate_axis. See the function documentation for more details. - conv1d
Deprecated - Macro generated for the function
crate::ops::conv1d. See the function documentation for more details. - conv2d
Deprecated - Macro generated for the function
crate::ops::conv2d. See the function documentation for more details. - conv3d
Deprecated - Macro generated for the function
crate::ops::conv3d. See the function documentation for more details. - conv_
general Deprecated - Macro generated for the function
crate::ops::conv_general. See the function documentation for more details. - conv_
transpose1d Deprecated - Macro generated for the function
crate::ops::conv_transpose1d. See the function documentation for more details. - conv_
transpose2d Deprecated - Macro generated for the function
crate::ops::conv_transpose2d. See the function documentation for more details. - conv_
transpose3d Deprecated - Macro generated for the function
crate::ops::conv_transpose3d. See the function documentation for more details. - cos
Deprecated - Macro generated for the function
crate::ops::cos. See the function documentation for more details. - cosh
Deprecated - Macro generated for the function
crate::ops::cosh. See the function documentation for more details. - cross
Deprecated - Macro generated for the function
crate::linalg::cross. See the function documentation for more details. - cummax
Deprecated - Macro generated for the function
crate::ops::cummax. See the function documentation for more details. - cummin
Deprecated - Macro generated for the function
crate::ops::cummin. See the function documentation for more details. - cumprod
Deprecated - Macro generated for the function
crate::ops::cumprod. See the function documentation for more details. - cumsum
Deprecated - Macro generated for the function
crate::ops::cumsum. See the function documentation for more details. - degrees
Deprecated - Macro generated for the function
crate::ops::degrees. See the function documentation for more details. - dequantize
Deprecated - Macro generated for the function
crate::ops::dequantize. See the function documentation for more details. - diag
Deprecated - Macro generated for the function
crate::ops::diag. See the function documentation for more details. - diagonal
Deprecated - Macro generated for the function
crate::ops::diagonal. See the function documentation for more details. - divide
Deprecated - Macro generated for the function
crate::ops::divide. See the function documentation for more details. - divmod
Deprecated - Macro generated for the function
crate::ops::divmod. See the function documentation for more details. - eig
Deprecated - Macro generated for the function
crate::linalg::eig. See the function documentation for more details. - eigh
Deprecated - Macro generated for the function
crate::linalg::eigh. See the function documentation for more details. - eigvals
Deprecated - Macro generated for the function
crate::linalg::eigvals. See the function documentation for more details. - eigvalsh
Deprecated - Macro generated for the function
crate::linalg::eigvalsh. See the function documentation for more details. - einsum
Deprecated - Macro generated for the function
crate::ops::einsum. See the function documentation for more details. - eq
Deprecated - Macro generated for the function
crate::ops::eq. See the function documentation for more details. - erf
Deprecated - Macro generated for the function
crate::ops::erf. See the function documentation for more details. - erfinv
Deprecated - Macro generated for the function
crate::ops::erfinv. See the function documentation for more details. - exp
Deprecated - Macro generated for the function
crate::ops::exp. See the function documentation for more details. - expand_
dims Deprecated - Macro generated for the function
crate::ops::expand_dims. See the function documentation for more details. - expand_
dims_ axes Deprecated - Macro generated for the function
crate::ops::expand_dims_axes. See the function documentation for more details. - expm1
Deprecated - Macro generated for the function
crate::ops::expm1. See the function documentation for more details. - eye
Deprecated - Macro generated for the function
crate::ops::eye. See the function documentation for more details. - fft
Deprecated - Macro generated for the function
crate::fft::fft. See the function documentation for more details. - fft2
Deprecated - Macro generated for the function
crate::fft::fft2. See the function documentation for more details. - fftn
Deprecated - Macro generated for the function
crate::fft::fftn. See the function documentation for more details. - fftshift
Deprecated - Macro generated for the function
crate::fft::fftshift. See the function documentation for more details. - flatten
Deprecated - Macro generated for the function
crate::ops::flatten. See the function documentation for more details. - floor
Deprecated - Macro generated for the function
crate::ops::floor. See the function documentation for more details. - floor_
divide Deprecated - Macro generated for the function
crate::ops::floor_divide. See the function documentation for more details. - from_
fp8 Deprecated - Macro generated for the function
crate::ops::from_fp8. See the function documentation for more details. - full
Deprecated - Macro generated for the function
crate::ops::full. See the function documentation for more details. - full_
like Deprecated - Macro generated for the function
crate::ops::full_like. See the function documentation for more details. - gather_
mm Deprecated - Macro generated for the function
crate::ops::gather_mm. See the function documentation for more details. - gather_
qmm Deprecated - Macro generated for the function
crate::ops::gather_qmm. See the function documentation for more details. - gather_
single Deprecated - Macro generated for the function
crate::ops::indexing::gather_single. See the function documentation for more details. - ge
Deprecated - Macro generated for the function
crate::ops::ge. See the function documentation for more details. - gt
Deprecated - Macro generated for the function
crate::ops::gt. See the function documentation for more details. - gumbel
Deprecated - Macro generated for the function
crate::random::gumbel. See the function documentation for more details. - identity
Deprecated - Macro generated for the function
crate::ops::identity. See the function documentation for more details. - ifft
Deprecated - Macro generated for the function
crate::fft::ifft. See the function documentation for more details. - ifft2
Deprecated - Macro generated for the function
crate::fft::ifft2. See the function documentation for more details. - ifftn
Deprecated - Macro generated for the function
crate::fft::ifftn. See the function documentation for more details. - ifftshift
Deprecated - Macro generated for the function
crate::fft::ifftshift. See the function documentation for more details. - imag
Deprecated - Macro generated for the function
crate::ops::imag. See the function documentation for more details. - inner
Deprecated - Macro generated for the function
crate::ops::inner. See the function documentation for more details. - inv
Deprecated - Macro generated for the function
crate::linalg::inv. See the function documentation for more details. - irfft
Deprecated - Macro generated for the function
crate::fft::irfft. See the function documentation for more details. - irfft2
Deprecated - Macro generated for the function
crate::fft::irfft2. See the function documentation for more details. - irfftn
Deprecated - Macro generated for the function
crate::fft::irfftn. See the function documentation for more details. - is_
close Deprecated - Macro generated for the function
crate::ops::is_close. See the function documentation for more details. - is_inf
Deprecated - Macro generated for the function
crate::ops::is_inf. See the function documentation for more details. - is_nan
Deprecated - Macro generated for the function
crate::ops::is_nan. See the function documentation for more details. - is_
neg_ inf Deprecated - Macro generated for the function
crate::ops::is_neg_inf. See the function documentation for more details. - is_
pos_ inf Deprecated - Macro generated for the function
crate::ops::is_pos_inf. See the function documentation for more details. - kron
Deprecated - Macro generated for the function
crate::ops::kron. See the function documentation for more details. - layer_
norm Deprecated - Macro generated for the function
crate::fast::layer_norm. See the function documentation for more details. - le
Deprecated - Macro generated for the function
crate::ops::le. See the function documentation for more details. - linspace
Deprecated - Macro generated for the function
crate::ops::linspace. See the function documentation for more details. - log
Deprecated - Macro generated for the function
crate::ops::log. See the function documentation for more details. - log2
Deprecated - Macro generated for the function
crate::ops::log2. See the function documentation for more details. - log1p
Deprecated - Macro generated for the function
crate::ops::log1p. See the function documentation for more details. - log10
Deprecated - Macro generated for the function
crate::ops::log10. See the function documentation for more details. - logaddexp
Deprecated - Macro generated for the function
crate::ops::logaddexp. See the function documentation for more details. - logical_
and Deprecated - Macro generated for the function
crate::ops::logical_and. See the function documentation for more details. - logical_
not Deprecated - Macro generated for the function
crate::ops::logical_not. See the function documentation for more details. - logical_
or Deprecated - Macro generated for the function
crate::ops::logical_or. See the function documentation for more details. - logsumexp
Deprecated - Macro generated for the function
crate::ops::logsumexp. See the function documentation for more details. - logsumexp_
axes Deprecated - Macro generated for the function
crate::ops::logsumexp_axes. See the function documentation for more details. - logsumexp_
axis Deprecated - Macro generated for the function
crate::ops::logsumexp_axis. See the function documentation for more details. - lt
Deprecated - Macro generated for the function
crate::ops::lt. See the function documentation for more details. - lu
Deprecated - Macro generated for the function
crate::linalg::lu. See the function documentation for more details. - lu_
factor Deprecated - Macro generated for the function
crate::linalg::lu_factor. See the function documentation for more details. - masked_
scatter Deprecated - Macro generated for the function
crate::ops::indexing::masked_scatter. See the function documentation for more details. - matmul
Deprecated - Macro generated for the function
crate::ops::matmul. See the function documentation for more details. - max
Deprecated - Macro generated for the function
crate::ops::max. See the function documentation for more details. - max_
axes Deprecated - Macro generated for the function
crate::ops::max_axes. See the function documentation for more details. - max_
axis Deprecated - Macro generated for the function
crate::ops::max_axis. See the function documentation for more details. - maximum
Deprecated - Macro generated for the function
crate::ops::maximum. See the function documentation for more details. - mean
Deprecated - Macro generated for the function
crate::ops::mean. See the function documentation for more details. - mean_
axes Deprecated - Macro generated for the function
crate::ops::mean_axes. See the function documentation for more details. - mean_
axis Deprecated - Macro generated for the function
crate::ops::mean_axis. See the function documentation for more details. - median
Deprecated - Macro generated for the function
crate::ops::median. See the function documentation for more details. - median_
axes Deprecated - Macro generated for the function
crate::ops::median_axes. See the function documentation for more details. - median_
axis Deprecated - Macro generated for the function
crate::ops::median_axis. See the function documentation for more details. - min
Deprecated - Macro generated for the function
crate::ops::min. See the function documentation for more details. - min_
axes Deprecated - Macro generated for the function
crate::ops::min_axes. See the function documentation for more details. - min_
axis Deprecated - Macro generated for the function
crate::ops::min_axis. See the function documentation for more details. - minimum
Deprecated - Macro generated for the function
crate::ops::minimum. See the function documentation for more details. - move_
axis Deprecated - Macro generated for the function
crate::ops::move_axis. See the function documentation for more details. - multiply
Deprecated - Macro generated for the function
crate::ops::multiply. See the function documentation for more details. - multivariate_
normal Deprecated - Macro generated for the function
crate::random::multivariate_normal. See the function documentation for more details. - ne
Deprecated - Macro generated for the function
crate::ops::ne. See the function documentation for more details. - negative
Deprecated - Macro generated for the function
crate::ops::negative. See the function documentation for more details. - norm
Deprecated - Macro generated for the function
crate::linalg::norm. See the function documentation for more details. - norm_l2
Deprecated - Macro generated for the function
crate::linalg::norm_l2. See the function documentation for more details. - norm_
matrix Deprecated - Macro generated for the function
crate::linalg::norm_matrix. See the function documentation for more details. - normal
Deprecated - Macro generated for the function
crate::random::normal. See the function documentation for more details. - ones
Deprecated - Macro generated for the function
crate::ops::ones. See the function documentation for more details. - ones_
dtype Deprecated - Macro generated for the function
crate::ops::ones_dtype. See the function documentation for more details. - ones_
like Deprecated - Macro generated for the function
crate::ops::ones_like. See the function documentation for more details. - outer
Deprecated - Macro generated for the function
crate::ops::outer. See the function documentation for more details. - pad
Deprecated - Macro generated for the function
crate::ops::pad. See the function documentation for more details. - partition
Deprecated - Macro generated for the function
crate::ops::partition. See the function documentation for more details. - partition_
axis Deprecated - Macro generated for the function
crate::ops::partition_axis. See the function documentation for more details. - pinv
Deprecated - Macro generated for the function
crate::linalg::pinv. See the function documentation for more details. - power
Deprecated - Macro generated for the function
crate::ops::power. See the function documentation for more details. - prod
Deprecated - Macro generated for the function
crate::ops::prod. See the function documentation for more details. - prod_
axes Deprecated - Macro generated for the function
crate::ops::prod_axes. See the function documentation for more details. - prod_
axis Deprecated - Macro generated for the function
crate::ops::prod_axis. See the function documentation for more details. - put_
along_ axis Deprecated - Macro generated for the function
crate::ops::indexing::put_along_axis. See the function documentation for more details. - qr
Deprecated - Macro generated for the function
crate::linalg::qr. See the function documentation for more details. - quantize
Deprecated - Macro generated for the function
crate::ops::quantize. See the function documentation for more details. - quantized_
matmul Deprecated - Macro generated for the function
crate::ops::quantized_matmul. See the function documentation for more details. - radians
Deprecated - Macro generated for the function
crate::ops::radians. See the function documentation for more details. - randint
Deprecated - Macro generated for the function
crate::random::randint. See the function documentation for more details. - real
Deprecated - Macro generated for the function
crate::ops::real. See the function documentation for more details. - reciprocal
Deprecated - Macro generated for the function
crate::ops::reciprocal. See the function documentation for more details. - remainder
Deprecated - Macro generated for the function
crate::ops::remainder. See the function documentation for more details. - repeat
Deprecated - Macro generated for the function
crate::ops::repeat. See the function documentation for more details. - repeat_
axis Deprecated - Macro generated for the function
crate::ops::repeat_axis. See the function documentation for more details. - reshape
Deprecated - Macro generated for the function
crate::ops::reshape. See the function documentation for more details. - rfft
Deprecated - Macro generated for the function
crate::fft::rfft. See the function documentation for more details. - rfft2
Deprecated - Macro generated for the function
crate::fft::rfft2. See the function documentation for more details. - rfftn
Deprecated - Macro generated for the function
crate::fft::rfftn. See the function documentation for more details. - rms_
norm Deprecated - Macro generated for the function
crate::fast::rms_norm. See the function documentation for more details. - rope
Deprecated - Macro generated for the function
crate::fast::rope. See the function documentation for more details. - rope_
dynamic Deprecated - Macro generated for the function
crate::fast::rope_dynamic. See the function documentation for more details. - round
Deprecated - Macro generated for the function
crate::ops::round. See the function documentation for more details. - rsqrt
Deprecated - Macro generated for the function
crate::ops::rsqrt. See the function documentation for more details. - scaled_
dot_ product_ attention Deprecated - Macro generated for the function
crate::fast::scaled_dot_product_attention. See the function documentation for more details. - scatter_
add_ single Deprecated - Macro generated for the function
crate::ops::indexing::scatter_add_single. See the function documentation for more details. - scatter_
max_ single Deprecated - Macro generated for the function
crate::ops::indexing::scatter_max_single. See the function documentation for more details. - scatter_
min_ single Deprecated - Macro generated for the function
crate::ops::indexing::scatter_min_single. See the function documentation for more details. - scatter_
prod_ single Deprecated - Macro generated for the function
crate::ops::indexing::scatter_prod_single. See the function documentation for more details. - scatter_
single Deprecated - Macro generated for the function
crate::ops::indexing::scatter_single. See the function documentation for more details. - segmented_
mm Deprecated - Macro generated for the function
crate::ops::segmented_mm. See the function documentation for more details. - sigmoid
Deprecated - Macro generated for the function
crate::ops::sigmoid. See the function documentation for more details. - sign
Deprecated - Macro generated for the function
crate::ops::sign. See the function documentation for more details. - sin
Deprecated - Macro generated for the function
crate::ops::sin. See the function documentation for more details. - sinh
Deprecated - Macro generated for the function
crate::ops::sinh. See the function documentation for more details. - softmax
Deprecated - Macro generated for the function
crate::ops::softmax. See the function documentation for more details. - softmax_
axes Deprecated - Macro generated for the function
crate::ops::softmax_axes. See the function documentation for more details. - softmax_
axis Deprecated - Macro generated for the function
crate::ops::softmax_axis. See the function documentation for more details. - solve
Deprecated - Macro generated for the function
crate::linalg::solve. See the function documentation for more details. - solve_
triangular Deprecated - Macro generated for the function
crate::linalg::solve_triangular. See the function documentation for more details. - sort
Deprecated - Macro generated for the function
crate::ops::sort. See the function documentation for more details. - sort_
axis Deprecated - Macro generated for the function
crate::ops::sort_axis. See the function documentation for more details. - split
Deprecated - Macro generated for the function
crate::ops::split. See the function documentation for more details. - split_
sections Deprecated - Macro generated for the function
crate::ops::split_sections. See the function documentation for more details. - sqrt
Deprecated - Macro generated for the function
crate::ops::sqrt. See the function documentation for more details. - square
Deprecated - Macro generated for the function
crate::ops::square. See the function documentation for more details. - squeeze
Deprecated - Macro generated for the function
crate::ops::squeeze. See the function documentation for more details. - squeeze_
axes Deprecated - Macro generated for the function
crate::ops::squeeze_axes. See the function documentation for more details. - stack
Deprecated - Macro generated for the function
crate::ops::stack. See the function documentation for more details. - stack_
axis Deprecated - Macro generated for the function
crate::ops::stack_axis. See the function documentation for more details. - std
Deprecated - Macro generated for the function
crate::ops::std. See the function documentation for more details. - std_
axes Deprecated - Macro generated for the function
crate::ops::std_axes. See the function documentation for more details. - std_
axis Deprecated - Macro generated for the function
crate::ops::std_axis. See the function documentation for more details. - subtract
Deprecated - Macro generated for the function
crate::ops::subtract. See the function documentation for more details. - sum
Deprecated - Macro generated for the function
crate::ops::sum. See the function documentation for more details. - sum_
axes Deprecated - Macro generated for the function
crate::ops::sum_axes. See the function documentation for more details. - sum_
axis Deprecated - Macro generated for the function
crate::ops::sum_axis. See the function documentation for more details. - svd
Deprecated - Macro generated for the function
crate::linalg::svd. See the function documentation for more details. - swap_
axes Deprecated - Macro generated for the function
crate::ops::swap_axes. See the function documentation for more details. - take
Deprecated - Macro generated for the function
crate::ops::indexing::take. See the function documentation for more details. - take_
along_ axis Deprecated - Macro generated for the function
crate::ops::indexing::take_along_axis. See the function documentation for more details. - take_
axis Deprecated - Macro generated for the function
crate::ops::indexing::take_axis. See the function documentation for more details. - tan
Deprecated - Macro generated for the function
crate::ops::tan. See the function documentation for more details. - tanh
Deprecated - Macro generated for the function
crate::ops::tanh. See the function documentation for more details. - tensordot_
axes Deprecated - Macro generated for the function
crate::ops::tensordot_axes. See the function documentation for more details. - tensordot_
axis Deprecated - Macro generated for the function
crate::ops::tensordot_axis. See the function documentation for more details. - tile
Deprecated - Macro generated for the function
crate::ops::tile. See the function documentation for more details. - to_fp8
Deprecated - Macro generated for the function
crate::ops::to_fp8. See the function documentation for more details. - topk
Deprecated - Macro generated for the function
crate::ops::indexing::topk. See the function documentation for more details. - topk_
axis Deprecated - Macro generated for the function
crate::ops::indexing::topk_axis. See the function documentation for more details. - transpose
Deprecated - Macro generated for the function
crate::ops::transpose. See the function documentation for more details. - transpose_
axes Deprecated - Macro generated for the function
crate::ops::transpose_axes. See the function documentation for more details. - tri
Deprecated - Macro generated for the function
crate::ops::tri. See the function documentation for more details. - tri_inv
Deprecated - Macro generated for the function
crate::linalg::tri_inv. See the function documentation for more details. - tril
Deprecated - Macro generated for the function
crate::ops::tril. See the function documentation for more details. - triu
Deprecated - Macro generated for the function
crate::ops::triu. See the function documentation for more details. - truncated_
normal Deprecated - Macro generated for the function
crate::random::truncated_normal. See the function documentation for more details. - unflatten
Deprecated - Macro generated for the function
crate::ops::unflatten. See the function documentation for more details. - uniform
Deprecated - Macro generated for the function
crate::random::uniform. See the function documentation for more details. - var
Deprecated - Macro generated for the function
crate::ops::var. See the function documentation for more details. - var_
axes Deprecated - Macro generated for the function
crate::ops::var_axes. See the function documentation for more details. - var_
axis Deprecated - Macro generated for the function
crate::ops::var_axis. See the function documentation for more details. - which
Deprecated - Macro generated for the function
crate::ops::which. See the function documentation for more details. - zeros
Deprecated - Macro generated for the function
crate::ops::zeros. See the function documentation for more details. - zeros_
dtype Deprecated - Macro generated for the function
crate::ops::zeros_dtype. See the function documentation for more details. - zeros_
like Deprecated - Macro generated for the function
crate::ops::zeros_like. See the function documentation for more details.
Structs§
- Array
- An n-dimensional array.
- Device
- Representation of a Device in MLX.
- Dtype
Iter - An iterator over the variants of Dtype
- Stream
- A stream of evaluation attached to a particular device.
- Stream
OrDevice - Parameter type for all MLX operations.
Enums§
- Axes
- Axis selection for operations that accept all, one, or several axes.
- Device
Type - Type of device.
- Dtype
- Array element type
Traits§
- Array
Element - A marker trait for array elements.
- From
Nested - A helper trait to construct
Arrayfrom nested arrays or slices. - From
Scalar - A helper trait to construct
Arrayfrom scalar values.
Functions§
- stop_
gradient - Stop gradients from being computed.
- stop_
gradient_ device - Stop gradients from being computed.
- task_
local_ default_ stream Deprecated - Gets the thread-local scoped default stream.
- thread_
local_ default_ stream - Gets the thread-local scoped default stream.
- with_
device - Uses the default stream on
devicefor operations constructed duringf. - with_
new_ default_ stream Deprecated - Uses a given default stream for the duration of
f. - with_
stream - Uses
streamfor operations constructed duringf.
Type Aliases§
- complex64
- Type alias for
num_complex::Complex<f32>.