autogluon.core¶
Decorators for customizing AutoGluon to apply hyperparameter-tuning on arbitrary user-defined objects and functions.
Toy Example
Create class and function with searchable spaces for hyperparameters name and idx:
>>> import autogluon as ag
>>> @ag.obj(
... name=ag.space.Categorical('auto', 'gluon'),
... idx = ag.space.Int(0, 100),
... )
>>> class myobj:
... def __init__(self, name, idx):
... self.name = name
... self.idx = idx
...
>>> @ag.func(framework=ag.space.Categorical('mxnet', 'pytorch'))
>>> def myfunc(framework):
... return framework
Create the objects using decorated class and function as argument of autogluon.args
>>> @ag.args(
... h=ag.space.Categorical('test', myobj()),
... i = myfunc(),
... )
>>> def train_fn(args, reporter):
... h, i = args.h, args.i
... assert hasattr(h, 'name') or h == 'test'
... assert i in ['mxnet', 'pytorch']
... reporter(epoch=1, accuracy=0)
Create a scheduler and run training trials to search for the best values of the hyperparameters:
>>> scheduler = ag.scheduler.FIFOScheduler(train_fn,
... resource={'num_cpus': 2, 'num_gpus': 0},
... num_trials=20,
... reward_attr='accuracy',
... time_attr='epoch')
>>> scheduler.run()
Core APIs¶
AutoGluon: AutoML Toolkit for Deep Learning
Decorator for a Python training script that registers its arguments as hyperparameters. |
|
Decorator for a Python class that registers its arguments as hyperparameters. |
|
Decorator for a function that registers its arguments as hyperparameters. |
args¶
-
autogluon.
args
(default=None, **kwvars)¶ - Decorator for a Python training script that registers its arguments as hyperparameters.
Each hyperparameter takes fixed value or is a searchable space, and the arguments may either be: built-in Python objects (e.g. floats, strings, lists, etc.), AutoGluon objects (see
autogluon.obj()
), or AutoGluon search spaces (seeautogluon.space.Int
,autogluon.space.Real
, etc.).
Examples
>>> import autogluon as ag >>> @ag.args(batch_size=10, lr=ag.Real(0.01, 0.1)) >>> def train_func(args): ... print('Batch size is {}, LR is {}'.format(args.batch_size, arg.lr))
obj¶
-
autogluon.
obj
(**kwvars)¶ - Decorator for a Python class that registers its arguments as hyperparameters.
Each hyperparameter may take a fixed value or be a searchable space (autogluon.space).
- Returns
- Instance of
autogluon.space.AutoGluonObject
: A lazily initialized object, which allows distributed training.
- Instance of
Examples
>>> import autogluon as ag >>> from mxnet import optimizer as optim >>> @ag.obj( >>> learning_rate=ag.space.Real(1e-4, 1e-1, log=True), >>> wd=ag.space.Real(1e-4, 1e-1), >>> ) >>> class Adam(optim.Adam): >>> pass
func¶
-
autogluon.
func
(**kwvars)¶ - Decorator for a function that registers its arguments as hyperparameters.
Each hyperparameter may take a fixed value or be a searchable space (autogluon.space).
- Returns
- Instance of
autogluon.space.AutoGluonObject
: A lazily initialized object, which allows for distributed training.
- Instance of
Examples
>>> import autogluon as ag >>> from gluoncv.model_zoo import get_model >>> >>> @ag.func(pretrained=ag.space.Categorical(True, False)) >>> def cifar_resnet(pretrained): ... return get_model('cifar_resnet20_v1', pretrained=pretrained)