Files
ml-sdk/docs/references/api/concrete.ml.quantization.quantizers.md
zeekay 531fc57003 chore(brand): purge Zama refs across docs, README, configs — phase 1
Brand-only sweep. Touches READMEs, docs, package metadata, comments,
notebook markdown, requirements.txt files; does NOT yet touch Python
`concrete.*` imports (those are module-level dependencies requiring the
phase-2 Python module port from `concrete` → `torus`).

Substitutions applied:

  Concrete ML                  → TorusML
  concrete-ml                  → torus-ml
  Concrete-ML                  → Torus-ML
  concrete_ml                  → torus_ml
  zama-ai/concrete-ml          → luxfhe/ml-sdk
  zama-ai/concrete             → luxfhe/torus
  github.com/zama-ai           → github.com/luxfhe
  docs.zama.ai/concrete-ml     → docs.luxfhe.com/ml-sdk
  docs.zama.ai/concrete        → docs.luxfhe.com/torus
  Zama Concrete ML             → Lux TorusML
  Zama Concrete                → Lux Torus
  Zama tfhe-rs / Zama TFHE-rs  → Lux-FHE
  tfhe-rs / TFHE-rs            → Lux-FHE
  Zama fhEVM / fhEVM           → TorusEVM
  Concrete framework           → Torus framework
  Concrete compiler            → Torus compiler
  Concrete by Zama             → Torus by Lux
  the Zama team                → the Lux Industries team
  Zama's                       → Lux Industries'
  (Zama)                       → (Lux)
  CoFHE / Fhenix               → (removed)

LICENSE: original Zama copyright RETAINED per BSD-3-Clause-Clear §1-§2
requirements; Lux Industries modifications copyright added. Per §3 no
name of ZAMA used to endorse the derived work — product marketed
exclusively as TorusML.

README image URLs migrated to github.com/luxfhe/ml-sdk/assets to break
the dependency on Zama's CDN.

Hit count: 350 → 295. Residual hits are Python `from concrete.fhe import`
imports referencing the upstream Zama `concrete` PyPI package; these
require module-level port (phase 2):

  Phase 2 plan:
    1. Fork zama-ai/concrete (the Python compiler) to luxfhe/torus
    2. Rename Python module `concrete` → `torus`; PyPI publish as `torus-fhe`
    3. Update ml-sdk imports from `concrete.fhe` → `torus.fhe`, etc.
    4. Wire `torus.compiler` GPU dispatch through `luxcpp/gpu` vtbl
       (lux-private/gpu-kernels for CUDA/Metal/WebGPU/FPGA targets)
    5. Port concrete-cuda + concrete-mlir kernels to
       lux-private/gpu-kernels/{cuda,metal,wgsl}/ckks/ (matrix-vector
       mul, rescale, rotate, bootstrap for TorusML inference)

  Phase 3 plan (kernels):
    - CKKS/BGV/BFV GPU kernels in lux-private/gpu-kernels/
      (currently only TFHE PBS / keyswitch / blind-rotate exist)
    - FPGA bitstreams in lux-private/fpga/ (currently scaffold only)

Phase 1 = docs/branding sweep. PR not opened; user reviews and merges.
2026-05-29 13:53:42 -07:00

29 KiB

module concrete.ml.quantization.quantizers

Quantization utilities for a numpy array/tensor.

Global Variables

  • QUANT_ROUND_LIKE_ROUND_PBS
  • STABILITY_CONST

function fill_from_kwargs

fill_from_kwargs(obj, klass, accept_missing, **kwargs)

Fill a parameter set structure from kwargs parameters.

Args:

  • obj: an object of type klass, if None the object is created if any of the type's members appear in the kwargs
  • klass: the type of object to fill
  • accept_missing: don't assert if the fields are None in the kwargs
  • kwargs: parameter names and values to fill into an instance of the klass type

Returns:

  • obj: an object of type klass
  • kwargs: remaining parameter names and values that were not filled into obj

Raises:

  • TypeError: if the types of the parameters in kwargs could not be converted to the corresponding types of members of klass

class QuantizationOptions

Options for quantization.

Determines the number of bits for quantization and the method of quantization of the values. Signed quantization allows negative quantized values. Symmetric quantization assumes the float values are distributed symmetrically around x=0 and assigns signed values around 0 to the float values. QAT (quantization aware training) quantization assumes the values are already quantized, taking a discrete set of values, and assigns these values to integers, computing only the scale.

method __init__

__init__(
    n_bits: 'int',
    is_signed: 'bool' = False,
    is_symmetric: 'bool' = False,
    is_qat: 'bool' = False
)

property quant_options

Get a copy of the quantization parameters.

Returns:

  • UniformQuantizationParameters: a copy of the current quantization parameters

method copy_opts

copy_opts(opts)

Copy the options from a different structure.

Args:

  • opts (QuantizationOptions): structure to copy parameters from.

method dump

dump(file: 'TextIO') → None

Dump itself to a file.

Args:

  • file (TextIO): The file to dump the serialized object into.

method dump_dict

dump_dict() → Dict

Dump itself to a dict.

Returns:

  • metadata (Dict): Dict of serialized objects.

method dumps

dumps() → str

Dump itself to a string.

Returns:

  • metadata (str): String of the serialized object.

method is_equal

is_equal(opts, ignore_sign_qat: 'bool' = False) → bool

Compare two quantization options sets.

Args:

  • opts (QuantizationOptions): options to compare this instance to
  • ignore_sign_qat (bool): ignore sign comparison for QAT options

Returns:

  • bool: whether the two quantization options compared are equivalent

method load_dict

load_dict(metadata: 'Dict')

Load itself from a string.

Args:

  • metadata (Dict): Dict of serialized objects.

Returns:

  • QuantizationOptions: The loaded object.

class MinMaxQuantizationStats

Calibration set statistics.

This class stores the statistics for the calibration set or for a calibration data batch. Currently we only store min/max to determine the quantization range. The min/max are computed from the calibration set.

method __init__

__init__(rmax: 'Optional[float]' = None, rmin: 'Optional[float]' = None)

property quant_stats

Get a copy of the calibration set statistics.

Returns:

  • MinMaxQuantizationStats: a copy of the current quantization stats

method compute_quantization_stats

compute_quantization_stats(values: 'ndarray') → None

Compute the calibration set quantization statistics.

Args:

  • values (numpy.ndarray): Calibration set on which to compute statistics.

method copy_stats

copy_stats(stats) → None

Copy the statistics from a different structure.

Args:

  • stats (MinMaxQuantizationStats): structure to copy statistics from.

method dump

dump(file: 'TextIO') → None

Dump itself to a file.

Args:

  • file (TextIO): The file to dump the serialized object into.

method dump_dict

dump_dict() → Dict

Dump itself to a dict.

Returns:

  • metadata (Dict): Dict of serialized objects.

method dumps

dumps() → str

Dump itself to a string.

Returns:

  • metadata (str): String of the serialized object.

method load_dict

load_dict(metadata: 'Dict')

Load itself from a string.

Args:

  • metadata (Dict): Dict of serialized objects.

Returns:

  • QuantizationOptions: The loaded object.

class UniformQuantizationParameters

Quantization parameters for uniform quantization.

This class stores the parameters used for quantizing real values to discrete integer values. The parameters are computed from quantization options and quantization statistics.

method __init__

__init__(
    scale: 'Optional[float64]' = None,
    zero_point: 'Optional[Union[int, float, ndarray]]' = None,
    offset: 'Optional[int]' = None
)

property quant_params

Get a copy of the quantization parameters.

Returns:

  • UniformQuantizationParameters: a copy of the current quantization parameters

method compute_quantization_parameters

compute_quantization_parameters(
    options: 'QuantizationOptions',
    stats: 'MinMaxQuantizationStats'
) → None

Compute the quantization parameters.

Args:

  • options (QuantizationOptions): quantization options set
  • stats (MinMaxQuantizationStats): calibrated statistics for quantization

method copy_params

copy_params(params) → None

Copy the parameters from a different structure.

Args:

  • params (UniformQuantizationParameters): parameter structure to copy

method dump

dump(file: 'TextIO') → None

Dump itself to a file.

Args:

  • file (TextIO): The file to dump the serialized object into.

method dump_dict

dump_dict() → Dict

Dump itself to a dict.

Returns:

  • metadata (Dict): Dict of serialized objects.

method dumps

dumps() → str

Dump itself to a string.

Returns:

  • metadata (str): String of the serialized object.

method load_dict

load_dict(metadata: 'Dict') → UniformQuantizationParameters

Load itself from a string.

Args:

  • metadata (Dict): Dict of serialized objects.

Returns:

  • UniformQuantizationParameters: The loaded object.

class UniformQuantizer

Uniform quantizer.

Contains all information necessary for uniform quantization and provides quantization/de-quantization functionality on numpy arrays.

Args:

  • options (QuantizationOptions): Quantization options set
  • stats (Optional[MinMaxQuantizationStats]): Quantization batch statistics set
  • params (Optional[UniformQuantizationParameters]): Quantization parameters set (scale, zero-point)

method __init__

__init__(
    options: 'Optional[QuantizationOptions]' = None,
    stats: 'Optional[MinMaxQuantizationStats]' = None,
    params: 'Optional[UniformQuantizationParameters]' = None,
    no_clipping: 'bool' = False
)

property quant_options

Get a copy of the quantization parameters.

Returns:

  • UniformQuantizationParameters: a copy of the current quantization parameters

property quant_params

Get a copy of the quantization parameters.

Returns:

  • UniformQuantizationParameters: a copy of the current quantization parameters

property quant_stats

Get a copy of the calibration set statistics.

Returns:

  • MinMaxQuantizationStats: a copy of the current quantization stats

method compute_quantization_parameters

compute_quantization_parameters(
    options: 'QuantizationOptions',
    stats: 'MinMaxQuantizationStats'
) → None

Compute the quantization parameters.

Args:

  • options (QuantizationOptions): quantization options set
  • stats (MinMaxQuantizationStats): calibrated statistics for quantization

method compute_quantization_stats

compute_quantization_stats(values: 'ndarray') → None

Compute the calibration set quantization statistics.

Args:

  • values (numpy.ndarray): Calibration set on which to compute statistics.

method copy_opts

copy_opts(opts)

Copy the options from a different structure.

Args:

  • opts (QuantizationOptions): structure to copy parameters from.

method copy_params

copy_params(params) → None

Copy the parameters from a different structure.

Args:

  • params (UniformQuantizationParameters): parameter structure to copy

method copy_stats

copy_stats(stats) → None

Copy the statistics from a different structure.

Args:

  • stats (MinMaxQuantizationStats): structure to copy statistics from.

method dequant

dequant(qvalues: 'ndarray') → Union[float, ndarray, Tracer]

De-quantize values.

Args:

  • qvalues (numpy.ndarray): integer values to de-quantize

Returns:

  • Union[numpy.ndarray, Tracer]: De-quantized float values.

method dump

dump(file: 'TextIO') → None

Dump itself to a file.

Args:

  • file (TextIO): The file to dump the serialized object into.

method dump_dict

dump_dict() → Dict

Dump itself to a dict.

Returns:

  • metadata (Dict): Dict of serialized objects.

method dumps

dumps() → str

Dump itself to a string.

Returns:

  • metadata (str): String of the serialized object.

method is_equal

is_equal(opts, ignore_sign_qat: 'bool' = False) → bool

Compare two quantization options sets.

Args:

  • opts (QuantizationOptions): options to compare this instance to
  • ignore_sign_qat (bool): ignore sign comparison for QAT options

Returns:

  • bool: whether the two quantization options compared are equivalent

method load_dict

load_dict(metadata: 'Dict') → UniformQuantizer

Load itself from a string.

Args:

  • metadata (Dict): Dict of serialized objects.

Returns:

  • UniformQuantizer: The loaded object.

method quant

quant(values: 'ndarray', dtype: 'DTypeLike' = <class 'numpy.int64'>) → ndarray

Quantize values.

Args:

  • values (numpy.ndarray): float values to quantize
  • dtype (numpy.typing.DTypeLike): optional user-specified datatype for the output

Returns:

  • numpy.ndarray: Integer quantized values.

class TorchUniformQuantizer

Uniform quantizer with a PyTorch implementation.

Contains all information necessary for uniform quantization and provides quantization/de-quantization functionality on torch tensors.

Args:

  • quantizer (UniformQuantizer): Underlying numpy quantizer containing all parameters

method __init__

__init__(quantizer: 'UniformQuantizer')

method dequant

dequant(qvalues: 'Tensor') → Tensor

De-quantize values.

Args:

  • qvalues (numpy.ndarray): integer values to de-quantize

Returns:

  • Union[numpy.ndarray, Tracer]: De-quantized float values.

method quant

quant(values: 'Tensor', dtype: 'Optional[dtype]' = None) → Tensor

Quantize values.

Args:

  • values (numpy.ndarray): float values to quantize
  • dtype (Optional[torch.dtype]): optional user-specified datatype for the output

Returns:

  • numpy.ndarray: Integer quantized values.

class QuantizedArray

Abstraction of quantized array.

Contains float values and their quantized integer counter-parts. Quantization is performed by the quantizer member object. Float and int values are kept in sync. Having both types of values is useful since quantized operators in TorusML graphs might need one or the other depending on how the operator works (in float or in int). Moreover, when the encrypted function needs to return a value, it must return integer values.

See https://arxiv.org/abs/1712.05877.

Args:

  • values (numpy.ndarray): Values to be quantized.
  • n_bits (int): The number of bits to use for quantization.
  • value_is_float (bool, optional): Whether the passed values are real (float) values or not. If False, the values will be quantized according to the passed scale and zero_point. Defaults to True.
  • options (QuantizationOptions): Quantization options set
  • stats (Optional[MinMaxQuantizationStats]): Quantization batch statistics set
  • params (Optional[UniformQuantizationParameters]): Quantization parameters set (scale, zero-point)
  • kwargs: Any member of the options, stats, params sets as a key-value pair. The parameter sets need to be completely parametrized if their members appear in kwargs.

method __init__

__init__(
    n_bits,
    values: 'Union[None, float, int, ndarray]',
    value_is_float: 'bool' = True,
    options: 'Optional[QuantizationOptions]' = None,
    stats: 'Optional[MinMaxQuantizationStats]' = None,
    params: 'Optional[UniformQuantizationParameters]' = None,
    **kwargs
)

method dequant

dequant() → Union[ndarray, Tracer]

De-quantize self.qvalues.

Returns:

  • Union[numpy.ndarray, Tracer]: De-quantized values.

method dump

dump(file: 'TextIO') → None

Dump itself to a file.

Args:

  • file (TextIO): The file to dump the serialized object into.

method dump_dict

dump_dict() → Dict

Dump itself to a dict.

Returns:

  • metadata (Dict): Dict of serialized objects.

method dumps

dumps() → str

Dump itself to a string.

Returns:

  • metadata (str): String of the serialized object.

method load_dict

load_dict(metadata: 'Dict') → QuantizedArray

Load itself from a string.

Args:

  • metadata (Dict): Dict of serialized objects.

Returns:

  • QuantizedArray: The loaded object.

method quant

quant() → Union[ndarray, Tracer]

Quantize self.values.

Returns:

  • Union[numpy.ndarray, Tracer]: Quantized values.

method update_quantized_values

update_quantized_values(
    qvalues: 'Union[ndarray, Tracer]'
) → Union[ndarray, Tracer]

Update qvalues to get their corresponding values using the related quantized parameters.

Args:

  • qvalues (Union[numpy.ndarray, Tracer]): Values to replace self.qvalues

Returns:

  • values (Union[numpy.ndarray, Tracer]): Corresponding values

method update_values

update_values(values: 'Union[ndarray, Tracer]') → Union[ndarray, Tracer]

Update values to get their corresponding qvalues using the related quantized parameters.

Args:

  • values (Union[numpy.ndarray, Tracer]): Values to replace self.values

Returns:

  • qvalues (Union[numpy.ndarray, Tracer]): Corresponding qvalues