pub struct AsyncSGBT<L: Loss = SquaredLoss> { /* private fields */ }Expand description
Async wrapper around SGBT for tokio-native streaming training.
AsyncSGBT owns the shared model and the receiving end of a bounded
sample channel. Call run to start the training loop,
which consumes samples from the channel and trains incrementally.
Generic over L: Loss so the training loop benefits from monomorphized
gradient/hessian dispatch (no vtable overhead).
Prediction handles (Predictor) and sender handles (SampleSender)
can be obtained before starting the loop and used concurrently from
other tasks.
§Shutdown
When run is called, it drops the internal sender copy
so that the channel closes as soon as all external senders are dropped.
The loop then drains any remaining buffered samples and returns Ok(()).
Implementations§
Source§impl AsyncSGBT<SquaredLoss>
impl AsyncSGBT<SquaredLoss>
Sourcepub fn new(config: SGBTConfig) -> Self
pub fn new(config: SGBTConfig) -> Self
Create a new async SGBT runner with the default channel capacity (1024).
Uses squared loss (regression). For other loss functions, use
with_loss or with_loss_and_capacity.
Sourcepub fn with_capacity(config: SGBTConfig, capacity: usize) -> Self
pub fn with_capacity(config: SGBTConfig, capacity: usize) -> Self
Create a new async SGBT runner with a custom channel capacity.
Uses squared loss (regression).
Source§impl<L: Loss> AsyncSGBT<L>
impl<L: Loss> AsyncSGBT<L>
Sourcepub fn with_loss(config: SGBTConfig, loss: L) -> Self
pub fn with_loss(config: SGBTConfig, loss: L) -> Self
Create a new async SGBT runner with a specific loss function.
use irithyll::SGBTConfig;
use irithyll::stream::AsyncSGBT;
use irithyll::loss::logistic::LogisticLoss;
let config = SGBTConfig::builder().n_steps(10).build().unwrap();
let runner = AsyncSGBT::with_loss(config, LogisticLoss);Sourcepub fn with_loss_and_capacity(
config: SGBTConfig,
loss: L,
capacity: usize,
) -> Self
pub fn with_loss_and_capacity( config: SGBTConfig, loss: L, capacity: usize, ) -> Self
Create a new async SGBT runner with a specific loss and channel capacity.
Sourcepub fn sender(&self) -> SampleSender
pub fn sender(&self) -> SampleSender
Obtain a clonable sender handle for feeding samples into the channel.
Multiple senders can be created (via Clone) and used from different
async tasks. The training loop runs until all external senders are
dropped.
§Panics
Panics if called after run has already started, since
the internal sender is consumed at that point.
Sourcepub fn predictor(&self) -> Predictor<L>
pub fn predictor(&self) -> Predictor<L>
Obtain a concurrent prediction handle to the shared model.
The predictor can be cloned and used from any thread or task while the training loop is running.
Sourcepub async fn run(&mut self) -> Result<()>
pub async fn run(&mut self) -> Result<()>
Run the main training loop.
Receives samples from the bounded channel and trains the model incrementally. For each sample:
- Acquire write lock on the shared
SGBT<L>. - Call
train_one(&sample). - Release the lock.
Before entering the loop, the internal sender is dropped so that the channel closes cleanly when all external senders are dropped.
Returns Ok(()) when the channel closes (all senders have been
dropped and all buffered samples have been consumed).
§Logging
Emits a tracing::debug! message every 1000 samples with the
current sample count.
§Panics
Panics if called more than once (the receiver is consumed on first call).
Sourcepub async fn run_with_callback<F>(&mut self, callback: F) -> Result<()>
pub async fn run_with_callback<F>(&mut self, callback: F) -> Result<()>
Run the training loop with a callback invoked after each sample.
Behaves identically to run, but calls callback
with the current n_samples_seen() count after training each sample.
Useful for progress bars, metrics collection, or adaptive control.
The callback runs synchronously within the training task – keep it fast to avoid blocking the loop.
§Panics
Panics if called more than once (the receiver is consumed on first call).
Auto Trait Implementations§
impl<L> Freeze for AsyncSGBT<L>
impl<L = SquaredLoss> !RefUnwindSafe for AsyncSGBT<L>
impl<L> Send for AsyncSGBT<L>
impl<L> Sync for AsyncSGBT<L>
impl<L> Unpin for AsyncSGBT<L>
impl<L> UnsafeUnpin for AsyncSGBT<L>
impl<L = SquaredLoss> !UnwindSafe for AsyncSGBT<L>
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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