Preprocessing#
2025-10-17
4 min read time
Scalar Quantizer#
- cuvs.preprocessing.quantize.scalar.scalar.check_cuvs(status: cuvsError_t)#
- check_cuvs(cuvsError_t status: cuvsError_t)
Converts a status code into an exception
- cuvs.preprocessing.quantize.scalar.scalar.auto_sync_resources(f)#
auto_sync_resources(f) Decorator to automatically call sync on a cuVS Resources object when
it isn’t passed to a function.
When a resources=None is passed to the wrapped function, this decorator will automatically create a default resources for the function, and call sync on that resources when the function exits.
This will also insert the appropriate docstring for the resources parameter
- class cuvs.preprocessing.quantize.scalar.scalar.Quantizer#
Defines and stores scalar for quantisation upon training
The quantization is performed by a linear mapping of an interval in the float data type to the full range of the quantized int type.
- class cuvs.preprocessing.quantize.scalar.scalar.QuantizerParams#
QuantizerParams(quantile=None, *)
Parameters for scalar quantization
- quantile: float
specifies how many outliers at top & bottom will be ignored needs to be within range of (0, 1]
- cuvs.preprocessing.quantize.scalar.scalar.inverse_transform(*args, resources=None, **kwargs)#
inverse_transform(Quantizer quantizer, dataset, output=None, resources=None)
Perform inverse quantization step on previously quantized dataset
Note that depending on the chosen data types train dataset the conversion is not lossless.
quantizer : trained Quantizer object dataset : row major host or device dataset to transform output : optional preallocated output memory, on host or device resources : Optional cuVS Resource handle for reusing CUDA resources.
If Resources aren’t supplied, CUDA resources will be allocated inside this function and synchronized before the function exits. If resources are supplied, you will need to explicitly synchronize yourself by calling resources.sync() before accessing the output.
output : transformed dataset with scalar quantization reversed
- cuvs.preprocessing.quantize.scalar.scalar.train(*args, resources=None, **kwargs)#
train(QuantizerParams params, dataset, resources=None)
Initializes a scalar quantizer to be used later for quantizing the dataset.
params : QuantizerParams object dataset : row major host or device dataset resources : Optional cuVS Resource handle for reusing CUDA resources.
If Resources aren’t supplied, CUDA resources will be allocated inside this function and synchronized before the function exits. If resources are supplied, you will need to explicitly synchronize yourself by calling resources.sync() before accessing the output.
quantizer: cuvs.preprocessing.quantize.scalar.Quantizer
>>> import cupy as cp >>> from cuvs.preprocessing.quantize import scalar >>> n_samples = 50000 >>> n_features = 50 >>> dataset = cp.random.random_sample((n_samples, n_features), ... dtype=cp.float32) >>> params = scalar.QuantizerParams(quantile=0.99) >>> quantizer = scalar.train(params, dataset) >>> transformed = scalar.transform(quantizer, dataset)
- cuvs.preprocessing.quantize.scalar.scalar.transform(*args, resources=None, **kwargs)#
transform(Quantizer quantizer, dataset, output=None, resources=None)
Applies quantization transform to given dataset
quantizer : trained Quantizer object dataset : row major host or device dataset to transform output : optional preallocated output memory, on host or device memory resources : Optional cuVS Resource handle for reusing CUDA resources.
If Resources aren’t supplied, CUDA resources will be allocated inside this function and synchronized before the function exits. If resources are supplied, you will need to explicitly synchronize yourself by calling resources.sync() before accessing the output.
output : transformed dataset quantized into a int8
>>> import cupy as cp >>> from cuvs.preprocessing.quantize import scalar >>> n_samples = 50000 >>> n_features = 50 >>> dataset = cp.random.random_sample((n_samples, n_features), ... dtype=cp.float32) >>> params = scalar.QuantizerParams(quantile=0.99) >>> quantizer = scalar.train(params, dataset) >>> transformed = scalar.transform(quantizer, dataset)