pub trait DynQuantizedStorage:
Send
+ Sync
+ Debug {
Show 15 methods
// Required methods
fn dtype(&self) -> GgmlDType;
fn block_size(&self) -> usize;
fn storage_size_in_bytes(&self) -> usize;
fn quantize(&mut self, src: &dyn DynBackendStorage) -> Result<(), Error>;
fn quantize_imatrix(
&mut self,
src: &dyn DynBackendStorage,
imatrix_weights: &[f32],
n_per_row: usize,
) -> Result<(), Error>;
fn quantize_onto(
&mut self,
src: &dyn DynBackendStorage,
) -> Result<(), Error>;
fn quantize_imatrix_onto(
&mut self,
src: &dyn DynBackendStorage,
imatrix_weights: &[f32],
n_per_row: usize,
) -> Result<(), Error>;
fn dequantize(
&self,
elem_count: usize,
) -> Result<Box<dyn DynBackendStorage>, Error>;
fn data(&self) -> Result<Cow<'_, [u8]>, Error>;
fn fwd(
&self,
self_shape: &Shape,
input: &dyn DynBackendStorage,
layout: &Layout,
) -> Result<(Box<dyn DynBackendStorage>, Shape), Error>;
fn as_any(&self) -> &(dyn Any + 'static);
fn device_arc_dyn(&self) -> Arc<dyn DynBackendDevice> ⓘ;
// Provided methods
fn dequantize_f16(
&self,
_elem_count: usize,
) -> Result<Box<dyn DynBackendStorage>, Error> { ... }
fn device_ptr(&self) -> Result<*const u8, Error> { ... }
fn indexed_moe_forward(
&self,
_self_shape: &Shape,
_input: &dyn DynBackendStorage,
_input_layout: &Layout,
_ids: &dyn DynBackendStorage,
_ids_layout: &Layout,
) -> Result<(Box<dyn DynBackendStorage>, Shape), Error> { ... }
}Expand description
Object-safe per-backend quantized storage. Each backend (CPU, CUDA,
Metal, …) supplies a concrete type that implements this trait;
fuel-core holds them as Box<dyn DynQuantizedStorage> and dispatches
without naming backends.
The _src arguments to quantize* are typed as &dyn DynBackendStorage
so the implementor can downcast to its own concrete storage; the
_onto variants take a HostBuffer-shaped CPU source.
Required Methods§
fn dtype(&self) -> GgmlDType
fn block_size(&self) -> usize
fn storage_size_in_bytes(&self) -> usize
Sourcefn quantize(&mut self, src: &dyn DynBackendStorage) -> Result<(), Error>
fn quantize(&mut self, src: &dyn DynBackendStorage) -> Result<(), Error>
Quantize an in-device source storage onto self.
Sourcefn quantize_imatrix(
&mut self,
src: &dyn DynBackendStorage,
imatrix_weights: &[f32],
n_per_row: usize,
) -> Result<(), Error>
fn quantize_imatrix( &mut self, src: &dyn DynBackendStorage, imatrix_weights: &[f32], n_per_row: usize, ) -> Result<(), Error>
Quantize with importance-matrix weighting.
Sourcefn quantize_onto(&mut self, src: &dyn DynBackendStorage) -> Result<(), Error>
fn quantize_onto(&mut self, src: &dyn DynBackendStorage) -> Result<(), Error>
Quantize a CPU source onto self (cross-device).
Sourcefn quantize_imatrix_onto(
&mut self,
src: &dyn DynBackendStorage,
imatrix_weights: &[f32],
n_per_row: usize,
) -> Result<(), Error>
fn quantize_imatrix_onto( &mut self, src: &dyn DynBackendStorage, imatrix_weights: &[f32], n_per_row: usize, ) -> Result<(), Error>
Quantize with importance matrix from a CPU source.
Sourcefn dequantize(
&self,
elem_count: usize,
) -> Result<Box<dyn DynBackendStorage>, Error>
fn dequantize( &self, elem_count: usize, ) -> Result<Box<dyn DynBackendStorage>, Error>
Dequantize to backend-native f32 storage.
Sourcefn data(&self) -> Result<Cow<'_, [u8]>, Error>
fn data(&self) -> Result<Cow<'_, [u8]>, Error>
Raw bytes of the quantized data (host-readable copy).
Sourcefn fwd(
&self,
self_shape: &Shape,
input: &dyn DynBackendStorage,
layout: &Layout,
) -> Result<(Box<dyn DynBackendStorage>, Shape), Error>
fn fwd( &self, self_shape: &Shape, input: &dyn DynBackendStorage, layout: &Layout, ) -> Result<(Box<dyn DynBackendStorage>, Shape), Error>
QMatMul forward against an in-device input storage. Returns a fresh
device storage and its output shape. self_shape is the weight shape
(the QTensor’s own shape).
Sourcefn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Identity returns the host device tag this storage is on.
Sourcefn device_arc_dyn(&self) -> Arc<dyn DynBackendDevice> ⓘ
fn device_arc_dyn(&self) -> Arc<dyn DynBackendDevice> ⓘ
Owning device handle. Lets fuel-core recover a Device from a
QTensor without keeping a parallel device field on QTensor.
Provided Methods§
Sourcefn dequantize_f16(
&self,
_elem_count: usize,
) -> Result<Box<dyn DynBackendStorage>, Error>
fn dequantize_f16( &self, _elem_count: usize, ) -> Result<Box<dyn DynBackendStorage>, Error>
Dequantize to f16 (CUDA fast path; default impl rejects).
Sourcefn device_ptr(&self) -> Result<*const u8, Error>
fn device_ptr(&self) -> Result<*const u8, Error>
Device pointer for callers that need raw addressing (CUDA only today).
Sourcefn indexed_moe_forward(
&self,
_self_shape: &Shape,
_input: &dyn DynBackendStorage,
_input_layout: &Layout,
_ids: &dyn DynBackendStorage,
_ids_layout: &Layout,
) -> Result<(Box<dyn DynBackendStorage>, Shape), Error>
fn indexed_moe_forward( &self, _self_shape: &Shape, _input: &dyn DynBackendStorage, _input_layout: &Layout, _ids: &dyn DynBackendStorage, _ids_layout: &Layout, ) -> Result<(Box<dyn DynBackendStorage>, Shape), Error>
Indexed MoE forward (CUDA-only today; default rejects).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".