pub struct Compressor {
pub model: Arc<Model>,
pub state: State,
pub scratch: ScratchBuffers,
pub pdf_buffer: Vec<f64>,
/* private fields */
}Expand description
Stateful compressor built around a Mamba model.
Fields§
§model: Arc<Model>Model weights.
state: StateRecurrent state.
scratch: ScratchBuffersReusable scratch.
pdf_buffer: Vec<f64>Reusable PDF buffer.
Implementations§
Source§impl Compressor
impl Compressor
Sourcepub fn new<P: AsRef<Path>>(model_path: P) -> Result<Self>
pub fn new<P: AsRef<Path>>(model_path: P) -> Result<Self>
Create compressor by loading model path.
Sourcepub fn load_model<P: AsRef<Path>>(model_path: P) -> Result<Arc<Model>>
pub fn load_model<P: AsRef<Path>>(model_path: P) -> Result<Arc<Model>>
Load model from path and wrap in Arc.
Sourcepub fn new_from_model(model: Arc<Model>) -> Self
pub fn new_from_model(model: Arc<Model>) -> Self
Create compressor from preloaded model.
Sourcepub fn new_from_method(method: &str) -> Result<Self>
pub fn new_from_method(method: &str) -> Result<Self>
Create compressor from method string.
Sourcepub fn begin_online_policy_stream(
&mut self,
total_symbols: Option<u64>,
) -> Result<()>
pub fn begin_online_policy_stream( &mut self, total_symbols: Option<u64>, ) -> Result<()>
Begin a policy stream with optional total symbol count.
Sourcepub fn finish_online_policy_stream(&mut self) -> Result<()>
pub fn finish_online_policy_stream(&mut self) -> Result<()>
Flush any pending TBPTT segment while preserving current predictive state.
Sourcepub fn restart_online_policy_stream(
&mut self,
total_symbols: Option<u64>,
) -> Result<()>
pub fn restart_online_policy_stream( &mut self, total_symbols: Option<u64>, ) -> Result<()>
Reset hidden state and TBPTT bookkeeping for a fresh stream.
Sourcepub fn reset_and_prime(&mut self)
pub fn reset_and_prime(&mut self)
Reset and compute initial distribution.
Sourcepub fn snapshot_runtime(&self) -> RuntimeSnapshot
pub fn snapshot_runtime(&self) -> RuntimeSnapshot
Capture runtime snapshot.
Sourcepub fn restore_runtime(&mut self, snapshot: &RuntimeSnapshot)
pub fn restore_runtime(&mut self, snapshot: &RuntimeSnapshot)
Restore runtime snapshot.
Sourcepub fn absorb_chain(&mut self, parts: &[&[u8]]) -> Result<()>
pub fn absorb_chain(&mut self, parts: &[&[u8]]) -> Result<()>
Condition the model on a chain of prefixes.
Sourcepub fn cross_entropy_from_current(&mut self, data: &[u8]) -> Result<f64>
pub fn cross_entropy_from_current(&mut self, data: &[u8]) -> Result<f64>
Cross entropy from current runtime state.
Sourcepub fn cross_entropy_frozen_plugin_chain(
&mut self,
fit_parts: &[&[u8]],
data: &[u8],
) -> Result<f64>
pub fn cross_entropy_frozen_plugin_chain( &mut self, fit_parts: &[&[u8]], data: &[u8], ) -> Result<f64>
Fit on fit_parts, then reset stream state and score data without further adaptation.
Sourcepub fn can_adapt_online(&self) -> bool
pub fn can_adapt_online(&self) -> bool
Returns true when the current online configuration can actually adapt parameters.
Sourcepub fn tokens_processed(&self) -> u64
pub fn tokens_processed(&self) -> u64
Tokens processed by online updater.
Sourcepub fn online_method_string(&self) -> Option<&str>
pub fn online_method_string(&self) -> Option<&str>
Canonical online method string.
Sourcepub fn vocab_size(&self) -> usize
pub fn vocab_size(&self) -> usize
Vocabulary size.
Sourcepub fn online_apply_logits_bias(&self, logits: &[f32], pdf_out: &mut [f64])
pub fn online_apply_logits_bias(&self, logits: &[f32], pdf_out: &mut [f64])
Convert logits to PDF with online bias if active.
Sourcepub fn logits_to_pdf(logits: &[f32], bias: Option<&[f32]>, pdf_out: &mut [f64])
pub fn logits_to_pdf(logits: &[f32], bias: Option<&[f32]>, pdf_out: &mut [f64])
Convert logits + optional bias into stable normalized PDF.
Sourcepub fn forward_to_pdf(&mut self, token: u32, pdf_out: &mut [f64])
pub fn forward_to_pdf(&mut self, token: u32, pdf_out: &mut [f64])
Forward one token and emit the resulting (optionally biased) PDF.
Sourcepub fn online_bias_snapshot(&self) -> Option<Vec<f32>>
pub fn online_bias_snapshot(&self) -> Option<Vec<f32>>
Snapshot online bias only.
Sourcepub fn online_bias_slice(&self) -> Option<&[f32]>
pub fn online_bias_slice(&self) -> Option<&[f32]>
Borrow online output bias vector when online mode is active.
Sourcepub fn online_update_from_pdf(&mut self, symbol: u8, pdf: &[f64]) -> Result<()>
pub fn online_update_from_pdf(&mut self, symbol: u8, pdf: &[f64]) -> Result<()>
Apply one online update using external PDF.
Sourcepub fn observe_symbol_from_pdf(&mut self, symbol: u8, pdf: &[f64]) -> Result<()>
pub fn observe_symbol_from_pdf(&mut self, symbol: u8, pdf: &[f64]) -> Result<()>
Update online state from pdf, then advance model state with symbol.
Sourcepub fn observe_symbol_from_current_pdf(&mut self, symbol: u8) -> Result<()>
pub fn observe_symbol_from_current_pdf(&mut self, symbol: u8) -> Result<()>
Update online state using current internal PDF, then consume symbol.
Sourcepub fn export_online<P: AsRef<Path>>(&self, model_path: P) -> Result<()>
pub fn export_online<P: AsRef<Path>>(&self, model_path: P) -> Result<()>
Export model and online sidecar.
Sourcepub fn compress_into<W: Write>(
&mut self,
data: &[u8],
coder: CoderType,
w: &mut W,
) -> Result<()>
pub fn compress_into<W: Write>( &mut self, data: &[u8], coder: CoderType, w: &mut W, ) -> Result<()>
Compress into writer.
Sourcepub fn compress_chain_into<W: Write>(
&mut self,
parts: &[&[u8]],
coder: CoderType,
w: &mut W,
) -> Result<()>
pub fn compress_chain_into<W: Write>( &mut self, parts: &[&[u8]], coder: CoderType, w: &mut W, ) -> Result<()>
Compress a chain of byte slices into writer.
Sourcepub fn compress_size(&mut self, data: &[u8], coder: CoderType) -> Result<u64>
pub fn compress_size(&mut self, data: &[u8], coder: CoderType) -> Result<u64>
Return compressed size without output allocation.
Sourcepub fn compress_size_chain(
&mut self,
parts: &[&[u8]],
coder: CoderType,
) -> Result<u64>
pub fn compress_size_chain( &mut self, parts: &[&[u8]], coder: CoderType, ) -> Result<u64>
Return compressed size for chained inputs.
Sourcepub fn compress(&mut self, data: &[u8], coder: CoderType) -> Result<Vec<u8>>
pub fn compress(&mut self, data: &[u8], coder: CoderType) -> Result<Vec<u8>>
Compress to bytes.
Sourcepub fn cross_entropy(&mut self, data: &[u8]) -> Result<f64>
pub fn cross_entropy(&mut self, data: &[u8]) -> Result<f64>
Cross entropy over whole sample.
Sourcepub fn cross_entropy_conditional_chain(
&mut self,
prefix_parts: &[&[u8]],
data: &[u8],
) -> Result<f64>
pub fn cross_entropy_conditional_chain( &mut self, prefix_parts: &[&[u8]], data: &[u8], ) -> Result<f64>
Cross entropy conditioned on prefix chain.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Compressor
impl RefUnwindSafe for Compressor
impl Send for Compressor
impl Sync for Compressor
impl Unpin for Compressor
impl UnwindSafe for Compressor
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,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
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§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.