hgq.layers package
Subpackages
- hgq.layers.core package
- Submodules
- hgq.layers.core.base module
MultipleQuantizersQLayerBaseQLayerBase.betaQLayerBase.build()QLayerBase.ebopsQLayerBase.enable_ebopsQLayerBase.enable_iqQLayerBase.enable_lora()QLayerBase.enable_oqQLayerBase.from_config()QLayerBase.get_config()QLayerBase.load_own_variables()QLayerBase.oqQLayerBase.save_own_variables()QLayerBase.try_build_output_quantizer()
QLayerBaseMultiInputsQLayerBaseSingleInputQLayerMetacheck_save_load_own_variables()get_method_source()
- hgq.layers.core.dense module
- hgq.layers.core.einsum_dense module
- Module contents
QBatchNormDenseQDenseQEinsumDenseQLayerBaseQLayerBase.betaQLayerBase.build()QLayerBase.ebopsQLayerBase.enable_ebopsQLayerBase.enable_iqQLayerBase.enable_lora()QLayerBase.enable_oqQLayerBase.from_config()QLayerBase.get_config()QLayerBase.load_own_variables()QLayerBase.oqQLayerBase.save_own_variables()QLayerBase.try_build_output_quantizer()
QLayerBaseMultiInputsQLayerBaseSingleInput
- hgq.layers.ops package
- hgq.layers.rnn package
- Submodules
- hgq.layers.rnn.gru module
QGRUQGRUCellQGRUCell.bqQGRUCell.build()QGRUCell.call()QGRUCell.enable_ebopsQGRUCell.get_config()QGRUCell.get_initial_state()QGRUCell.iqQGRUCell.kqQGRUCell.paqQGRUCell.praqQGRUCell.qactivation()QGRUCell.qbiasQGRUCell.qkernelQGRUCell.qrecurrent_activation()QGRUCell.qrecurrent_kernelQGRUCell.rhqQGRUCell.rkqQGRUCell.sq
- hgq.layers.rnn.simple_rnn module
QRNNQSimpleRNNQSimpleRNNCellQSimpleRNNCell.bqQSimpleRNNCell.build()QSimpleRNNCell.call()QSimpleRNNCell.enable_ebopsQSimpleRNNCell.enable_sqQSimpleRNNCell.get_config()QSimpleRNNCell.iqQSimpleRNNCell.kqQSimpleRNNCell.paqQSimpleRNNCell.qbiasQSimpleRNNCell.qkernelQSimpleRNNCell.qrecurrent_kernelQSimpleRNNCell.rkqQSimpleRNNCell.sq
- Module contents
QGRUQGRUCellQGRUCell.bqQGRUCell.build()QGRUCell.call()QGRUCell.enable_ebopsQGRUCell.get_config()QGRUCell.get_initial_state()QGRUCell.iqQGRUCell.kqQGRUCell.paqQGRUCell.praqQGRUCell.qactivation()QGRUCell.qbiasQGRUCell.qkernelQGRUCell.qrecurrent_activation()QGRUCell.qrecurrent_kernelQGRUCell.rhqQGRUCell.rkqQGRUCell.sq
QSimpleRNNQSimpleRNNCellQSimpleRNNCell.bqQSimpleRNNCell.build()QSimpleRNNCell.call()QSimpleRNNCell.enable_ebopsQSimpleRNNCell.enable_sqQSimpleRNNCell.get_config()QSimpleRNNCell.iqQSimpleRNNCell.kqQSimpleRNNCell.paqQSimpleRNNCell.qbiasQSimpleRNNCell.qkernelQSimpleRNNCell.qrecurrent_kernelQSimpleRNNCell.rkqQSimpleRNNCell.sq
- hgq.layers.table package
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.
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.
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.QDenseT(*args, **kwargs)
Bases:
QLayerBaseSingleInput- build(input_shape)
- call(x, 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 toq
- 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.QGRU(*args, **kwargs)
Bases:
QRNN,GRUGated Recurrent Unit - Cho et al. 2014.
The QGRU only allows the backend native implementation (no CuDNN kernel). When the jax backend is used, if any WRAP quantizers are used, unroll will be set to True to avoid the side effect issue in the jax.lax.scan loop.
- Parameters:
units (int) – Positive integer, dimensionality of the output space.
activation (str, optional) – Activation function to use. Default: linear, effectively hard_tanh by the pre-activation quantizer.
recurrent_activation (str, optional) – Activation function to use for the recurrent step. Default: linear, effectively hard_sigmoid (slope=0.5) by the pre-activation quantizer.
use_bias (bool, optional) – Whether the layer should use a bias vector. Default: True.
kernel_initializer (str, optional) – Initializer for the kernel weights matrix, used for the linear transformation of the inputs. Default: “glorot_uniform”.
recurrent_initializer (str, optional) – Initializer for the recurrent_kernel weights matrix, used for the linear transformation of the recurrent state. Default: “orthogonal”.
bias_initializer (str, optional) – Initializer for the bias vector. Default: “zeros”.
kernel_regularizer (optional) – Regularizer function applied to the kernel weights matrix. Default: None.
recurrent_regularizer (optional) – Regularizer function applied to the recurrent_kernel weights matrix. Default: None.
bias_regularizer (optional) – Regularizer function applied to the bias vector. Default: None.
activity_regularizer (optional) – Regularizer function applied to the output of the layer (its “activation”). Default: None.
kernel_constraint (optional) – Constraint function applied to the kernel weights matrix. Default: None.
recurrent_constraint (optional) – Constraint function applied to the recurrent_kernel weights matrix. Default: None.
bias_constraint (optional) – Constraint function applied to the bias vector. Default: None.
dropout (float, optional) – Float between 0 and 1. Fraction of the units to drop for the linear transformation of the inputs. Default: 0.
recurrent_dropout (float, optional) – Float between 0 and 1. Fraction of the units to drop for the linear transformation of the recurrent state. Default: 0.
seed (int, optional) – Random seed for dropout.
return_sequences (bool, optional) – Whether to return the last output in the output sequence, or the full sequence. Default: False.
return_state (bool, optional) – Whether to return the last state in addition to the output. Default: False.
go_backwards (bool, optional) – If True, process the input sequence backwards and return the reversed sequence. Default: False.
stateful (bool, optional) – If True, the last state for each sample at index i in a batch will be used as initial state for the sample of index i in the following batch. Default: False.
unroll (bool or None, optional) – None is equivalent to False. However, for the JAX backend, if any WRAP quantizers are used, unroll will be set to True to avoid the side effect issue in the jax.lax.scan loop. If True, the network will be unrolled, else a symbolic loop will be used. Unrolling can speed-up a RNN, although it tends to be more memory-intensive. Unrolling is only suitable for short sequences. Default: None.
reset_after (bool, optional) – GRU convention (whether to apply reset gate after or before matrix multiplication). False is “before”, True is “after” (default and cuDNN compatible). Default: True.
iq_conf (QuantizerConfig or None, optional) – Quantizer configuration for input quantizer. Default: None (global default)
paq_conf (QuantizerConfig or None, optional) – Quantizer configuration for post-activation quantizer. Default: None (hard tanh like, w/ global default)
praq_conf (QuantizerConfig or None, optional) – Quantizer configuration for pre-recurrent activation quantizer. Default: None (hard sigmoid like, w/ global default)
sq_conf (QuantizerConfig or None, optional) – Quantizer configuration for state quantizer. Default: None (global default)
kq_conf (QuantizerConfig or None, optional) – Quantizer configuration for kernel quantizer. Default: None (global default)
rkq_conf (QuantizerConfig or None, optional) – Quantizer configuration for recurrent kernel quantizer. Default: None (global default)
bq_conf (QuantizerConfig or None, optional) – Quantizer configuration for bias quantizer. Default: None (global default)
oq_conf (QuantizerConfig or None, optional) – Quantizer configuration for output quantizer. Default: None (global default)
rhq_conf (QuantizerConfig or None, optional) – Quantizer configuration for recurrent hidden state quantizer. Default: None (global default)
parallelization_factor (int, optional) – Factor for parallelization. Default: 1.
enable_oq (bool or None, optional) – Whether to enable output quantizer. Default: None (global default)
enable_iq (bool or None, optional) – Whether to enable input quantizer. Default: None (global default)
enable_ebops (bool or None, optional) – Whether to enable energy-efficient bit operations. Default: None (global default)
beta0 (float or None, optional) – Beta0 parameter for quantizer. Default: None (global default)
enable_ebops – Whether to enable EBOPs resource consumption estimation. Default: None (global default).
parallelization_factor – Number of cells to be computed in parallel. Default: 1.
Notes
- inputsarray_like
A 3D tensor, with shape (batch, timesteps, feature).
- maskarray_like, optional
Binary tensor of shape (samples, timesteps) indicating whether a given timestep should be masked (optional). An individual True entry indicates that the corresponding timestep should be utilized, while a False entry indicates that the corresponding timestep should be ignored. Defaults to None.
- trainingbool, optional
Python boolean indicating whether the layer should behave in training mode or in inference mode. This argument is passed to the cell when calling it. This is only relevant if dropout or recurrent_dropout is used (optional). Defaults to None.
- initial_statelist, optional
List of initial state tensors to be passed to the first call of the cell (optional, None causes creation of zero-filled initial state tensors). Defaults to 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.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.QSimpleRNN(*args, **kwargs)
Bases:
QRNN,SimpleRNNQuantized Fully-connected RNN where the output is to be fed back as the new input.
When the jax backend is used, if any WRAP quantizers are used, unroll will be set to True to avoid the side effect issue in the jax.lax.scan loop.
- Parameters:
units (int) – Positive integer, dimensionality of the output space.
activation (str, optional) – Activation function to use. Default: linear, effectively hard_tanh by the pre-activation quantizer.
use_bias (bool, optional) – Whether the layer uses a bias vector. Default: True.
kernel_initializer (str, optional) – Initializer for the kernel weights matrix, used for the linear transformation of the inputs. Default: “glorot_uniform”.
recurrent_initializer (str, optional) – Initializer for the recurrent_kernel weights matrix, used for the linear transformation of the recurrent state. Default: “orthogonal”.
bias_initializer (str, optional) – Initializer for the bias vector. Default: “zeros”.
kernel_regularizer (optional) – Regularizer function applied to the kernel weights matrix. Default: None.
recurrent_regularizer (optional) – Regularizer function applied to the recurrent_kernel weights matrix. Default: None.
bias_regularizer (optional) – Regularizer function applied to the bias vector. Default: None.
activity_regularizer (optional) – Regularizer function applied to the output of the layer (its “activation”). Default: None.
kernel_constraint (optional) – Constraint function applied to the kernel weights matrix. Default: None.
recurrent_constraint (optional) – Constraint function applied to the recurrent_kernel weights matrix. Default: None.
bias_constraint (optional) – Constraint function applied to the bias vector. Default: None.
dropout (float, optional) – Float between 0 and 1. Fraction of the units to drop for the linear transformation of the inputs. Default: 0.
recurrent_dropout (float, optional) – Float between 0 and 1. Fraction of the units to drop for the linear transformation of the recurrent state. Default: 0.
return_sequences (bool, optional) – Whether to return the last output in the output sequence, or the full sequence. Default: False.
return_state (bool, optional) – Whether to return the last state in addition to the output. Default: False.
go_backwards (bool, optional) – If True, process the input sequence backwards and return the reversed sequence. Default: False.
stateful (bool, optional) – If True, the last state for each sample at index i in a batch will be used as initial state for the sample of index i in the following batch. Default: False.
unroll (bool or None, optional) – None is equivalent to False. However, for the JAX backend, if any WRAP quantizers are used, unroll will be set to True to avoid the side effect issue in the jax.lax.scan loop. If True, the network will be unrolled, else a symbolic loop will be used. Unrolling can speed-up a RNN, although it tends to be more memory-intensive. Unrolling is only suitable for short sequences. Default: None.
seed (int, optional) – Random seed for dropout.
iq_conf (QuantizerConfig or None, optional) – Quantizer configuration for input quantizer. Default: None.
sq_conf (QuantizerConfig or None, optional) – Quantizer configuration for state quantizer. Default: None.
kq_conf (QuantizerConfig or None, optional) – Quantizer configuration for kernel quantizer. Default: None.
rkq_conf (QuantizerConfig or None, optional) – Quantizer configuration for recurrent kernel quantizer. Default: None.
bq_conf (QuantizerConfig or None, optional) – Quantizer configuration for bias quantizer. Default: None.
oq_conf (QuantizerConfig or None, optional) – Quantizer configuration for output quantizer. Default: None.
paq_conf (QuantizerConfig or None, optional) – Quantizer configuration for pre-activation quantizer. Default: None.
parallelization_factor (int, optional) – Factor for parallelization. Default: -1 (automatic).
enable_sq (bool or None, optional) – Whether to enable state quantizer. When the output is already quantized and the state is 0-inited, the state quantizer should be disabled to avoid double quantization. Default: False.
enable_oq (bool or None, optional) – Whether to enable output quantizer. Default: None.
enable_iq (bool or None, optional) – Whether to enable input quantizer. Default: None.
enable_ebops (bool or None, optional) – Whether to enable energy-efficient bit operations. Default: None.
beta0 (float or None, optional) – Beta0 parameter for quantizer. Default: None.
Notes
- sequencearray_like
A 3D tensor, with shape [batch, timesteps, feature].
- maskarray_like, optional
Binary tensor of shape [batch, timesteps] indicating whether a given timestep should be masked. An individual True entry indicates that the corresponding timestep should be utilized, while a False entry indicates that the corresponding timestep should be ignored.
- trainingbool, optional
Python boolean indicating whether the layer should behave in training mode or in inference mode. This argument is passed to the cell when calling it. This is only relevant if dropout or recurrent_dropout is used.
- initial_statelist, optional
List of initial state tensors to be passed to the first call of the cell.
- 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:
LayerThe 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)
- property fbits
- fbits_(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