Skip to main content

Options

Struct Options 

Source
#[non_exhaustive]
pub struct Options { pub cache_capacity: usize, pub shapeless: bool, }
Expand description

Options of compile, compile_mut and compile_flat_with: Options::default().cache_capacity(8).

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§cache_capacity: usize

The most traced signatures a compiled function keeps (least recently used first out); 0 never caches. Default 64.

§shapeless: bool

Trace once per input structure, dtypes and ranks, and replay for any shapes (Options::shapeless). Default off.

Implementations§

Source§

impl Options

Source

pub fn cache_capacity(self, n: usize) -> Self

Sets the cache capacity.

Source

pub fn shapeless(self, on: bool) -> Self

Shapeless compilation (MLX’s shapeless=True): the function is traced once per input structure, dtypes and ranks, and replayed for any shapes of those ranks. Each replay infers the shapes again, and element-wise operations broadcast their operands as the uncompiled ones do, so the results are the shaped compile’s bit for bit.

use nuvec_compile::Options;
use nuvec_core::{Array, DType, ops};

let swiglu = Options::default()
    .shapeless(true)
    .compile(|(g, u): &(Array, Array)| g.multiply(g.sigmoid()).multiply(u));
for rows in [7, 512, 2048] {
    let g = ops::ones([rows, 64], DType::F32);
    swiglu(&(g.clone(), g))?.eval()?; // traced once, for every row count
}
  • Operations whose parameters hold traced sizes fail the trace with an error naming them: reshapes, slices and slice updates, broadcasts other than an element-wise operation’s own, random draws, custom Metal kernels and attention (whose kernel choice depends on the lengths). Compile those without the option.
  • As in MLX, Rust code that reads a shape while tracing (x.shape()[0], a branch on a size) bakes the first call’s value in, and constants built from a traced shape keep it: a replay on another shape then fails in the operation that uses them.
  • compile_mut keys its state exactly and its inputs shapelessly.
Source

pub fn compile<'f, I, O, F, R>(self, f: F) -> impl Fn(&I) -> Result<O> + 'f
where I: Tree, O: Tree, F: Fn(&I) -> R + 'f, R: IntoResult<Ok = O>,

compile with these options.

Source

pub fn compile_mut<'f, S, I, O, F, R>( self, f: F, ) -> impl Fn(&mut S, &I) -> Result<O> + 'f
where S: Tree, I: Tree, O: Tree, F: Fn(&mut S, &I) -> R + 'f, R: IntoResult<Ok = O>,

compile_mut with these options.

Trait Implementations§

Source§

impl Clone for Options

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Options

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Options

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.