multiml.agent.basic package
Submodules
Module contents
- class multiml.agent.basic.BaseAgent(saver=None, storegate=None, task_scheduler=None, metric=None, metric_args=None)
Bases:
Agent
Base class of agent.
All agent class need to inherit this
BaseAgent
class.- __init__(saver=None, storegate=None, task_scheduler=None, metric=None, metric_args=None)
Initialize base agent.
- Parameters:
saver (Saver or str) –
Saver
class instance. Ifsaver
is None,Saver
class instance is created without any args. If Ifsaver
is str, Saver` class instance is created with givensave_dir
.storegate (StoreGate or dict) –
StoreGate
class instance. If dict is given,StoreGate
class instance is created with given dict args.task_scheduler (TaskScheduler or list) –
TaskScheduler
class instance. If ordered tasks (list) are given,TaskScheduler
is initialized with ordered tasks. Please seeTaskScheduler
class for details.metric (str or BaseMetric) – str or Metric class instance. If str is given, Metric class is searched from multiml.agent.metric, and initialized with
metric_args
below.metric_args (dict) – arbitrary args of Metric class. This option is valid only if
metric
is str.
- execute()
Execute base agent.
Users need to implement algorithms.
- finalize()
Finalize base agent.
- execute_finalize()
Execute and finalize base agent.
- property storegate
Return storegate of base agent.
- property saver
Return saver of base agent.
- property task_scheduler
Return task_scheduler of base agent.
- property metric
Return metric of base agent.
- class multiml.agent.basic.SequentialAgent(differentiable=None, diff_pretrain=False, diff_task_args=None, num_trials=None, **kwargs)
Bases:
BaseAgent
Agent execute sequential tasks.
Examples
>>> task0 = your_task0 >>> task1 = your_task1 >>> task2 = your_task2 >>> >>> agent = SequentialAgent(storegate=storegate, >>> task_scheduler=[task0, task1, task2], >>> metric=your_metric) >>> agent.execute() >>> agent.finalize()
- __init__(differentiable=None, diff_pretrain=False, diff_task_args=None, num_trials=None, **kwargs)
Initialize sequential agent.
- Parameters:
differentiable (str) –
keras
orpytorch
. If differentiable is given,ConnectionTask()
is created based on sequential tasks. If differentiable is None (default), sequential tasks are executed step by step.diff_pretrain (bool) – If True, each subtask is trained before creating ConnectionTask()`.
diff_task_args (dict) – arbitrary args passed to
ConnectionTask()
.num_trials (ine) – number of trials. Average value of trials is used as final metric.
- property result
Return result of execution.
- execute()
Execute sequential agent.
- finalize()
Finalize sequential agent.
- execute_subtasktuples(subtasktuples, counter)
Execute given subtasktuples.
- execute_pipeline(subtasktuples, counter, trial=None)
Execute pipeline.
- execute_differentiable(subtasktuples, counter, trial=None)
Execute connection model.
- class multiml.agent.basic.RandomSearchAgent(samplings=None, seed=0, metric_type=None, num_workers=None, context='spawn', dump_all_results=False, disable_tqdm=True, **kwargs)
Bases:
SequentialAgent
Agent executing random search..
- __init__(samplings=None, seed=0, metric_type=None, num_workers=None, context='spawn', dump_all_results=False, disable_tqdm=True, **kwargs)
Initialize simple agent.
- Parameters:
samplings (int or list) – If int, number of random samplings. If list, indexes of combination.
seed (int) – seed of random samplings.
metric_type (str) – ‘min’ or ‘max’ for indicating direction of metric optimization. If it is None,
type
is retrieved from metric class instance.num_workers (int or list) – number of workers for multiprocessing or lsit of GPU ids. If
num_workers
is given, multiprocessing is enabled.context (str) – fork (default) or spawn.
dump_all_results (bool) – dump all results or not.
disable_tqdm (bool) – enable tqdm bar.
- property history
Return history of execution.
- execute()
Execute simple agent.
- finalize()
Finalize grid scan agent.
- execute_jobs(ctx, queue, args)
(expert method) Execute multiprocessing jobs.
- execute_pool_jobs(ctx, queue, args)
(expert method) Execute multiprocessing pool jobs.
- execute_wrapper(queue, subtasktuples, counter, cuda_id)
(expert method) Wrapper method to execute multiprocessing pipeline.
- class multiml.agent.basic.GridSearchAgent(**kwargs)
Bases:
RandomSearchAgent
Agent scanning all possible subtasks and hyper parameters.
- __init__(**kwargs)
Initialize grid scan agent.
- Parameters:
kwargs (dict) – arbitrary kwargs passed to
RandomSearchAgent
class.
- execute()
Execute grid scan agent.
- class multiml.agent.basic.ConnectionRandomSearchAgent(freeze_model_weights=False, do_pretraining=True, connectiontask_name=None, connectiontask_args={}, **kwargs)
Bases:
RandomSearchAgent
Agent executing with only one possible hyperparameter combination.
- __init__(freeze_model_weights=False, do_pretraining=True, connectiontask_name=None, connectiontask_args={}, **kwargs)
- Parameters:
freeze_model_weights (bool) – Fix model trainable weights after pre-training
do_pretraining (bool) – run pre-training before model connection
connectiontask_name (str) – Task name for ModelConnectionTask
connectiontask_args (dict) – args for ModelConnectionTask
**kwargs – Arbitrary keyword arguments
- execute()
Execute.
- connectiontask_name_with_jobid(job_id)
Returns a formatted name for ConnectionTask. job_id is used as a suffix.
- Returns:
formatted name for the ConnectionTask
- Return type:
str
- class multiml.agent.basic.ConnectionGridSearchAgent(reuse_pretraining=False, **kwargs)
Bases:
GridSearchAgent
,ConnectionRandomSearchAgent
Agent executing with all possible hyperparameter combination.
- __init__(reuse_pretraining=False, **kwargs)
Initialize.
- Parameters:
reuse_pretraining (bool) – Use common model weights for pretraining
**kwargs – Arbitrary keyword arguments
- execute()
Execute.
- finalize()
Finalize.
- get_best_result()
Returns the best combination as a result of agent execution.
- Returns:
best result dict: auxiliary value of the best result
- Return type:
dict