pub struct LMBatch {
pub input_ids: Vec<u32>,
pub target_ids: Vec<u32>,
pub batch_size: usize,
pub seq_len: usize,
}Expand description
A batch of tokenized sequences for language model training
Fields§
§input_ids: Vec<u32>Input token IDs (batch_size x seq_len flattened)
target_ids: Vec<u32>Target token IDs (batch_size x seq_len flattened, shifted by 1)
batch_size: usizeBatch size
seq_len: usizeSequence length
Implementations§
Source§impl LMBatch
impl LMBatch
Sourcepub fn from_sequences(sequences: &[Vec<u32>], pad_id: u32, eos_id: u32) -> Self
pub fn from_sequences(sequences: &[Vec<u32>], pad_id: u32, eos_id: u32) -> Self
Create a new LM batch from token sequences
For causal LM, targets are inputs shifted by 1: input: [BOS, A, B, C, D] target: [A, B, C, D, EOS]
Sourcepub fn single(input_ids: Vec<u32>, target_ids: Vec<u32>) -> Self
pub fn single(input_ids: Vec<u32>, target_ids: Vec<u32>) -> Self
Create a batch from a single sequence (for testing)
Sourcepub fn get_input(&self, batch_idx: usize) -> Option<&[u32]>
pub fn get_input(&self, batch_idx: usize) -> Option<&[u32]>
Get input IDs for a specific batch item
Sourcepub fn get_target(&self, batch_idx: usize) -> Option<&[u32]>
pub fn get_target(&self, batch_idx: usize) -> Option<&[u32]>
Get target IDs for a specific batch item
Sourcepub fn num_tokens(&self) -> usize
pub fn num_tokens(&self) -> usize
Total number of tokens in batch
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LMBatch
impl RefUnwindSafe for LMBatch
impl Send for LMBatch
impl Sync for LMBatch
impl Unpin for LMBatch
impl UnwindSafe for LMBatch
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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