Skip to main content

PaddedCausalBatch

Struct PaddedCausalBatch 

Source
pub struct PaddedCausalBatch<B: Backend> {
    pub input_ids: Tensor<B, 2, Int>,
    pub labels: Tensor<B, 2, Int>,
    pub attention_mask: Tensor<B, 2, Bool>,
    pub position_ids: Tensor<B, 2, Int>,
    pub lengths: Vec<usize>,
    pub supervised_tokens: usize,
    pub ignore_index: i64,
    pub target_alignment: CausalTargetAlignment,
}
Available on crate feature std only.
Expand description

Rectangular actual documents with explicitly masked batch-padding cells.

Fields§

§input_ids: Tensor<B, 2, Int>

Token IDs shaped [actual examples, maximum actual sequence length].

§labels: Tensor<B, 2, Int>

Same shape as input_ids; all padding cells contain ignore_index.

§attention_mask: Tensor<B, 2, Bool>

True exactly at real source tokens, never at padding cells.

§position_ids: Tensor<B, 2, Int>

Real positions reset per document; masked padding positions are zero.

§lengths: Vec<usize>

Original encoded lengths in actual batch order.

§supervised_tokens: usize

Actual nonignored supervised targets under the selected alignment.

§ignore_index: i64

Actual label sentinel used during collation.

§target_alignment: CausalTargetAlignment

Target alignment recorded for the downstream loss contract.

Implementations§

Source§

impl<B: Backend> PaddedCausalBatch<B>

Source

pub fn examples(&self) -> usize

Actual source example count; no synthetic rows are created.

Source

pub fn to_device(self, device: &B::Device) -> Self

Move the actual tensors while retaining the original length metadata.

Source§

impl<B: Backend> PaddedCausalBatch<B>

Source

pub fn token_inputs(&self) -> PaddedTokenBatch<B>

Label-free input view; cloning tensor handles does not duplicate token values.

Trait Implementations§

Source§

impl<B: Clone + Backend> Clone for PaddedCausalBatch<B>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B: Debug + Backend> Debug for PaddedCausalBatch<B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<B> Freeze for PaddedCausalBatch<B>
where Tensor<B, 2, Int>: Freeze, Tensor<B, 2, Bool>: Freeze,

§

impl<B> RefUnwindSafe for PaddedCausalBatch<B>

§

impl<B> Send for PaddedCausalBatch<B>
where Tensor<B, 2, Int>: Send, Tensor<B, 2, Bool>: Send,

§

impl<B> Sync for PaddedCausalBatch<B>
where Tensor<B, 2, Int>: Sync, Tensor<B, 2, Bool>: Sync,

§

impl<B> Unpin for PaddedCausalBatch<B>
where Tensor<B, 2, Int>: Unpin, Tensor<B, 2, Bool>: Unpin,

§

impl<B> UnsafeUnpin for PaddedCausalBatch<B>
where Tensor<B, 2, Int>: UnsafeUnpin, Tensor<B, 2, Bool>: UnsafeUnpin,

§

impl<B> UnwindSafe for PaddedCausalBatch<B>
where Tensor<B, 2, Int>: UnwindSafe, Tensor<B, 2, Bool>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.