hgq.utils package
Subpackages
- hgq.utils.sugar package
- Submodules
- hgq.utils.sugar.beta_pid module
- hgq.utils.sugar.beta_scheduler module
- hgq.utils.sugar.early_stopping_ebops module
- hgq.utils.sugar.ebops module
- hgq.utils.sugar.pareto module
- hgq.utils.sugar.pbar module
- Module contents
Submodules
hgq.utils.dataset module
hgq.utils.minmax_trace module
- class hgq.utils.minmax_trace.TrainingFlagWrapper(value)
Bases:
object
- hgq.utils.minmax_trace.trace_minmax(model: Model, data: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | Sequence[_Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]] | PyDataset, reset=True, batch_size=1024, verbose: int | bool = 0, return_results=False) int | ndarray[tuple[Any, ...], dtype[_ScalarT]] | tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], ...]
With a calibration dataset, find the necessary integer bits required for the quantizers in a model. Only needed if WRAP overflow mode is used anywhere for the activation quantizers.
- Parameters:
model (keras.Model) – The model to trace.
data (ArrayLike or Sequence[ArrayLike] or PyDataset) – The calibration dataset.
reset (bool, default True) – Whether to reset the min/max values before tracing. Set to False if you want to continue tracing from previous values.
batch_size (int, default 1024) – The batch size to use for tracing.
verbose (int or bool, default 0) – If not o or False, print the EBOPs for each layer after tracing. If > 1 or True, show a progress bar during tracing.
return_results (bool, default False) – If True, return the model outputs on the calibration dataset. If False, return the total EBOPs.
hgq.utils.misc module
- hgq.utils.misc.gather_vars_to_kwargs(skip_pattern=None) dict[str, Any]
Gather all local variables in the calling function and return them as a dictionary. If a variable is named kwargs, it will be updated with the rest of the variables. This function is useful for initializing classes with a large number of arguments.
- Parameters:
skip_pattern (str, optional) – A regular expression pattern to match variables to skip. If a variable matches the pattern, it will not be included in the returned dictionary. The default is None.
- Returns:
A dictionary containing all local variables in the calling function, except for those that start and end with double underscores.
- Return type:
dict[str, Any]
- hgq.utils.misc.warn_no_synth(conf: bool, msg: str)
hgq.utils.singleton module
- class hgq.utils.singleton.Singleton
Bases:
type
Module contents
- hgq.utils.trace_minmax(model: Model, data: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | Sequence[_Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]] | PyDataset, reset=True, batch_size=1024, verbose: int | bool = 0, return_results=False) int | ndarray[tuple[Any, ...], dtype[_ScalarT]] | tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], ...]
With a calibration dataset, find the necessary integer bits required for the quantizers in a model. Only needed if WRAP overflow mode is used anywhere for the activation quantizers.
- Parameters:
model (keras.Model) – The model to trace.
data (ArrayLike or Sequence[ArrayLike] or PyDataset) – The calibration dataset.
reset (bool, default True) – Whether to reset the min/max values before tracing. Set to False if you want to continue tracing from previous values.
batch_size (int, default 1024) – The batch size to use for tracing.
verbose (int or bool, default 0) – If not o or False, print the EBOPs for each layer after tracing. If > 1 or True, show a progress bar during tracing.
return_results (bool, default False) – If True, return the model outputs on the calibration dataset. If False, return the total EBOPs.