pub struct DynamicBatchConfig {
pub max_context_length: usize,
pub avg_sentence_length: usize,
pub min_contexts: usize,
pub max_contexts: usize,
pub same_document: bool,
pub window_overlap: usize,
}Expand description
Dynamic batching configuration for cross-context training.
From xCoRe (Section 3.3): “At each step, we first sample the number of training contexts n in the range (1, ⌊w/s⌋), then construct a training batch by sampling n continuous contexts from d_i, with length equal to min(w, |d_i|)/n.”
This allows models to learn with both:
- Many small contexts (for cross-context learning)
- Few large contexts (for within-context quality)
Fields§
§max_context_length: usizeMaximum context length (tokens)
avg_sentence_length: usizeAverage sentence length (for computing max contexts)
min_contexts: usizeMinimum number of contexts per batch
max_contexts: usizeMaximum number of contexts per batch
same_document: boolWhether to sample contexts from same document (long-doc) or different docs (cross-doc)
window_overlap: usizeOverlap tokens between adjacent windows (for long-doc mode)
Implementations§
Source§impl DynamicBatchConfig
impl DynamicBatchConfig
Sourcepub fn cross_document() -> Self
pub fn cross_document() -> Self
Create config for cross-document training.
Sourcepub fn long_document() -> Self
pub fn long_document() -> Self
Create config for long-document training.
Sourcepub fn sample_num_contexts(&self, rng_seed: u64) -> usize
pub fn sample_num_contexts(&self, rng_seed: u64) -> usize
Compute the number of contexts to sample for this training step.
Uses uniform sampling in range (min_contexts, max_contexts).
Sourcepub fn context_length(&self, num_contexts: usize, doc_length: usize) -> usize
pub fn context_length(&self, num_contexts: usize, doc_length: usize) -> usize
Compute context length given number of contexts.
From xCoRe: “length equal to min(w, |d_i|)/n”
Trait Implementations§
Source§impl Clone for DynamicBatchConfig
impl Clone for DynamicBatchConfig
Source§fn clone(&self) -> DynamicBatchConfig
fn clone(&self) -> DynamicBatchConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DynamicBatchConfig
impl Debug for DynamicBatchConfig
Source§impl Default for DynamicBatchConfig
impl Default for DynamicBatchConfig
Source§impl<'de> Deserialize<'de> for DynamicBatchConfig
impl<'de> Deserialize<'de> for DynamicBatchConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for DynamicBatchConfig
impl RefUnwindSafe for DynamicBatchConfig
impl Send for DynamicBatchConfig
impl Sync for DynamicBatchConfig
impl Unpin for DynamicBatchConfig
impl UnsafeUnpin for DynamicBatchConfig
impl UnwindSafe for DynamicBatchConfig
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,
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