IVORY.CORE.RUN
This module provides the Run
class that is one of the main classes of
Ivory library. In addition, Task
and Study
classes are defined, which manages
multiple runs for cross validation, hyperparameter tuning, and so on.
To create an Run
instance:
import ivory
client = ivory.create_run('example')
The argument example
is an experiment name in which the created run is included.
Ivory assumes that example.yml
or example.yaml
file exists under the client's
working directory.
You can comfirm the client's working directory by:
os.path.dirname(client.source_name)
One you got a Run
instance. call Run.start()
to start training. For test,
call Run.start('test')
instead. Also, you can perform traing and test by one step
with Run.start('both')
.
ivory.core.run.
Run
(
params=None
, **instances
)
Run class is one of the main classes of Ivory library.
params
(optional) — Parameter dictionary to create this instance.**instances
— Member instances. Key is its name and value is the member instance.
dict
—id
(str) — Instance ID given by MLFlow Tracking.mode
—name
(str) — Instance name.params
(dict, optional) — Parameter dictionary that is used to to create this instance.source_name
(str) — Name of the YAML parameter file that is used to create this instance.
create_callbacks
(
)
— Creates callback functions and store them in a dictionary.</>create_instance
(
instance_name
,args
,name
,**kwargs
)
— Creates an member instance of aRun
according to arguments.</>create_params
(
args
,name
,**kwargs
)
(dict, dict) — Returns a tuple of (parameter dictionary, update dictionary).</>create_run
(
args
,name
,**kwargs
)
(Run) — Creates aRun
instance according to arguments.</>load
(
directory
)
(dict(str: any)) — Loads member instances.</>load_state_dict
(
state_dict
)
— Loads a state dictionary to all of member instances.</>save
(
directory
)
— Saves member instances.</>set_tracker
(
tracker
,name
)
— Sets tracker for tracking.</>start
(
mode
)
— Starts traing and/or test.</>state_dict
(
)
(dict) — Returns a state dictionary for all of member instances.</>
create_params
(
args=None
, name='run'
, **kwargs
)
→ (dict, dict)
Returns a tuple of (parameter dictionary, update dictionary).
The parameter dictionary is deeply copied from original one, then updated according to the arguments. The update dictionary includes updated parameter only.
args
(dict, optional) — Update dictionary.name
(str, optional) — Run class name in lower case.**kwargs
— Additional update dictionary.
Use args
for parameters including dots:
params, update = experiment.create_params(
{'hidden_sizes.0': 100}, fold=3
)
The params
is the full parameter dictionary, while the update
is a
part of params
, i.e., update = {'hidden_sizes.0': 100, 'fold': 3}
.
create_run
(
args=None
, name='run'
, **kwargs
)
Creates a Run
instance according to arguments.
args
(dict, optional) — Update dictionary.name
(str, optional) — Run class name in lower case.**kwargs
— Additional update dictionary.
Created Run
instance. The parameter for this instance is the
returned dictionary from the
create_params()
function.
create_instance
(
instance_name
, args=None
, name='run'
, **kwargs
)
Creates an member instance of a Run
according to arguments.
instance_name
(str) — Name of a member instance to create.args
(dict, optional) — Update dictionary.name
(optional) — Run class name in lower case.**kwargs
— Additional update dictionary.
Created instance. The parameter for this instance is the
returned directory from the
create_params()
function.
create_callbacks
(
)
Creates callback functions and store them in a dictionary.
set_tracker
(
tracker
, name
)
Sets tracker for tracking.
By setting a tracker, a Run
instance can be a run of MLFlow Tracking
at the same time. MLFlow Tracking gives the Run ID and name for this
instance.
tracker
(Tracker) — Tracker instance.name
(str) —
start
(
mode='train'
)
Starts traing and/or test.
mode
(str, optional) — Mode name:'train'
,'test'
, or'both'
.
state_dict
(
)
→ dict
Returns a state dictionary for all of member instances.
load_state_dict
(
state_dict
)
Loads a state dictionary to all of member instances.
state_dict
(dict) — state dictionary for all of member instances.
save
(
directory
)
Saves member instances.
directory
(str) — Directory where member instances are saved.
load
(
directory
)
→ dict(str: any)
Loads member instances.
directory
(str) — Directory where member instances have been saved.
ivory.core.run.
Task
(
params=None
, **instances
)
Task class creates a parent run that generates multiple runs.
params
(optional) — Parameter dictionary to create this instance.**instances
— Member instances. Key is its name and value is the member instance.
dict
—id
(str) — Instance ID given by MLFlow Tracking.mode
—name
(str) — Instance name.params
(dict, optional) — Parameter dictionary that is used to to create this instance.source_name
(str) — Name of the YAML parameter file that is used to create this instance.
chain
(
params
,use_best_param
,**kwargs
)
(Run) — Makes a chain iterator.</>create_callbacks
(
)
— Creates callback functions and store them in a dictionary.</>create_instance
(
instance_name
,args
,name
,**kwargs
)
— Creates an member instance of aRun
according to arguments.</>create_params
(
args
,name
,**kwargs
)
(dict, dict) — Returns a tuple of (parameter dictionary, update dictionary).</>create_run
(
args
,**kwargs
)
(Run) — Create a nested run according to arguments</>load
(
directory
)
(dict(str: any)) — Loads member instances.</>load_state_dict
(
state_dict
)
— Loads a state dictionary to all of member instances.</>product
(
params
,repeat
,**kwargs
)
(Run) — Makes a product iterator.</>save
(
directory
)
— Saves member instances.</>set_tracker
(
tracker
,name
)
— Sets tracker for tracking.</>start
(
mode
)
— Starts traing and/or test.</>state_dict
(
)
(dict) — Returns a state dictionary for all of member instances.</>
create_params
(
args=None
, name='run'
, **kwargs
)
→ (dict, dict)
Returns a tuple of (parameter dictionary, update dictionary).
The parameter dictionary is deeply copied from original one, then updated according to the arguments. The update dictionary includes updated parameter only.
args
(dict, optional) — Update dictionary.name
(str, optional) — Run class name in lower case.**kwargs
— Additional update dictionary.
Use args
for parameters including dots:
params, update = experiment.create_params(
{'hidden_sizes.0': 100}, fold=3
)
The params
is the full parameter dictionary, while the update
is a
part of params
, i.e., update = {'hidden_sizes.0': 100, 'fold': 3}
.
create_instance
(
instance_name
, args=None
, name='run'
, **kwargs
)
Creates an member instance of a Run
according to arguments.
instance_name
(str) — Name of a member instance to create.args
(dict, optional) — Update dictionary.name
(optional) — Run class name in lower case.**kwargs
— Additional update dictionary.
Created instance. The parameter for this instance is the
returned directory from the
create_params()
function.
create_callbacks
(
)
Creates callback functions and store them in a dictionary.
set_tracker
(
tracker
, name
)
Sets tracker for tracking.
By setting a tracker, a Run
instance can be a run of MLFlow Tracking
at the same time. MLFlow Tracking gives the Run ID and name for this
instance.
tracker
(Tracker) — Tracker instance.name
(str) —
start
(
mode='train'
)
Starts traing and/or test.
mode
(str, optional) — Mode name:'train'
,'test'
, or'both'
.
state_dict
(
)
→ dict
Returns a state dictionary for all of member instances.
load_state_dict
(
state_dict
)
Loads a state dictionary to all of member instances.
state_dict
(dict) — state dictionary for all of member instances.
save
(
directory
)
Saves member instances.
directory
(str) — Directory where member instances are saved.
load
(
directory
)
→ dict(str: any)
Loads member instances.
directory
(str) — Directory where member instances have been saved.
create_run
(
args
, **kwargs
)
Create a nested run according to arguments
args
(dict, optional) — Update dictionary.**kwargs
— Additional update dictionary.
Created nested Run
instance.
Makes a product iterator.
This iterator returns runs from cartesian product of input parameters.
params
(dict, optional) — Parameter range. Key is a parameter name and value is an iterable of parameter's value.repeat
(int, optional) — Number of repeatation.**kwargs
— Additional parameter range.
Product section in Multiple Runs Tutorial
Makes a chain iterator.
This iterator returns runs from the first input paramter until it is exhausted, then proceeds to the next parameter, until all of the parameters are exhausted. Other parameters have default values if they don't be specified by additional key-value pairs.
params
(dict, optional) — Parameter range. Key is a parameter name and value is an iterable of parameter's value. use_best_param: If True (default), the parameter that got the best score is used during the following iterations.use_best_param
(bool, optional) —**kwargs
— Additional parameter range.
Chain section in Multiple Runs Tutorial
ivory.core.run.
Study
(
params=None
, **instances
)
Study class create a parent run to manage hyperparameter tuning.
params
(optional) — Parameter dictionary to create this instance.**instances
— Member instances. Key is its name and value is the member instance.
dict
—id
(str) — Instance ID given by MLFlow Tracking.mode
—name
(str) — Instance name.params
(dict, optional) — Parameter dictionary that is used to to create this instance.source_name
(str) — Name of the YAML parameter file that is used to create this instance.
chain
(
params
,use_best_param
,**kwargs
)
(Run) — Makes a chain iterator.</>create_callbacks
(
)
— Creates callback functions and store them in a dictionary.</>create_instance
(
instance_name
,args
,name
,**kwargs
)
— Creates an member instance of aRun
according to arguments.</>create_params
(
args
,name
,**kwargs
)
(dict, dict) — Returns a tuple of (parameter dictionary, update dictionary).</>create_run
(
args
,**kwargs
)
(Run) — Create a nested run according to arguments</>load
(
directory
)
(dict(str: any)) — Loads member instances.</>load_state_dict
(
state_dict
)
— Loads a state dictionary to all of member instances.</>optimize
(
suggest_name
,**kwargs
)
— Performs parameter optimizations using Optuna.</>product
(
params
,repeat
,**kwargs
)
(Run) — Makes a product iterator.</>save
(
directory
)
— Saves member instances.</>set_tracker
(
tracker
,name
)
— Sets tracker for tracking.</>start
(
mode
)
— Starts traing and/or test.</>state_dict
(
)
(dict) — Returns a state dictionary for all of member instances.</>
create_params
(
args=None
, name='run'
, **kwargs
)
→ (dict, dict)
Returns a tuple of (parameter dictionary, update dictionary).
The parameter dictionary is deeply copied from original one, then updated according to the arguments. The update dictionary includes updated parameter only.
args
(dict, optional) — Update dictionary.name
(str, optional) — Run class name in lower case.**kwargs
— Additional update dictionary.
Use args
for parameters including dots:
params, update = experiment.create_params(
{'hidden_sizes.0': 100}, fold=3
)
The params
is the full parameter dictionary, while the update
is a
part of params
, i.e., update = {'hidden_sizes.0': 100, 'fold': 3}
.
create_instance
(
instance_name
, args=None
, name='run'
, **kwargs
)
Creates an member instance of a Run
according to arguments.
instance_name
(str) — Name of a member instance to create.args
(dict, optional) — Update dictionary.name
(optional) — Run class name in lower case.**kwargs
— Additional update dictionary.
Created instance. The parameter for this instance is the
returned directory from the
create_params()
function.
create_callbacks
(
)
Creates callback functions and store them in a dictionary.
set_tracker
(
tracker
, name
)
Sets tracker for tracking.
By setting a tracker, a Run
instance can be a run of MLFlow Tracking
at the same time. MLFlow Tracking gives the Run ID and name for this
instance.
tracker
(Tracker) — Tracker instance.name
(str) —
start
(
mode='train'
)
Starts traing and/or test.
mode
(str, optional) — Mode name:'train'
,'test'
, or'both'
.
state_dict
(
)
→ dict
Returns a state dictionary for all of member instances.
load_state_dict
(
state_dict
)
Loads a state dictionary to all of member instances.
state_dict
(dict) — state dictionary for all of member instances.
save
(
directory
)
Saves member instances.
directory
(str) — Directory where member instances are saved.
load
(
directory
)
→ dict(str: any)
Loads member instances.
directory
(str) — Directory where member instances have been saved.
create_run
(
args
, **kwargs
)
Create a nested run according to arguments
args
(dict, optional) — Update dictionary.**kwargs
— Additional update dictionary.
Created nested Run
instance.
Makes a product iterator.
This iterator returns runs from cartesian product of input parameters.
params
(dict, optional) — Parameter range. Key is a parameter name and value is an iterable of parameter's value.repeat
(int, optional) — Number of repeatation.**kwargs
— Additional parameter range.
Product section in Multiple Runs Tutorial
Makes a chain iterator.
This iterator returns runs from the first input paramter until it is exhausted, then proceeds to the next parameter, until all of the parameters are exhausted. Other parameters have default values if they don't be specified by additional key-value pairs.
params
(dict, optional) — Parameter range. Key is a parameter name and value is an iterable of parameter's value. use_best_param: If True (default), the parameter that got the best score is used during the following iterations.use_best_param
(bool, optional) —**kwargs
— Additional parameter range.
Chain section in Multiple Runs Tutorial
optimize
(
suggest_name=''
, **kwargs
)
Performs parameter optimizations using Optuna.
suggest_name
(str, optional) — Name of suggest function.**kwargs
— Key-iterable pairs for parametric optimization.
Hyperparameter Tuning in Tutorial