pub struct PipelineParallel<B: Backend> { /* private fields */ }Expand description
Pipeline-parallel executor using GPipe-style micro-batching.
Splits a model into sequential stages and processes micro-batches through the pipeline. This increases throughput by overlapping computation across stages.
§Example
ⓘ
let stage0 = PipelineStage::new(0)
.add_layer(Box::new(Linear::new(784, 256, true, DType::F32, &dev)?));
let stage1 = PipelineStage::new(1)
.add_layer(Box::new(Linear::new(256, 10, true, DType::F32, &dev)?));
let pipeline = PipelineParallel::new(vec![stage0, stage1], 4);
let output = pipeline.forward(&input)?;Implementations§
Source§impl<B: Backend> PipelineParallel<B>
impl<B: Backend> PipelineParallel<B>
Sourcepub fn new(stages: Vec<PipelineStage<B>>, num_micro_batches: usize) -> Self
pub fn new(stages: Vec<PipelineStage<B>>, num_micro_batches: usize) -> Self
Create a pipeline with the given stages and micro-batch count.
Sourcepub fn forward(&self, x: &Tensor<B>) -> Result<Tensor<B>>
pub fn forward(&self, x: &Tensor<B>) -> Result<Tensor<B>>
Full forward pass through all stages.
Splits the input into num_micro_batches micro-batches, runs each
through the pipeline sequentially, and concatenates the results.
In a multi-device setting, stages would run on different devices with inter-device transfers between stages.
Sourcepub fn parameters(&self) -> Vec<Tensor<B>>
pub fn parameters(&self) -> Vec<Tensor<B>>
Collect all parameters from all stages (for optimizer).
Sourcepub fn num_stages(&self) -> usize
pub fn num_stages(&self) -> usize
Number of stages.
Sourcepub fn stage(&self, idx: usize) -> Option<&PipelineStage<B>>
pub fn stage(&self, idx: usize) -> Option<&PipelineStage<B>>
Get a reference to a specific stage.
Auto Trait Implementations§
impl<B> Freeze for PipelineParallel<B>
impl<B> !RefUnwindSafe for PipelineParallel<B>
impl<B> !Send for PipelineParallel<B>
impl<B> !Sync for PipelineParallel<B>
impl<B> Unpin for PipelineParallel<B>
impl<B> !UnwindSafe for PipelineParallel<B>
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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