mlos_bench.tunables.tunable_types
Helper types for Tunable.
The main class of interest to most users in this module is TunableDict,
which provides the typed conversions from a JSON config to a config used for
creating a Tunable.
The other types are mostly used for type checking and documentation purposes.
Attributes
The |
|
Maps |
|
A |
|
A |
|
Tunable value |
|
Tunable values dictionary type. |
Classes
A |
|
A |
|
A |
|
A |
Functions
|
Creates a TunableDict from a regular dict. |
Module Contents
- class mlos_bench.tunables.tunable_types.DistributionDict(*args, **kwargs)[source]
Bases:
DistributionDictOptA
TypedDictfor aTunableparameter’s requireddistributionconfig parameters.Mostly used for type checking. These are the types expected to be received from the json config.
See also
Tunable.distribution:Examples of Tunables with distributions.
Tunable.distribution_params:Examples of distribution parameters.
- type: DistributionName[source]
The name of the distribution.
See also
Tunable.distribution:Examples of distribution names.
- class mlos_bench.tunables.tunable_types.DistributionDictOpt(*args, **kwargs)[source]
Bases:
TypedDictA
TypedDictfor aTunableparameter’s optionaldistribution_paramsconfig.Mostly used for type checking. These are the types expected to be received from the json config.
Notes
DistributionDictcontains the required fields for theTunable.distributionparameter.See also
Tunable.distribution_params:Examples of distribution parameters.
- class mlos_bench.tunables.tunable_types.TunableDict(*args, **kwargs)[source]
Bases:
TunableDictOptA
TypedDictfor aTunableparameter’s required config parameters.Mostly used for type checking. These are the types expected to be received from the json config.
Examples
>>> # Example values of the TunableDict >>> TunableDict({'type': 'int', 'default': 0, 'range': [0, 10]}) {'type': 'int', 'default': 0, 'range': [0, 10]}
>>> # Example values of the TunableDict with optional fields >>> TunableDict({'type': 'categorical', 'default': 'a', 'values': ['a', 'b']}) {'type': 'categorical', 'default': 'a', 'values': ['a', 'b']}
- default: TunableValue[source]
The default value of the
Tunableparameter.See also
- type: TunableValueTypeName[source]
The name of the type of the
Tunableparameter.See also
Tunable.type: Examples of type names.
- class mlos_bench.tunables.tunable_types.TunableDictOpt(*args, **kwargs)[source]
Bases:
TypedDictA
TypedDictfor aTunableparameter’s optional config parameters.Mostly used for type checking. These are the types expected to be received from the json config.
Notes
TunableDictcontains the required fields for theTunableparameter.- distribution: DistributionDict | None[source]
Optional sampling distribution configuration for an “int” or “float” type
Tunableparameter.See also
Tunable.distribution:Examples of distributions.
Tunable.distribution_params:Examples of distribution parameters.
- log: bool | None[source]
Whether to use log sampling for an “int” or “float” type
Tunableparameter.See also
- meta: dict[str, Any][source]
Free form dict to store additional metadata for the
Tunableparameter (e.g., unit suffix, etc.)See also
Tunable.meta: Examples of Tunables with metadata.
- quantization_bins: int | None[source]
The number of quantization bins for an “int” or “float” type
Tunableparameter.See also
Tunable.quantization_bins:Examples of quantized Tunables.
- range: collections.abc.Sequence[int] | collections.abc.Sequence[float] | None[source]
The range of values for an “int” or “float” type
Tunableparameter.Must be a sequence of two values:
[min, max].A range is required for “int” and “float” type Tunables.
See also
Tunable.range: Examples of ranges.Tunable.values
- range_weight: float | None[source]
Optional sampling weight for the main ranges of an “int” or “float” type
Tunableparameter.See also
Tunable.range_weight:Examples of weighted sampling Tunables.
- special: list[int] | list[float] | None[source]
List of special values for an “int” or “float” type
Tunableparameter.These are values that are considered special by the target system (e.g.,
null,0,-1,auto, etc.) and should be sampled with higher weights.See also
Tunable.special: Examples of special values.
- special_weights: list[float] | None[source]
Optional sampling weights for the special values of an “int” or “float” type
Tunableparameter.See also
Tunable.weights: Examples of weighted sampling Tunables.
- mlos_bench.tunables.tunable_types.tunable_dict_from_dict(config: dict[str, Any]) TunableDict[source]
Creates a TunableDict from a regular dict.
Notes
Mostly used for type checking while instantiating a
Tunablefrom a json config.- Parameters:
config (dict[str, Any]) – A regular dict that represents a
TunableDict.- Return type:
Examples
>>> # Example values of the TunableDict >>> import json5 as json >>> config = json.loads("{'type': 'int', 'default': 0, 'range': [0, 10]}") >>> config {'type': 'int', 'default': 0, 'range': [0, 10]} >>> typed_dict = tunable_dict_from_dict(config) >>> typed_dict {'type': 'int', 'description': None, 'default': 0, 'values': None, 'range': [0, 10], 'quantization_bins': None, 'log': None, 'distribution': None, 'special': None, 'values_weights': None, 'special_weights': None, 'range_weight': None, 'meta': {}}
- mlos_bench.tunables.tunable_types.DistributionName[source]
The
distributiontype names for aTunablevalue.See also
Tunable.distribution:Example of accepted distribution names.
- mlos_bench.tunables.tunable_types.TUNABLE_DTYPE: dict[TunableValueTypeName, TunableValueType][source]
Maps
Tunabletypes to their corresponding Python data types by name.See also
Tunable.dtype: Example of type mappings.
- type mlos_bench.tunables.tunable_types.TunableValue = int | float | str | None[source]
A
TypeAliasfor aTunableparameter value.
- type mlos_bench.tunables.tunable_types.TunableValueType = type[int] | type[float] | type[str][source]
A
TypeAliasforTunablevaluedata type.See also
Tunable.dtype: Example of accepted types.
- mlos_bench.tunables.tunable_types.TunableValueTypeName[source]
The accepted string names of a
Tunablevaluetype.See also
Tunable.type: Example of accepted type names.
- mlos_bench.tunables.tunable_types.TunableValueTypeTuple[source]
Tunable value
typetuple.Notes
For checking whether a param is a
TunableValuewithisinstance().