Skip to main content

ruda_optim/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![warn(missing_docs)]
3#![cfg_attr(docsrs, feature(doc_cfg))]
4#![recursion_limit = "256"]
5
6//! Ruda optimizer updates, gradient state, clipping and learning-rate schedules.
7
8#[macro_use]
9extern crate derive_new;
10
11extern crate alloc;
12
13/// Optimizer module.
14mod optim;
15pub use optim::*;
16
17/// Opt-in single-kernel AdamW/AMSGrad and explicit numerical reference.
18#[cfg(feature = "fused-adamw")]
19pub mod fused_adamw;
20
21/// Gradient clipping module.
22pub mod grad_clipping;
23
24/// Learning rate scheduler module.
25#[cfg(feature = "std")]
26pub mod lr_scheduler;
27
28/// Combined model, optimizer, scheduler and accumulated-gradient records.
29#[cfg(feature = "std")]
30pub mod training;
31
32/// Type alias for the learning rate.
33///
34/// LearningRate also implements [learning rate scheduler](crate::lr_scheduler::LrScheduler) so it
35/// can be used for constant learning rate.
36pub type LearningRate = f64; // We could potentially change the type.
37
38/// Backend for test cases
39#[cfg(all(
40    test,
41    not(feature = "test-tch"),
42    not(feature = "test-wgpu"),
43    not(feature = "test-cuda"),
44    not(feature = "test-rocm")
45))]
46pub type TestBackend = ruda_tensor_host::Host;
47
48#[cfg(all(test, feature = "test-tch"))]
49/// Backend for test cases
50pub type TestBackend = ruda_tensor_tch::LibTorch<f32>;
51
52#[cfg(all(test, feature = "test-wgpu"))]
53/// Backend for test cases
54pub type TestBackend = ruda_tensor_wgpu::Wgpu;
55
56#[cfg(all(test, feature = "test-cuda"))]
57/// Backend for test cases
58pub type TestBackend = ruda_tensor_device::cuda::Cuda;
59
60#[cfg(all(test, feature = "test-rocm"))]
61/// Backend for test cases
62pub type TestBackend = ruda_tensor_rocm::Rocm;
63
64/// Backend for autodiff test cases
65#[cfg(test)]
66pub type TestAutodiffBackend = ruda_autodiff::Autodiff<TestBackend>;
67
68#[cfg(all(test, feature = "test-memory-checks"))]
69mod tests {
70    ruda_fusion::memory_checks!();
71}