pub enum HardwareOptimizerKind {
Sgd,
Lion,
Adam,
Lamb,
}Expand description
Optimizer families the hardware analysis can recommend.
The distinguishing property is how much per-parameter optimizer state each family needs, because on the memory-constrained platforms this module models that state — not the parameters themselves — is what decides whether a model fits.
Variants§
Sgd
Momentum SGD: one auxiliary buffer per parameter, and none at all when momentum is zero. Recommended when optimizer state has to be paid for over a slow link (CPU offloading) or under a very small power budget.
Lion
Lion: a single momentum buffer and a sign-based update (Chen et al., “Symbolic Discovery of Optimization Algorithms”, arXiv:2302.06675). Half of Adam’s optimizer state, and the sign update is insensitive to gradient scale, which suits the quantized/low-precision arithmetic edge devices use.
Adam
Adam: first and second moments, two buffers per parameter. The default when optimizer-state memory is not the binding constraint.
Lamb
LAMB: Adam’s moments plus a layer-wise trust ratio, for the very large batches TPU and distributed configurations produce.
Implementations§
Source§impl HardwareOptimizerKind
impl HardwareOptimizerKind
Sourcepub fn state_buffers_per_parameter(self) -> usize
pub fn state_buffers_per_parameter(self) -> usize
Number of per-parameter auxiliary buffers this family keeps.
Multiply by the parameter count and the element size to get the optimizer-state footprint that has to fit alongside the model.
Sourcepub fn recommend_for<A: Float>(
platform: &HardwarePlatform,
config: &HardwareOptimizationConfig<A>,
) -> Self
pub fn recommend_for<A: Float>( platform: &HardwarePlatform, config: &HardwareOptimizationConfig<A>, ) -> Self
Recommend an optimizer family for a platform and the configuration the hardware analysis produced for it.
The rules are ordered from the hardest constraint to the softest:
- Offloading optimizer state to CPU memory, or a sub-
LOW_POWER_BUDGET_WATTSpower budget, makes every extra per-parameter buffer expensive: use SGD. - Any other edge device: use Lion, which halves Adam’s state and whose sign update tolerates quantized arithmetic.
- Batches of
LARGE_BATCH_THRESHOLDor more (TPU, distributed): use LAMB. - Otherwise: Adam.
Trait Implementations§
Source§impl Clone for HardwareOptimizerKind
impl Clone for HardwareOptimizerKind
Source§fn clone(&self) -> HardwareOptimizerKind
fn clone(&self) -> HardwareOptimizerKind
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for HardwareOptimizerKind
Source§impl Debug for HardwareOptimizerKind
impl Debug for HardwareOptimizerKind
impl Eq for HardwareOptimizerKind
Source§impl Hash for HardwareOptimizerKind
impl Hash for HardwareOptimizerKind
Source§impl PartialEq for HardwareOptimizerKind
impl PartialEq for HardwareOptimizerKind
impl StructuralPartialEq for HardwareOptimizerKind
Auto Trait Implementations§
impl Freeze for HardwareOptimizerKind
impl RefUnwindSafe for HardwareOptimizerKind
impl Send for HardwareOptimizerKind
impl Sync for HardwareOptimizerKind
impl Unpin for HardwareOptimizerKind
impl UnsafeUnpin for HardwareOptimizerKind
impl UnwindSafe for HardwareOptimizerKind
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.