pub struct VectorQuantizer { /* private fields */ }Expand description
EMA-trained vector quantizer with persistent, non-gradient codebook state.
Implementations§
Source§impl VectorQuantizer
impl VectorQuantizer
pub fn new_with_seed(config: VectorQuantizerConfig, seed: u64) -> Result<Self>
Sourcepub fn new_with_seed_on(
runtime: &Runtime,
config: VectorQuantizerConfig,
seed: u64,
) -> Result<Self>
pub fn new_with_seed_on( runtime: &Runtime, config: VectorQuantizerConfig, seed: u64, ) -> Result<Self>
Construct a deterministically initialized quantizer.
§Errors
Returns an error for an invalid configuration, shape overflow, or failed state allocation/upload.
pub fn new(config: VectorQuantizerConfig) -> Result<Self>
Sourcepub fn new_on(runtime: &Runtime, config: VectorQuantizerConfig) -> Result<Self>
pub fn new_on(runtime: &Runtime, config: VectorQuantizerConfig) -> Result<Self>
Construct a quantizer using deterministic seed zero.
§Errors
Returns the same errors as Self::new_with_seed.
Sourcepub fn quantize(&self, latent: &Matrix) -> Result<VqResult>
pub fn quantize(&self, latent: &Matrix) -> Result<VqResult>
Quantize latent rows and build the donor straight-through estimator.
This records entirely device-side work. The codebook receives no gradient;
EMA updates it explicitly through Self::ema_update.
§Errors
Returns an error for an incompatible latent or failed runtime recording.
Sourcepub fn ema_update(&self, latent: &Matrix, indices: &Matrix) -> Result<()>
pub fn ema_update(&self, latent: &Matrix, indices: &Matrix) -> Result<()>
Advance codebook EMA state once from the current latent assignment.
§Errors
Returns an error for incompatible inputs or failed runtime recording.
Sourcepub fn lookup(&self, indices: &Matrix) -> Result<Matrix>
pub fn lookup(&self, indices: &Matrix) -> Result<Matrix>
Decode I32 token ids into code vectors.
§Errors
Returns an error for incompatible indices or failed runtime recording.
Sourcepub fn seed(&self, latents: &Matrix) -> Result<()>
pub fn seed(&self, latents: &Matrix) -> Result<()>
Seed codes from the highest-L2-norm latent rows.
Equal norms select lower source-row indices. Selection stays on the GPU; the final checkpoint is the donor-compatible explicit initialization completion boundary.
§Errors
Returns an error unless latents is FP32 [N,D], N >= K, and its code
dimension and runtime match this quantizer, or readback/upload fails.
Sourcepub const fn config(&self) -> &VectorQuantizerConfig
pub const fn config(&self) -> &VectorQuantizerConfig
Return this quantizer’s immutable configuration.
Trait Implementations§
Source§impl Module for VectorQuantizer
impl Module for VectorQuantizer
Source§fn forward(&self, input: &Matrix) -> Result<Matrix>
fn forward(&self, input: &Matrix) -> Result<Matrix>
Source§fn registry(&self) -> &ModuleRegistry
fn registry(&self) -> &ModuleRegistry
Source§fn parameters(&self) -> Vec<Parameter>
fn parameters(&self) -> Vec<Parameter>
Source§fn named_parameters(&self) -> Vec<NamedParameter>
fn named_parameters(&self) -> Vec<NamedParameter>
Source§fn named_buffers(&self) -> Vec<NamedBuffer>
fn named_buffers(&self) -> Vec<NamedBuffer>
Source§fn all_parameters(&self) -> Result<Vec<Parameter>>
fn all_parameters(&self) -> Result<Vec<Parameter>>
Source§fn all_named_parameters(&self) -> Result<Vec<NamedParameter>>
fn all_named_parameters(&self) -> Result<Vec<NamedParameter>>
Source§fn all_named_buffers(&self) -> Result<Vec<NamedBuffer>>
fn all_named_buffers(&self) -> Result<Vec<NamedBuffer>>
Source§fn all_named_state_u32(&self) -> Result<Vec<NamedStateU32>>
fn all_named_state_u32(&self) -> Result<Vec<NamedStateU32>>
u32 scalar state in
deterministic depth-first order. Read more