hgq.layers package

Subpackages

Submodules

hgq.layers.activation module

class hgq.layers.activation.QUnaryFunctionLUT(*args, **kwargs)

Bases: Activation, QLayerBaseSingleInput

call(inputs, training=None)
get_config()

Returns the config of the object.

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

hgq.layers.batch_normalization module

class hgq.layers.batch_normalization.QBatchNormalization(*args, **kwargs)

Bases: QLayerBaseSingleInput, BatchNormalization

property beta
property bq
build(input_shape)
call(inputs, training=None, mask=None)
property gamma
get_config()

Returns the config of the object.

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

property kq
property qscaler_and_qoffset

hgq.layers.conv module

class hgq.layers.conv.QBaseConv(*args, **kwargs)

Bases: QLayerBaseSingleInput, BaseConv

property bq
build(input_shape)
call(inputs, training=None)
get_config()

Returns the config of the object.

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

property kq
property qbias
property qkernel
class hgq.layers.conv.QConv1D(*args, **kwargs)

Bases: QBaseConv

call(inputs, training=None)
get_config()

Returns the config of the object.

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

class hgq.layers.conv.QConv2D(*args, **kwargs)

Bases: QBaseConv

get_config()

Returns the config of the object.

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

class hgq.layers.conv.QConv3D(*args, **kwargs)

Bases: QBaseConv

get_config()

Returns the config of the object.

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

hgq.layers.einsum_dense_batchnorm module

class hgq.layers.einsum_dense_batchnorm.QEinsumDenseBatchnorm(*args, **kwargs)

Bases: QEinsumDense

property bq
build(input_shape)
call(inputs, training=None)
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_fused_qkernel_and_qbias(training, mean, var)
property kq
property qbias
property qkernel

hgq.layers.linformer_attention module

class hgq.layers.linformer_attention.QLinformerAttention(*args, **kwargs)

Bases: QMultiHeadAttention

build(query_shape, value_shape, key_shape=None)

Builds layers and variables.

Parameters:
  • query_shape (tuple) – Shape of the query tensor.

  • value_shape (tuple) – Shape of the value tensor.

  • key_shape (tuple, optional) – Shape of the key tensor.

call(query, value, key=None, query_mask=None, value_mask=None, key_mask=None, attention_mask=None, return_attention_scores=False, training=None, use_causal_mask=False)
property ebops: int
get_config()

Returns the config of the object.

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

hgq.layers.multi_head_attention module

class hgq.layers.multi_head_attention.QMultiHeadAttention(*args, **kwargs)

Bases: MultiHeadAttention, QLayerBase

build(query_shape, value_shape, key_shape=None)

Builds layers and variables.

Parameters:
  • query_shape (tuple) – Shape of the query tensor.

  • value_shape (tuple) – Shape of the value tensor.

  • key_shape (tuple, optional) – Shape of the key tensor.

call(query, value, key=None, query_mask=None, value_mask=None, key_mask=None, attention_mask=None, return_attention_scores=False, training=None, use_causal_mask=False)
compute_output_shape(query_shape, value_shape, key_shape=None)
property ebops: int
get_config()

Returns the config of the object.

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

hgq.layers.pooling module

class hgq.layers.pooling.QAveragePooling1D(*args, **kwargs)

Bases: QBasePooling, AveragePooling1D

get_config()

Returns the config of the object.

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

class hgq.layers.pooling.QAveragePooling2D(*args, **kwargs)

Bases: QBasePooling, AveragePooling2D

get_config()

Returns the config of the object.

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

class hgq.layers.pooling.QAveragePooling3D(*args, **kwargs)

Bases: QBasePooling, AveragePooling3D

get_config()

Returns the config of the object.

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

class hgq.layers.pooling.QGlobalAveragePooling1D(*args, **kwargs)

Bases: QBasePooling, GlobalAveragePooling1D

get_config()

Returns the config of the object.

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

class hgq.layers.pooling.QGlobalAveragePooling2D(*args, **kwargs)

Bases: QBasePooling, GlobalAveragePooling2D

get_config()

Returns the config of the object.

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

class hgq.layers.pooling.QGlobalAveragePooling3D(*args, **kwargs)

Bases: QBasePooling, GlobalAveragePooling3D

get_config()

Returns the config of the object.

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

class hgq.layers.pooling.QGlobalMaxPooling1D(*args, **kwargs)

Bases: QBasePooling, GlobalMaxPooling1D

get_config()

Returns the config of the object.

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

class hgq.layers.pooling.QGlobalMaxPooling2D(*args, **kwargs)

Bases: QBasePooling, GlobalMaxPooling2D

get_config()

Returns the config of the object.

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

class hgq.layers.pooling.QGlobalMaxPooling3D(*args, **kwargs)

Bases: QBasePooling, GlobalMaxPooling3D

get_config()

Returns the config of the object.

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

class hgq.layers.pooling.QMaxPooling1D(*args, **kwargs)

Bases: QBasePooling, MaxPooling1D

get_config()

Returns the config of the object.

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

class hgq.layers.pooling.QMaxPooling2D(*args, **kwargs)

Bases: QBasePooling, MaxPooling2D

get_config()

Returns the config of the object.

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

class hgq.layers.pooling.QMaxPooling3D(*args, **kwargs)

Bases: QBasePooling, MaxPooling3D

get_config()

Returns the config of the object.

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

hgq.layers.softmax module

class hgq.layers.softmax.QSoftmax(*args, **kwargs)

Bases: QLayerBaseSingleInput

build(input_shape)
call(inputs, training=None, mask=None)
compute_output_shape(input_shape)
property ebops
get_config()

Returns the config of the object.

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

Module contents

class hgq.layers.QAdd(*args, **kwargs)

Bases: QMerge, Add

get_config()

Returns the config of the object.

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

class hgq.layers.QAveragePooling1D(*args, **kwargs)

Bases: QBasePooling, AveragePooling1D

get_config()

Returns the config of the object.

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

class hgq.layers.QAveragePooling2D(*args, **kwargs)

Bases: QBasePooling, AveragePooling2D

get_config()

Returns the config of the object.

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

class hgq.layers.QAveragePooling3D(*args, **kwargs)

Bases: QBasePooling, AveragePooling3D

get_config()

Returns the config of the object.

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

class hgq.layers.QAveragePow2(*args, **kwargs)

Bases: QAdd, Average

build(input_shape)
get_config()

Returns the config of the object.

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

hgq.layers.QAvgPool1D

alias of QAveragePooling1D

hgq.layers.QAvgPool2D

alias of QAveragePooling2D

hgq.layers.QAvgPool3D

alias of QAveragePooling3D

class hgq.layers.QBatchNormDense(*args, **kwargs)

Bases: QDense

build(input_shape)
call(inputs, training=None)
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_fused_qkernel_and_qbias(mean, var)
property qbias
property qkernel
class hgq.layers.QBatchNormalization(*args, **kwargs)

Bases: QLayerBaseSingleInput, BatchNormalization

property beta
property bq
build(input_shape)
call(inputs, training=None, mask=None)
property gamma
get_config()

Returns the config of the object.

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

property kq
property qscaler_and_qoffset
class hgq.layers.QConv1D(*args, **kwargs)

Bases: QBaseConv

call(inputs, training=None)
get_config()

Returns the config of the object.

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

class hgq.layers.QConv2D(*args, **kwargs)

Bases: QBaseConv

get_config()

Returns the config of the object.

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

class hgq.layers.QConv3D(*args, **kwargs)

Bases: QBaseConv

get_config()

Returns the config of the object.

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

class hgq.layers.QDense(*args, **kwargs)

Bases: QLayerBaseSingleInput, Dense

property bq
build(input_shape)
call(inputs, training=None)
get_config()

Returns the config of the object.

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

property kq
property qbias
property qkernel
class hgq.layers.QDot(*args, **kwargs)

Bases: QMerge, Dot

build(input_shape)
get_config()

Returns the config of the object.

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

class hgq.layers.QEinsum(*args, **kwargs)

Bases: QLayerBaseMultiInputs

build(input_shape)
call(inputs, training=None)
get_config()

Returns the config of the object.

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

class hgq.layers.QEinsumDense(*args, **kwargs)

Bases: QLayerBaseSingleInput, EinsumDense

property bq
build(input_shape)
call(inputs, training=None)
get_config()

Returns the config of the object.

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

property kq
property qbias
property qkernel
class hgq.layers.QEinsumDenseBatchnorm(*args, **kwargs)

Bases: QEinsumDense

property bq
build(input_shape)
call(inputs, training=None)
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_fused_qkernel_and_qbias(training, mean, var)
property kq
property qbias
property qkernel
class hgq.layers.QGlobalAveragePooling1D(*args, **kwargs)

Bases: QBasePooling, GlobalAveragePooling1D

get_config()

Returns the config of the object.

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

class hgq.layers.QGlobalAveragePooling2D(*args, **kwargs)

Bases: QBasePooling, GlobalAveragePooling2D

get_config()

Returns the config of the object.

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

class hgq.layers.QGlobalAveragePooling3D(*args, **kwargs)

Bases: QBasePooling, GlobalAveragePooling3D

get_config()

Returns the config of the object.

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

hgq.layers.QGlobalAvgPool1D

alias of QGlobalAveragePooling1D

hgq.layers.QGlobalAvgPool2D

alias of QGlobalAveragePooling2D

hgq.layers.QGlobalAvgPool3D

alias of QGlobalAveragePooling3D

hgq.layers.QGlobalMaxPool1D

alias of QGlobalMaxPooling1D

hgq.layers.QGlobalMaxPool2D

alias of QGlobalMaxPooling2D

hgq.layers.QGlobalMaxPool3D

alias of QGlobalMaxPooling3D

class hgq.layers.QGlobalMaxPooling1D(*args, **kwargs)

Bases: QBasePooling, GlobalMaxPooling1D

get_config()

Returns the config of the object.

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

class hgq.layers.QGlobalMaxPooling2D(*args, **kwargs)

Bases: QBasePooling, GlobalMaxPooling2D

get_config()

Returns the config of the object.

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

class hgq.layers.QGlobalMaxPooling3D(*args, **kwargs)

Bases: QBasePooling, GlobalMaxPooling3D

get_config()

Returns the config of the object.

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

class hgq.layers.QLinformerAttention(*args, **kwargs)

Bases: QMultiHeadAttention

build(query_shape, value_shape, key_shape=None)

Builds layers and variables.

Parameters:
  • query_shape (tuple) – Shape of the query tensor.

  • value_shape (tuple) – Shape of the value tensor.

  • key_shape (tuple, optional) – Shape of the key tensor.

call(query, value, key=None, query_mask=None, value_mask=None, key_mask=None, attention_mask=None, return_attention_scores=False, training=None, use_causal_mask=False)
property ebops: int
get_config()

Returns the config of the object.

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

hgq.layers.QMaxPool1D

alias of QMaxPooling1D

hgq.layers.QMaxPool2D

alias of QMaxPooling2D

hgq.layers.QMaxPool3D

alias of QMaxPooling3D

class hgq.layers.QMaxPooling1D(*args, **kwargs)

Bases: QBasePooling, MaxPooling1D

get_config()

Returns the config of the object.

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

class hgq.layers.QMaxPooling2D(*args, **kwargs)

Bases: QBasePooling, MaxPooling2D

get_config()

Returns the config of the object.

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

class hgq.layers.QMaxPooling3D(*args, **kwargs)

Bases: QBasePooling, MaxPooling3D

get_config()

Returns the config of the object.

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

class hgq.layers.QMaximum(*args, **kwargs)

Bases: QMerge, Maximum

get_config()

Returns the config of the object.

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

class hgq.layers.QMeanPow2(*args, **kwargs)

Bases: QSum

build(input_shape)
get_config()

Returns the config of the object.

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

class hgq.layers.QMinimum(*args, **kwargs)

Bases: QMerge, Minimum

get_config()

Returns the config of the object.

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

class hgq.layers.QMultiHeadAttention(*args, **kwargs)

Bases: MultiHeadAttention, QLayerBase

build(query_shape, value_shape, key_shape=None)

Builds layers and variables.

Parameters:
  • query_shape (tuple) – Shape of the query tensor.

  • value_shape (tuple) – Shape of the value tensor.

  • key_shape (tuple, optional) – Shape of the key tensor.

call(query, value, key=None, query_mask=None, value_mask=None, key_mask=None, attention_mask=None, return_attention_scores=False, training=None, use_causal_mask=False)
compute_output_shape(query_shape, value_shape, key_shape=None)
property ebops: int
get_config()

Returns the config of the object.

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

class hgq.layers.QMultiply(*args, **kwargs)

Bases: QMerge, Multiply

get_config()

Returns the config of the object.

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

class hgq.layers.QSoftmax(*args, **kwargs)

Bases: QLayerBaseSingleInput

build(input_shape)
call(inputs, training=None, mask=None)
compute_output_shape(input_shape)
property ebops
get_config()

Returns the config of the object.

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

class hgq.layers.QSubtract(*args, **kwargs)

Bases: QMerge, Subtract

get_config()

Returns the config of the object.

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

class hgq.layers.QSum(*args, **kwargs)

Bases: QLayerBaseSingleInput

build(input_shape)
call(inputs, training=None)
get_config()

Returns the config of the object.

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

property keepdims
property scale
class hgq.layers.QUnaryFunctionLUT(*args, **kwargs)

Bases: Activation, QLayerBaseSingleInput

call(inputs, training=None)
get_config()

Returns the config of the object.

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

class hgq.layers.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