pub struct CpuEncoder { /* private fields */ }Expand description
The CPU encoder: loads a checkpoint directory (config.json + model.safetensors) and
embeds ragged token batches. Deterministic per input (fixed reduction orders), so it serves
as the GPU kernels’ tolerance-gated oracle.
Implementations§
Source§impl CpuEncoder
impl CpuEncoder
Sourcepub fn load(dir: &Path) -> Result<Self>
pub fn load(dir: &Path) -> Result<Self>
Load from a checkpoint dir. Refuses (loudly) architectures whose CPU arm hasn’t landed — “recognized” and “supported” stay honest.
Sourcepub fn load_siglip_text(dir: &Path) -> Result<Self>
pub fn load_siglip_text(dir: &Path) -> Result<Self>
Load the SigLIP TEXT tower from a joint checkpoint.
Sourcepub fn load_siglip_vision(dir: &Path) -> Result<Self>
pub fn load_siglip_vision(dir: &Path) -> Result<Self>
Load the SigLIP VISION tower from a joint checkpoint.
Sourcepub fn encode_image(
&self,
pixels: &[f32],
image_size: usize,
patch_size: usize,
) -> Result<Vec<f32>>
pub fn encode_image( &self, pixels: &[f32], image_size: usize, patch_size: usize, ) -> Result<Vec<f32>>
Embed ONE image’s normalized pixels ([3 · image² ] CHW, already resized/rescaled/
normalized): im2row patch embedding + positions → transformer → post-LN → MAP head.
Vision tower only.
Sourcepub fn config(&self) -> &EncoderConfig
pub fn config(&self) -> &EncoderConfig
The parsed configuration.
Sourcepub fn encode(&self, batch: &EncBatch) -> Result<EmbedOut>
pub fn encode(&self, batch: &EncBatch) -> Result<EmbedOut>
Embed a ragged batch. Sequence length (plus any learned-position offset) must fit
max_pos; empty sequences are refused (a mean over zero rows has no value).
The raw pre-pooling [total_tokens, hidden] hidden-state stream (row-major, ragged-
concatenated) — the encoder’s last_hidden_state. Every pooling mode is a reduction of
this: Cls L2-normalizes each sequence’s FIRST row, LastToken its last, Mean the
row-average. Exposed so parity gates and callers can inspect per-token states directly.
Runs inside the encoder-owned rayon pool.
Auto Trait Implementations§
impl !Freeze for CpuEncoder
impl !RefUnwindSafe for CpuEncoder
impl !UnwindSafe for CpuEncoder
impl Send for CpuEncoder
impl Sync for CpuEncoder
impl Unpin for CpuEncoder
impl UnsafeUnpin for CpuEncoder
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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