pub enum SteKind {
Identity,
ClippedIdentity,
Tanh,
HardTanh,
}Expand description
Straight-through estimator variants for Op::FakeQuantize’s
backward. The forward is the same regardless: discrete
clamp(round(x/s)) * s. The choice here affects only the
gradient w.r.t. x during training.
-
Identity—dx = upstream. The original STE; treats the round as identity in the backward direction. Simplest, fine for moderate bit widths (i4 / i8). -
ClippedIdentity—dx = upstream * (|x| ≤ q_max·s). Zero the gradient when the input was outside the quantization range (i.e. the clamp activated). Stops the optimizer from pushing weights further into saturation. -
Tanh—dx = upstream * (1 - tanh²(x/s)). Smooth surrogate for the round step. Slowly attenuates the gradient as|x|approachesq_max·s. Often best on tight bit widths (i2). -
HardTanh—dx = upstream * (1 - |x/(q_max·s)|).max(0). Piecewise-linear cousin ofTanh; cheaper to compute and nearly as effective.
Variants§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for SteKind
impl<'de> Deserialize<'de> for SteKind
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<SteKind, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<SteKind, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for SteKind
impl Serialize for SteKind
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for SteKind
impl Eq for SteKind
impl StructuralPartialEq for SteKind
Auto Trait Implementations§
impl Freeze for SteKind
impl RefUnwindSafe for SteKind
impl Send for SteKind
impl Sync for SteKind
impl Unpin for SteKind
impl UnsafeUnpin for SteKind
impl UnwindSafe for SteKind
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
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§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 more