pub struct QuantPreview<'model> { /* private fields */ }Expand description
Ask llama.cpp what it would do, without writing a file.
crate::model_quantize is all-or-nothing: it reads a model, quantizes
every tensor, and writes the result. This exposes the decision layer
underneath — which tensors get quantized at all, and to which ggml type —
so a tool can show the plan, or estimate output size, before committing to
a run that may take minutes and tens of gigabytes.
The k-quant mixes are why this is not simply LlamaFtype::default_ggml_type:
they deliberately keep attention and output tensors at higher precision, so
the per-tensor answer differs from the ftype’s nominal type.
Wraps llama_quant_init / llama_quant_free.
Implementations§
Source§impl<'model> QuantPreview<'model>
impl<'model> QuantPreview<'model>
Sourcepub fn new(
model: &'model LlamaModel,
params: &QuantizeParams,
) -> Result<Self, QuantPreviewError>
pub fn new( model: &'model LlamaModel, params: &QuantizeParams, ) -> Result<Self, QuantPreviewError>
Build a preview for model under params.
§Errors
Returns QuantPreviewError::Init if llama.cpp could not build the
quantization state, which happens for a model it cannot quantize.
Sourcepub fn allows_quantization(&self, tensor: &GgmlTensor) -> bool
pub fn allows_quantization(&self, tensor: &GgmlTensor) -> bool
Whether this tensor would be quantized at all.
llama.cpp skips 1-D tensors, tensors below a size threshold, and ones
whose name marks them as needing full precision — so a false here is
the usual reason a tensor keeps its original type.
Requires the ggml feature, which is what exposes crate::ggml::GgmlTensor.
Sourcepub fn compute_types(
&self,
tensors: &[&GgmlTensor],
ftype: LlamaFtype,
) -> Result<Vec<Option<GgmlType>>, QuantPreviewError>
pub fn compute_types( &self, tensors: &[&GgmlTensor], ftype: LlamaFtype, ) -> Result<Vec<Option<GgmlType>>, QuantPreviewError>
Compute the storage type each tensor would be assigned under ftype.
Every tensor passed must already satisfy Self::allows_quantization —
upstream states the caller filters first, and does not re-check.
An entry is None when llama.cpp picks a ggml type this crate’s
GgmlType does not know.
§Errors
Returns QuantPreviewError::NotQuantizable naming the first tensor
that fails the filter, rather than letting llama.cpp decide what to do
with it.
Requires the ggml feature.