pub struct ZunaEncoder<B: Backend> {
pub model_cfg: ModelConfig,
pub data_cfg: DataConfig,
/* private fields */
}Expand description
Standalone ZUNA encoder.
Loads only the encoder half of the pretrained weights — useful when you only
need latent embeddings and want to save memory and startup time compared to
loading the full crate::ZunaInference.
§Backend
Compile-time choice (same as the full model):
- CPU (default):
--features ndarray - GPU:
--no-default-features --features wgpu
Fields§
§model_cfg: ModelConfigArchitecture hyperparameters (from config.json).
data_cfg: DataConfigPreprocessing / tokenisation parameters.
Implementations§
Source§impl<B: Backend> ZunaEncoder<B>
impl<B: Backend> ZunaEncoder<B>
Sourcepub fn load(
config_path: &Path,
weights_path: &Path,
device: B::Device,
) -> Result<(Self, f64)>
pub fn load( config_path: &Path, weights_path: &Path, device: B::Device, ) -> Result<(Self, f64)>
Load encoder weights from a HuggingFace config.json and
model.safetensors. Decoder tensors are read from disk but not kept
in memory (the full file is parsed once for key extraction).
Returns (encoder, weight_load_ms).
Sourcepub fn encode_fif(
&self,
fif_path: &Path,
data_norm: f32,
) -> Result<EncodingResult>
pub fn encode_fif( &self, fif_path: &Path, data_norm: f32, ) -> Result<EncodingResult>
Preprocess a .fif recording and encode it into latent embeddings.
data_norm is the same divisor used to train ZUNA (default: 10.0).
It is applied during preprocessing; the encoder output is not
re-scaled — it reflects the MMD-regularised latent space directly.
Sourcepub fn encode_batch(&self, batch_path: &Path) -> Result<EncodingResult>
pub fn encode_batch(&self, batch_path: &Path) -> Result<EncodingResult>
Encode a pre-processed safetensors batch (Python / legacy input path).
The batch is assumed to already be normalised (÷ data_norm); the
data_norm argument is not applied again here — it exists only to
document the convention used when the file was created.
Sourcepub fn encode_tensor(&self, batch: &InputBatch<B>) -> Tensor<B, 3>
pub fn encode_tensor(&self, batch: &InputBatch<B>) -> Tensor<B, 3>
Encode a single prepared InputBatch, returning the raw encoder
output tensor [1, S, output_dim].
This is the MMD-regularised embedding: training constrains the distribution to N(0, I); at inference the bottleneck is a passthrough. No further normalisation is applied here.
Sourcepub fn preprocess_fif(
&self,
fif_path: &Path,
data_norm: f32,
) -> Result<(Vec<InputBatch<B>>, FifInfo)>
pub fn preprocess_fif( &self, fif_path: &Path, data_norm: f32, ) -> Result<(Vec<InputBatch<B>>, FifInfo)>
Run the FIF preprocessing pipeline and return raw InputBatches
without running the encoder.
Use together with Self::encode_batches to time encode separately,
or to export the pre-tokenised tensors for external comparison.
Sourcepub fn encode_batches(
&self,
batches: Vec<InputBatch<B>>,
) -> Result<Vec<EpochEmbedding>>
pub fn encode_batches( &self, batches: Vec<InputBatch<B>>, ) -> Result<Vec<EpochEmbedding>>
Encode a list of InputBatches produced by Self::preprocess_fif.
Auto Trait Implementations§
impl<B> !Freeze for ZunaEncoder<B>
impl<B> !RefUnwindSafe for ZunaEncoder<B>
impl<B> Send for ZunaEncoder<B>
impl<B> !Sync for ZunaEncoder<B>
impl<B> Unpin for ZunaEncoder<B>where
<B as Backend>::Device: Unpin,
<B as Backend>::FloatTensorPrimitive: Unpin,
<B as Backend>::QuantizedTensorPrimitive: Unpin,
impl<B> UnsafeUnpin for ZunaEncoder<B>where
<B as Backend>::Device: UnsafeUnpin,
<B as Backend>::FloatTensorPrimitive: UnsafeUnpin,
<B as Backend>::QuantizedTensorPrimitive: UnsafeUnpin,
impl<B> !UnwindSafe for ZunaEncoder<B>
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> 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