pub struct QatOptimizer { /* private fields */ }Expand description
QAT optimizer wrapper maintaining full-precision master weights.
The optimizer owns the Adam moment state and a cached fake-quantized view
of the master weights, but the FP32 master itself is owned by the caller and
passed into Self::step. Each step updates the master in place and
re-derives the quantized view from it.
Implementations§
Source§impl QatOptimizer
impl QatOptimizer
Sourcepub fn new(
master: &Array1<f64>,
config: QatConfig,
rng: &mut impl Rng,
) -> Result<Self, GpuOptimError>
pub fn new( master: &Array1<f64>, config: QatConfig, rng: &mut impl Rng, ) -> Result<Self, GpuOptimError>
Create an optimizer for the given FP32 master weights.
The initial quantized view is derived immediately from master.
§Errors
Returns GpuOptimError::InvalidState for empty master weights and
propagates any calibration error from the initial quantization.
Sourcepub fn quantized_weights(&self) -> &Array1<f64>
pub fn quantized_weights(&self) -> &Array1<f64>
The current fake-quantized view of the master weights (what the forward pass uses).
Sourcepub fn quant_params(&self) -> Option<&QuantParams>
pub fn quant_params(&self) -> Option<&QuantParams>
The integer quantization parameters currently in effect, if the target is
integer (always None for fp8 targets).
Sourcepub fn step_count(&self) -> u64
pub fn step_count(&self) -> u64
Number of Self::step calls performed so far.
Sourcepub fn step(
&mut self,
master: &mut Array1<f64>,
grad: &Array1<f64>,
rng: &mut impl Rng,
) -> Result<(), GpuOptimError>
pub fn step( &mut self, master: &mut Array1<f64>, grad: &Array1<f64>, rng: &mut impl Rng, ) -> Result<(), GpuOptimError>
Perform one optimizer step: an Adam/AdamW update of the FP32 master
followed by re-derivation of the quantized view.
The master weights stay in full precision; only the cached quantized
view (see Self::quantized_weights) is rounded onto the grid.
§Errors
Returns GpuOptimError::DimensionMismatch if master and grad (or the
optimizer’s internal state) disagree on length, and propagates any
re-calibration error.
Trait Implementations§
Source§impl Clone for QatOptimizer
impl Clone for QatOptimizer
Source§fn clone(&self) -> QatOptimizer
fn clone(&self) -> QatOptimizer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for QatOptimizer
impl RefUnwindSafe for QatOptimizer
impl Send for QatOptimizer
impl Sync for QatOptimizer
impl Unpin for QatOptimizer
impl UnsafeUnpin for QatOptimizer
impl UnwindSafe for QatOptimizer
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<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