cuvs.preprocessing.quantize.scalar#

4 min read time

Applies to Linux

Submodules#

Classes#

Quantizer

Defines and stores scalar for quantisation upon training

QuantizerParams

QuantizerParams(quantile=None, *)

Functions#

inverse_transform(*args[, resources])

inverse_transform(Quantizer quantizer, dataset, output=None, resources=None)

train(*args[, resources])

train(QuantizerParams params, dataset, resources=None)

transform(*args[, resources])

transform(Quantizer quantizer, dataset, output=None, resources=None)

Package Contents#

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.

static __reduce__(*args, **kwargs)#

Quantizer.__reduce_cython__(self)

static __repr__(*args, **kwargs)#
static __setstate__(*args, **kwargs)#

Quantizer.__setstate_cython__(self, __pyx_state)

class cuvs.preprocessing.quantize.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]

static __reduce__(*args, **kwargs)#

QuantizerParams.__reduce_cython__(self)

static __setstate__(*args, **kwargs)#

QuantizerParams.__setstate_cython__(self, __pyx_state)

cuvs.preprocessing.quantize.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.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.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)