您可以通过多种方式使用 AzureML 来解决此问题。最简单的方法是使用 AzureML Python SDK 启动多个作业(底层示例取自here https://github.com/Azure/MachineLearningNotebooks/blob/4170a394edd36413edebdbab347afb0d833c94ee/how-to-use-azureml/training/train-hyperparameter-tune-deploy-with-sklearn/train-hyperparameter-tune-deploy-with-sklearn.ipynb)
from azureml.train.sklearn import SKLearn
runs = []
for kernel in ['linear', 'rbf', 'poly', 'sigmoid']:
for penalty in [0.5, 1, 1.5]:
print ('submitting run for kernel', kernel, 'penalty', penalty)
script_params = {
'--kernel': kernel,
'--penalty': penalty,
}
estimator = SKLearn(source_directory=project_folder,
script_params=script_params,
compute_target=compute_target,
entry_script='train_iris.py',
pip_packages=['joblib==0.13.2'])
runs.append(experiment.submit(estimator))
上述内容要求您将训练内容与所需的 python 包一起分解为一个脚本(或文件夹中的一组脚本)。上面的估计器是使用 Scikit Learn 的便捷包装器。还有 Tensorflow、Pytorch、Chainer 和通用估计器(azureml.train.estimator.Estimator
)——它们在使用的 Python 包和基础 docker 上都有所不同。
如果您实际上正在调整参数,第二个选项是像这样使用 HyperDrive 服务(使用相同的SKLearn
估计器如上):
from azureml.train.sklearn import SKLearn
from azureml.train.hyperdrive.runconfig import HyperDriveConfig
from azureml.train.hyperdrive.sampling import RandomParameterSampling
from azureml.train.hyperdrive.run import PrimaryMetricGoal
from azureml.train.hyperdrive.parameter_expressions import choice
estimator = SKLearn(source_directory=project_folder,
script_params=script_params,
compute_target=compute_target,
entry_script='train_iris.py',
pip_packages=['joblib==0.13.2'])
param_sampling = RandomParameterSampling( {
"--kernel": choice('linear', 'rbf', 'poly', 'sigmoid'),
"--penalty": choice(0.5, 1, 1.5)
}
)
hyperdrive_run_config = HyperDriveConfig(estimator=estimator,
hyperparameter_sampling=param_sampling,
primary_metric_name='Accuracy',
primary_metric_goal=PrimaryMetricGoal.MAXIMIZE,
max_total_runs=12,
max_concurrent_runs=4)
hyperdrive_run = experiment.submit(hyperdrive_run_config)
或者您可以使用 DASK 来安排您提到的工作。以下是如何在 AzureML 计算集群上设置 DASK 的示例,以便您可以对其进行交互式工作:https://github.com/danielsc/azureml-and-dask https://github.com/danielsc/azureml-and-dask