addons.tune.interface
Handles the base interface
#
BaseInterface Objectsclass BaseInterface(ABC)
Base interface for the various hyper-parameter tuner backends
Attributes
_tuner_config: spock version of the tuner configuration_tuner_namespace: tuner namespace that has attr classes that maps to an underlying library types
#
__init__def __init__(tuner_config, tuner_namespace: Spockspace)
Base init call that maps a few variables
Arguments:
tuner_config
- necessary dict object to determine the interface and sample correctly from the underlying librarytuner_namespace
- tuner namespace that has attr classes that maps to an underlying library types
#
sample@abstractmethoddef sample()
Calls the underlying library sample to get a single sample/draw from the hyper-parameter sets (e.g. ranges, choices)
Returns:
Spockspace of the current hyper-parameter draw
#
_construct@abstractmethoddef _construct()
Constructs the base object needed by the underlying library to construct the correct object that allows for hyper-parameter sampling
Returns:
flat dictionary of all hyper-parameters named with dot notation (class.param_name)
#
_get_sample@property@abstractmethoddef _get_sample()
Gets the sample parameter dictionary from the underlying backend
#
tuner_status@property@abstractmethoddef tuner_status()
Returns a dictionary of all the necessary underlying tuner internals to report the result
#
best@property@abstractmethoddef best()
Returns a Spockspace of the best hyper-parameter config and the associated metric value
#
_sample_rollup@staticmethoddef _sample_rollup(params)
Rollup the sample draw into a dictionary that can be converted to a spockspace with the correct names and roots -- un-dots the name structure
Arguments:
params
- current parameter dictionary -- named by dot notation
Returns:
dictionary of rolled up sampled parameters md5 hash of the dictionary contents
#
_gen_spockspacedef _gen_spockspace(tune_dict: Dict)
Converts a dictionary of dictionaries of parameters into a valid Spockspace
Arguments:
tune_dict
- dictionary of current parameters
Returns:
tune_dict
- Spockspace
#
_config_to_dict@staticmethoddef _config_to_dict(tuner_config: Union[OptunaTunerConfig, AxTunerConfig])
Turns an attrs config object into a dictionary
Arguments:
tuner_config
- attrs config object
Returns:
dictionary of the attrs config object
#
_to_spockspace@staticmethoddef _to_spockspace(tune_dict: Dict)
Converts a dict to a Spockspace
Arguments:
tune_dict
- current dictionary
Returns:
Spockspace of dict
#
_get_caster@staticmethoddef _get_caster(val)
Gets a callable type object from a string type
Arguments:
val
- current attr val:
Returns:
type class object
#
_try_choice_castdef _try_choice_cast(val, type_string: str)
Try/except for casting choice parameters
Arguments:
val
- current attr valtype_string
- spock hyper-parameter type name
Returns:
val
- updated attr val
#
_try_range_castdef _try_range_cast(val, type_string: str)
Casting range parameters
Note that we don't need to try/except here as the range is already constrained to be a float/int which will always be able to be cast into float/int
Arguments:
val
- current attr valtype_string
- spock hyper-parameter type name
Returns:
low
- low boundhigh
- high bound