Skip to main content

NNOptimizer

Struct NNOptimizer 

Source
pub struct NNOptimizer { /* private fields */ }

Implementations§

Source§

impl NNOptimizer

Source

pub const fn as_ptr(&self) -> *mut c_void

Source§

impl NNOptimizer

Source

pub fn learning_rate(&self) -> f32

Source

pub fn set_learning_rate(&self, value: f32)

Source

pub fn gradient_rescale(&self) -> f32

Source

pub fn apply_gradient_clipping(&self) -> bool

Source

pub fn set_apply_gradient_clipping(&self, value: bool)

Source

pub fn gradient_clip_max(&self) -> f32

Source

pub fn gradient_clip_min(&self) -> f32

Source

pub fn regularization_scale(&self) -> f32

Source

pub fn regularization_type(&self) -> usize

Examples found in repository?
examples/07_optimizer_and_state.rs (line 68)
37fn main() {
38    let device = MetalDevice::system_default().expect("no Metal device available");
39    let queue = device.new_command_queue().expect("command queue");
40
41    let command_buffer = queue.new_command_buffer().expect("command buffer");
42    let temporary_a =
43        State::temporary_with_buffer_size(&command_buffer, 32).expect("temporary state a");
44    let temporary_b =
45        State::temporary_with_buffer_size(&command_buffer, 64).expect("temporary state b");
46    let unique_count =
47        state_batch_increment_read_count(&[&temporary_a, &temporary_a, &temporary_b], 1);
48    assert_eq!(unique_count, 2);
49    assert_eq!(
50        temporary_a.resource_type_at_index(0),
51        state_resource_type::BUFFER
52    );
53    command_buffer.commit();
54    command_buffer.wait_until_completed();
55
56    let resource_list = StateResourceList::new().expect("resource list");
57    resource_list.append_buffer(16);
58    let persistent_state =
59        State::new_with_resource_list(&device, &resource_list).expect("persistent state");
60    assert_eq!(persistent_state.resource_count(), 1);
61    assert_eq!(persistent_state.buffer_size_at_index(0), 16);
62
63    let (gradient_buffer, gradient_vector) = vector_with_values(&device, &[0.1, -0.2]);
64    let (values_buffer, values_vector) = vector_with_values(&device, &[1.0, -1.0]);
65    let (result_buffer, result_vector) = vector_with_values(&device, &[0.0, 0.0]);
66    let optimizer = NNOptimizerStochasticGradientDescent::new(&device, 0.5).expect("sgd");
67    let base = optimizer.as_optimizer().expect("optimizer base");
68    assert_eq!(base.regularization_type(), nn_regularization_type::NONE);
69
70    let command_buffer = queue.new_command_buffer().expect("command buffer");
71    optimizer.encode_vector(
72        &command_buffer,
73        &gradient_vector,
74        &values_vector,
75        None,
76        &result_vector,
77    );
78    command_buffer.commit();
79    command_buffer.wait_until_completed();
80
81    let _ = gradient_buffer;
82    let _ = values_buffer;
83    let output = read_f32_values(&result_buffer, 2);
84    println!("{output:?}");
85}

Trait Implementations§

Source§

impl Drop for NNOptimizer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for NNOptimizer

Source§

impl Sync for NNOptimizer

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> 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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.