hgq.quantizer package

Subpackages

Submodules

hgq.quantizer.config module

class hgq.quantizer.config.FloatConfig

Bases: dict

bw_mapper: BitwidthMapperBase | None
e0: int | float | integer | floating | Initializer
e00: int | float | integer | floating | Initializer
e0c: Constraint | None
e0r: Regularizer | None
ec: Constraint | None
er: Regularizer | None
heterogeneous_axis: Sequence[int] | None
homogeneous_axis: Sequence[int] | None
is_weight: bool
m0: int | float | integer | floating | Initializer
mc: Constraint | None
mr: Regularizer | None
trainable: bool
class hgq.quantizer.config.KBIConfig

Bases: dict

b0: int | float | integer | floating | Initializer
bc: Constraint | None
br: Regularizer | None
bw_mapper: BitwidthMapperBase | None
heterogeneous_axis: Sequence[int] | None
homogeneous_axis: Sequence[int] | None
i0: int | float | integer | floating | Initializer
i_decay_speed: int | float | integer | floating
ic: Constraint | None
ir: Regularizer | None
is_weight: bool
k0: int | float | integer | floating | bool | Initializer
overflow_mode: str
round_mode: str
trainable: bool
class hgq.quantizer.config.KIFConfig

Bases: dict

bw_mapper: BitwidthMapperBase | None
f0: int | float | integer | floating | Initializer
fc: Constraint | None
fr: Regularizer | None
heterogeneous_axis: Sequence[int] | None
homogeneous_axis: Sequence[int] | None
i0: int | float | integer | floating | Initializer
i_decay_speed: int | float | integer | floating
ic: Constraint | None
ir: Regularizer | None
is_weight: bool
k0: int | float | integer | floating | bool | Initializer
overflow_mode: str
round_mode: str
trainable: bool
class hgq.quantizer.config.QuantizerConfig(q_type: str = 'kbi', place: str = 'datalane', *, k0: int | float | integer | floating | bool | Initializer = True, b0: int | float | integer | floating | Initializer = 4, i0: int | float | integer | floating | Initializer = 2, round_mode: str = 'RND', overflow_mode: str = 'WRAP', bc: Constraint | None = MinMax(0, 12), ic: Constraint | None = None, br: Regularizer | None = None, ir: Regularizer | None = None, i_decay_speed: int | float | integer | floating = -1, homogeneous_axis: Sequence[int] | None = None, heterogeneous_axis: Sequence[int] | None = None, bw_mapper: BitwidthMapperBase | None = None, scaler: int | float | integer | floating | None = None, qnoise_factor: float | None = None, **kwargs)
class hgq.quantizer.config.QuantizerConfig(q_type: str = 'kif', place: str = 'datalane', *, k0: int | float | integer | floating | bool | Initializer = True, i0: int | float | integer | floating | Initializer = 4, f0: int | float | integer | floating | Initializer = 2, round_mode: str = 'RND', overflow_mode: str = 'SAT', ic: Constraint | None = MinMax(-12, 12), ir: Regularizer | None = None, fc: Constraint | None = MinMax(-10, 10), fr: Regularizer | None = None, i_decay_speed: int | float | integer | floating = 0.01, homogeneous_axis: Sequence[int] | None = (0,), heterogeneous_axis: Sequence[int] | None = None, bw_mapper: BitwidthMapperBase | None = None, scaler: int | float | integer | floating | None = None, qnoise_factor: float | None = None, **kwargs)
class hgq.quantizer.config.QuantizerConfig(q_type: str = 'float', place: str = 'datalane', *, m0: int | float | integer | floating | Initializer = 2, e0: int | float | integer | floating | Initializer = 1, e00: int | float | integer | floating | Initializer = 0, mc: Constraint | None = Min(-1), ec: Constraint | None = MinMax(0, 4), e0c: Constraint | None = MinMax(-8, 8), mr: Regularizer | None = None, er: Regularizer | None = None, e0r: Regularizer | None = None, homogeneous_axis: Sequence[int] | None = (), heterogeneous_axis: Sequence[int] | None = None, bw_mapper: BitwidthMapperBase | None = None, scaler: int | float | integer | floating | None = None, qnoise_factor: float | None = None, **kwargs)

Bases: Mapping

classmethod from_config(config)
get_config()
get_quantizer() TrainableQuantizerBase
class hgq.quantizer.config.QuantizerConfigBase

Bases: TypedDict

bw_mapper: BitwidthMapperBase | None
heterogeneous_axis: Sequence[int] | None
homogeneous_axis: Sequence[int] | None
is_weight: bool
trainable: bool
class hgq.quantizer.config.QuantizerConfigScope(q_type: str | Sequence[str] | set[str] = 'all', place: str | Sequence[str] | set[str] = 'all', default_q_type=None, **kwargs)

Bases: object

override()

Override the default quantizer config.

hgq.quantizer.config.all_places()
hgq.quantizer.config.all_quantizer_types()

hgq.quantizer.quantizer module

class hgq.quantizer.quantizer.Quantizer(*args, **kwargs)

Bases: Layer

The generic quantizer layer, wraps internal quantizers to provide a universal interface. Supports float, fixed-point (KBI, KIF) quantization. Can be initialized with a QuantizerConfig object or with the quantizer type and its parameters.

property bits
bits_(shape)
build(input_shape)
call(inputs, training=None)
epsilon_(shape)
classmethod from_config(config)

Creates an operation from its config.

This method is the reverse of get_config, capable of instantiating the same operation from the config dictionary.

Note: If you override this method, you might receive a serialized dtype config, which is a dict. You can deserialize it as follows:

```python if “dtype” in config and isinstance(config[“dtype”], dict):

policy = dtype_policies.deserialize(config[“dtype”])

```

Parameters:

config – A Python dictionary, typically the output of get_config.

Returns:

An operation instance.

get_config()

Returns the config of the object.

An object config is a Python dictionary (serializable) containing the information needed to re-instantiate it.

get_quantizer_config_kwargs(*args, **kwargs)
max_(shape)
min_(shape)
property q_type

Module contents

class hgq.quantizer.Quantizer(*args, **kwargs)

Bases: Layer

The generic quantizer layer, wraps internal quantizers to provide a universal interface. Supports float, fixed-point (KBI, KIF) quantization. Can be initialized with a QuantizerConfig object or with the quantizer type and its parameters.

property bits
bits_(shape)
build(input_shape)
call(inputs, training=None)
epsilon_(shape)
classmethod from_config(config)

Creates an operation from its config.

This method is the reverse of get_config, capable of instantiating the same operation from the config dictionary.

Note: If you override this method, you might receive a serialized dtype config, which is a dict. You can deserialize it as follows:

```python if “dtype” in config and isinstance(config[“dtype”], dict):

policy = dtype_policies.deserialize(config[“dtype”])

```

Parameters:

config – A Python dictionary, typically the output of get_config.

Returns:

An operation instance.

get_config()

Returns the config of the object.

An object config is a Python dictionary (serializable) containing the information needed to re-instantiate it.

get_quantizer_config_kwargs(*args, **kwargs)
max_(shape)
min_(shape)
property q_type
class hgq.quantizer.QuantizerConfig(q_type: str = 'kbi', place: str = 'datalane', *, k0: int | float | integer | floating | bool | Initializer = True, b0: int | float | integer | floating | Initializer = 4, i0: int | float | integer | floating | Initializer = 2, round_mode: str = 'RND', overflow_mode: str = 'WRAP', bc: Constraint | None = MinMax(0, 12), ic: Constraint | None = None, br: Regularizer | None = None, ir: Regularizer | None = None, i_decay_speed: int | float | integer | floating = -1, homogeneous_axis: Sequence[int] | None = None, heterogeneous_axis: Sequence[int] | None = None, bw_mapper: BitwidthMapperBase | None = None, scaler: int | float | integer | floating | None = None, qnoise_factor: float | None = None, **kwargs)
class hgq.quantizer.QuantizerConfig(q_type: str = 'kif', place: str = 'datalane', *, k0: int | float | integer | floating | bool | Initializer = True, i0: int | float | integer | floating | Initializer = 4, f0: int | float | integer | floating | Initializer = 2, round_mode: str = 'RND', overflow_mode: str = 'SAT', ic: Constraint | None = MinMax(-12, 12), ir: Regularizer | None = None, fc: Constraint | None = MinMax(-10, 10), fr: Regularizer | None = None, i_decay_speed: int | float | integer | floating = 0.01, homogeneous_axis: Sequence[int] | None = (0,), heterogeneous_axis: Sequence[int] | None = None, bw_mapper: BitwidthMapperBase | None = None, scaler: int | float | integer | floating | None = None, qnoise_factor: float | None = None, **kwargs)
class hgq.quantizer.QuantizerConfig(q_type: str = 'float', place: str = 'datalane', *, m0: int | float | integer | floating | Initializer = 2, e0: int | float | integer | floating | Initializer = 1, e00: int | float | integer | floating | Initializer = 0, mc: Constraint | None = Min(-1), ec: Constraint | None = MinMax(0, 4), e0c: Constraint | None = MinMax(-8, 8), mr: Regularizer | None = None, er: Regularizer | None = None, e0r: Regularizer | None = None, homogeneous_axis: Sequence[int] | None = (), heterogeneous_axis: Sequence[int] | None = None, bw_mapper: BitwidthMapperBase | None = None, scaler: int | float | integer | floating | None = None, qnoise_factor: float | None = None, **kwargs)

Bases: Mapping

classmethod from_config(config)
get_config()
get_quantizer() TrainableQuantizerBase