Preprocessing#
Scalar Quantizer#
- class cuvs.preprocessing.quantize.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.
- Attributes:
- max
- min
- class cuvs.preprocessing.quantize.scalar.QuantizerParams(quantile=None, *)#
Parameters for scalar quantization
- Parameters:
- quantile: float
specifies how many outliers at top & bottom will be ignored needs to be within range of (0, 1]
- Attributes:
- quantile
- cuvs.preprocessing.quantize.scalar.train(QuantizerParams params, dataset, resources=None)[source]#
Initializes a scalar quantizer to be used later for quantizing the dataset.
- Parameters:
- paramsQuantizerParams object
- datasetrow major host or device dataset
- resourcesOptional 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.
- Returns:
- quantizer: cuvs.preprocessing.quantize.scalar.Quantizer
Examples
>>> 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.transform(Quantizer quantizer, dataset, output=None, resources=None)[source]#
Applies quantization transform to given dataset
- Parameters:
- quantizertrained Quantizer object
- datasetrow major host or device dataset to transform
- outputoptional preallocated output memory, on host or device memory
- resourcesOptional 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.
- Returns:
- outputtransformed dataset quantized into a int8
Examples
>>> 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.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.
- Parameters:
- quantizertrained Quantizer object
- datasetrow major host or device dataset to transform
- outputoptional preallocated output memory, on host or device
- resourcesOptional 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.
- Returns:
- outputtransformed dataset with scalar quantization reversed