use crate::{
TokenDecoder,
TokenType,
UnifiedTokenVocab,
alloc::sync::Arc,
decoders::SlabIndexDecoder,
};
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct TokenDecoderOptions {
pub parallel: bool,
}
impl TokenDecoderOptions {
pub fn parallel(&self) -> bool {
self.parallel
}
pub fn set_parallel(
&mut self,
parallel: bool,
) {
self.parallel = parallel;
}
pub fn with_parallel(
mut self,
parallel: bool,
) -> Self {
self.set_parallel(parallel);
self
}
pub fn build<T: TokenType>(
&self,
vocab: Arc<UnifiedTokenVocab<T>>,
) -> Arc<dyn TokenDecoder<T>> {
#[allow(unused_mut)]
let mut dec: Arc<dyn TokenDecoder<T>> = Arc::new(SlabIndexDecoder::from_vocab(vocab));
#[cfg(feature = "parallel")]
if self.parallel {
use crate::support::concurrency::rayon::ParallelRayonDecoder;
dec = Arc::new(ParallelRayonDecoder::new(dec));
}
dec
}
}