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
Functions
|
Creates a TunableDict from a regular dict. |
Module Contents
- class mlos_bench.tunables.tunable_types.DistributionDict(*args, **kwargs)[source]
Bases:
DistributionDictOpt
A
TypedDict
for aTunable
parameter’s requireddistribution
config 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:
TypedDict
A
TypedDict
for aTunable
parameter’s optionaldistribution_params
config.Mostly used for type checking. These are the types expected to be received from the json config.
Notes
DistributionDict
contains the required fields for theTunable.distribution
parameter.See also
Tunable.distribution_params
:Examples of distribution parameters.
- class mlos_bench.tunables.tunable_types.TunableDict(*args, **kwargs)[source]
Bases:
TunableDictOpt
A
TypedDict
for aTunable
parameter’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
Tunable
parameter.See also
- type: TunableValueTypeName[source]
The name of the type of the
Tunable
parameter.See also
Tunable.type
: Examples of type names.
- class mlos_bench.tunables.tunable_types.TunableDictOpt(*args, **kwargs)[source]
Bases:
TypedDict
A
TypedDict
for aTunable
parameter’s optional config parameters.Mostly used for type checking. These are the types expected to be received from the json config.
Notes
TunableDict
contains the required fields for theTunable
parameter.- distribution: DistributionDict | None[source]
Optional sampling distribution configuration for an “int” or “float” type
Tunable
parameter.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
Tunable
parameter.See also
- meta: dict[str, Any][source]
Free form dict to store additional metadata for the
Tunable
parameter (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
Tunable
parameter.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
Tunable
parameter.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
Tunable
parameter.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
Tunable
parameter.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
Tunable
parameter.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
Tunable
from 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
distribution
type names for aTunable
value.See also
Tunable.distribution
:Example of accepted distribution names.
- mlos_bench.tunables.tunable_types.TUNABLE_DTYPE: dict[TunableValueTypeName, TunableValueType][source]
Maps
Tunable
types 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
TypeAlias
for aTunable
parameter value.
- type mlos_bench.tunables.tunable_types.TunableValueType = type[int] | type[float] | type[str][source]
A
TypeAlias
forTunable
valuedata type
.See also
Tunable.dtype
: Example of accepted types.
- mlos_bench.tunables.tunable_types.TunableValueTypeName[source]
The accepted string names of a
Tunable
valuetype
.See also
Tunable.type
: Example of accepted type names.
- mlos_bench.tunables.tunable_types.TunableValueTypeTuple[source]
Tunable value
type
tuple.Notes
For checking whether a param is a
TunableValue
withisinstance()
.