azure - 如何在训练步骤中将 AzureML SDK 中的管道和超参数结合起来

标签 azure sdk azure-machine-learning-service azureml-python-sdk

简短形式: 我试图弄清楚如何在管道中的训练步骤(即train_step = PythonScriptStep(...))中运行超参数,我不确定应该将“config=”放在哪里超光速推进器”

长格式:

一般:

# Register the environment 
diabetes_env.register(workspace=ws)
registered_env = Environment.get(ws, 'diabetes-pipeline-env')

# Create a new runconfig object for the pipeline
run_config = RunConfiguration()

# Use the compute you created above. 
run_config.target = ComputerTarget_Crea

# Assign the environment to the run configuration
run_config.environment = registered_env

超参数:

script_config = ScriptRunConfig(source_directory=experiment_folder,
                                script='diabetes_training.py',
                                # Add non-hyperparameter arguments -in this case, the training dataset
                                arguments = ['--input-data', diabetes_ds.as_named_input('training_data')],
                                environment=sklearn_env,
                                compute_target = training_cluster)

# Sample a range of parameter values
params = GridParameterSampling(
    {
        # Hyperdrive will try 6 combinations, adding these as script arguments
        '--learning_rate': choice(0.01, 0.1, 1.0),
        '--n_estimators' : choice(10, 100)
    }
)

# Configure hyperdrive settings
hyperdrive = HyperDriveConfig(run_config=script_config, 
                          hyperparameter_sampling=params, 
                          policy=None, # No early stopping policy
                          primary_metric_name='AUC', # Find the highest AUC metric
                          primary_metric_goal=PrimaryMetricGoal.MAXIMIZE, 
                          max_total_runs=6, # Restict the experiment to 6 iterations
                          max_concurrent_runs=2) # Run up to 2 iterations in parallel

# Run the experiment if I only want to run hyperparam alone without the pipeline
#experiment = Experiment(workspace=ws, name='mslearn-diabetes-hyperdrive')
#run = experiment.submit(**config=hyperdrive**)

管道:

prep_step = PythonScriptStep(name = "Prepare Data",
                                source_directory = experiment_folder,
                                script_name = "prep_diabetes.py",
                                arguments = ['--input-data', diabetes_ds.as_named_input('raw_data'),
                                             '--prepped-data', prepped_data_folder],
                                outputs=[prepped_data_folder],
                                compute_target = ComputerTarget_Crea,
                                runconfig = run_config,
                                allow_reuse = True)

# Step 2, run the training script
train_step = PythonScriptStep(name = "Train and Register Model",
                                source_directory = experiment_folder,
                                script_name = "train_diabetes.py",
                                arguments = ['--training-folder', prepped_data_folder],
                                inputs=[prepped_data_folder],
                                compute_target = ComputerTarget_Crea,
                                runconfig = run_config,
                                allow_reuse = True)
# Construct the pipeline
pipeline_steps = [prep_step, train_step]
pipeline = Pipeline(workspace=ws, steps=pipeline_steps)
print("Pipeline is built.")

# Create an experiment and run the pipeline
**#How do I need to change these below lines to use hyperdrive????**
experiment = Experiment(workspace=ws, name = 'mslearn-diabetes-pipeline')
pipeline_run = experiment.submit(pipeline, regenerate_outputs=True)

不确定需要将 config=hyperdrive 放在“管道”部分的什么位置?

最佳答案

关于azure - 如何在训练步骤中将 AzureML SDK 中的管道和超参数结合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67352949/

相关文章:

azure - Windows Azure 停止了 VM 数据持久性

azure - DocumentDB 惰性索引模式 : Querying a document before the index has updated

iphone - 如何获取属于某个人 ABAddressBook 的组

php - 获得对亚马逊 FBA 数据库的访问权限

python - 如何使用 jobs.create_or_update() 在 Azure ML SDK v2 中的管道中设置环境变量?

loops - Azure ML 循环执行不同的任务

azure - 在 Azure 搜索中为 View 建立索引时如何从索引中删除数据?

javascript - 索尼 Bravia JavaScript API 和模拟器

r - Azure ML R 模型训练和评分 Web 服务

Azure SQL Server 审核 EventHub Bicep