def tb(): import os ws = Workspace.from_config() print(ws.name) proj = Project.attach(ws, 'tbhistory', '/tmp/tb-test') shutil.copy('tftb.py', os.path.join(proj.project_directory, 'tftb.py')) from azureml.core.compute_target import RemoteTarget rt = RemoteTarget(name='dsvm', address='hai2.eastus2.cloudapp.azure.com:5022', username='******', password='******') proj.attach_legacy_compute_target(rt) rc = RunConfiguration.load(proj, "dsvm") rc.environment.python.user_managed_dependencies = True rc.environment.python.interpreter_path = '/anaconda/envs/tf/bin/python' print(rc.target) run = Run.submit(proj, rc, 'tftb.py') print(run.id) #run.wait_for_completion(show_output=True) from azureml.contrib.tensorboard import Tensorboard tb = Tensorboard([run]) print('starting tensorboard...') print(tb.start()) print('tensorboard started.') run.wait_for_completion(show_output=True) tb.stop()
def _get_run_config_object(self, run_config): if isinstance(run_config, str): # If it is a string then we don't need to create a copy. return RunConfiguration.load(self.project_directory, run_config) elif isinstance(run_config, RunConfiguration): # TODO: Deep copy of project and auth object too. import copy return copy.deepcopy(run_config) else: raise UserErrorException( "Unsupported runconfig type {}. run_config can be of str or " "azureml.core.runconfig.RunConfiguration type.".format( type(run_config)))
def publish(azureml_workspace, entry_point, name, description, parameters={}): luna_config = utils.Init() if azureml_workspace: run_config = RunConfiguration.load( luna_config['azureml']['run_config']) arguments = utils.GetPipelineArguments(luna_config['MLproject'], entry_point, parameters) trainStep = PythonScriptStep( script_name=luna_config['code'][entry_point], arguments=arguments, inputs=[], outputs=[], source_directory=os.getcwd(), runconfig=run_config) pipeline = Pipeline(workspace=azureml_workspace, steps=[trainStep]) published_pipeline = pipeline.publish(name=name, description=description) return published_pipeline.endpoint
from azureml.exceptions.azureml_exception import UserErrorException from azureml.core.compute_target import RemoteTarget try: # Attaches a remote docker on a remote vm as a compute target. project.attach_legacy_compute_target(RemoteTarget(name = "cpu-dsvm", address = "hai2.eastus2.cloudapp.azure.com:5022", username = "******", password = '******')) except UserErrorException as e: print("Caught = {}".format(e.message)) print("Compute config already attached.") print('Load the cpu-dsvm config and make it run Spark:') # Load the "cpu-dsvm.runconfig" file (created by the above attach operation) in memory run_config = RunConfiguration.load(project_object = project, run_config_name = "cpu-dsvm") # set framework to PySpark run_config.framework = "PySpark" # Use Docker in the remote VM run_config.environment.docker.enabled = True # Use the MMLSpark CPU based image. # https://hub.docker.com/r/microsoft/mmlspark/ run_config.environment.docker.base_image = azureml.core.runconfig.DEFAULT_MMLSPARK_CPU_IMAGE print('base image is:', run_config.environment.docker.base_image) # signal use the user-managed environment # do NOT provision a new one based on the conda.yml file run_config.environment.python.user_managed_dependencies = False
script_params=script_params, source_directory=os.path.dirname( os.path.realpath(__file__)), compute_target='local', user_managed=True, use_docker=False) if data_local is False: dataset_train = Dataset.get_by_name(workspace, name=input_name_train) dataset_test = Dataset.get_by_name(workspace, name=input_name_test) # Load run Config run_config = RunConfiguration.load(path=os.path.join( os.path.join( os.path.dirname(os.path.realpath(__file__)), "../..", filepath, )), name="sklearn") est = ScriptRunConfig( source_directory=os.path.dirname(os.path.realpath(__file__)), arguments=[ "--models", models, '--data_folder_train', 'DatasetConsumptionConfig:{}'.format(input_name_train), '--data_folder_test', 'DatasetConsumptionConfig:{}'.format(input_name_test), '--local', 'no' ], run_config=run_config)
if os.path.isdir(project_folder): print('{} already exists, remove it.'.format(project_folder)) shutil.rmtree(project_folder) project = Project.attach(workspace_object=ws, history_name=run_history_name, directory=project_folder) print(project.project_directory, project.history.name, sep='\n') print('copy {} to the project folder.'.format(train_script)) shutil.copy(train_script, os.path.join(project_folder, train_script)) print('load run config') # Editing a run configuration property on-fly. run_config = RunConfiguration.load(project_object=project, run_config_name="local") # You can choose a specific Python environment by pointing to a Python path #run_config.environment.python.interpreter_path = '/home/ninghai/miniconda3/envs/sdk2/bin/python' print() print('##################################################') print('submitting {} for a local run...'.format(train_script)) print('##################################################') print() run = Run.submit(project_object=project, run_config=run_config, script_to_run=train_script) print(helpers.get_run_history_url_2(run))
'--models', 'sklearnmodels', '--input_train', subset_train_prepared, '--input_test', subset_test_prepared, '--sklearnmodel', sklearnmodelpath ] script_params_model_training = [ '--models', 'deeplearning', '--fullmodel', "yes", '--input_train', train_prepared, '--input_test', test_prepared, '--savemodel', modelpath ] # LOAD RUN CONFIGURATIONS FOR EVERY STEP IN THE PIPELINE # Load run configuration for data validation on full dataset filepath = "environments/data_validation/RunConfig/runconfig_data_validation.yml" run_config_data_validation = RunConfiguration.load(path=os.path.join( os.path.join( os.path.dirname(os.path.realpath(__file__)), "../..", filepath, )), name="datavalidation") # Load run configuration for data validation on subset filepath = "environments/data_validation_subset/RunConfig/runconfig_data_validation.yml" run_config_data_validation_subset = RunConfiguration.load( path=os.path.join( os.path.join( os.path.dirname(os.path.realpath(__file__)), "../..", filepath, )), name="datavalidation")
'--local', False ] # define script parameters script_params = [ '--data_folder_train', dataset_train.as_named_input('train').as_mount(), '--data_folder_test', dataset_test.as_named_input('test').as_mount(), '--subset', True, '--local', False ] # Load run Config run_config_sub = RunConfiguration.load(path=os.path.join( os.path.join( os.path.dirname(os.path.realpath(__file__)), "../..", "environments/data_preperation_subset/RunConfig/runconfig_data_preperation.yml", )), name="dataprep_subset") # Load run Config run_config = RunConfiguration.load(path=os.path.join( os.path.join( os.path.dirname(os.path.realpath(__file__)), "../..", "environments/data_preperation_full/RunConfig/runconfig_data_preperation.yml", )), name="dataprep_full") dataprep_subset = PythonScriptStep( name="subset",
provisioning_config) # can poll for a minimum number of nodes and for a specific timeout. # if no min node count is provided it will use the scale settings for the cluster compute_target.wait_for_completion(show_output=True, min_node_count=None, timeout_in_minutes=20) # For a more detailed view of current AmlCompute status, use the 'status' property print(compute_target.status.serialize()) #%% from azureml.core.runconfig import RunConfiguration # create a new runconfig object run_config = RunConfiguration.load('.', 'aci') run_config.target = compute_target.name # set the data reference of the run configuration run_config.data_references = {ds.name: dr} #%% [markdown] # ### Submit the Experiment # Submit script to run in the Docker image in the remote VM. If you run this for the first time, the system will download the base image, layer in packages specified in the conda_dependencies.yml file on top of the base image, create a container and then execute the script in the container. #%% from azureml.core import Run from azureml.core import ScriptRunConfig src = ScriptRunConfig( source_directory=retrain_scripts_dir,
policy=None, primary_metric_name="accuracy", primary_metric_goal=PrimaryMetricGoal.MAXIMIZE, max_total_runs=2, max_concurrent_runs=None), estimator_entry_script_arguments=script_params, outputs=[], metrics_output=metrics_data, allow_reuse=True, version=None) # Load run Config run_config = RunConfiguration.load(path=os.path.join( os.path.join( os.path.dirname(os.path.realpath(__file__)), "../..", "environments/fullmodel_step/RunConfig/runconfig_fullmodel.yml", )), name="fullmodel") fullmodel = PythonScriptStep(name="fullmodel", script_name="train.py", arguments=script_params_2, inputs=[metrics_data], outputs=[], runconfig=run_config, source_directory=os.path.join( os.path.dirname(os.path.realpath(__file__)), '..', 'modeling')) # Attach step to the pipelines
# Prepare the Docker and conda environment automatically when they're used for the first time run_dsvm.prepare_environment = True # Specify the CondaDependencies object run_dsvm.environment.python.conda_dependencies = CondaDependencies.create(conda_packages=['scikit-learn']) #</run_dsvm> hdi_compute.name = "blah" from azureml.core.runconfig import RunConfiguration from azureml.core.conda_dependencies import CondaDependencies # use pyspark framework hdi_run_config = RunConfiguration(framework="pyspark") # Set compute target to the HDI cluster hdi_run_config.target = hdi_compute.name # specify CondaDependencies object to ask system installing numpy cd = CondaDependencies() cd.add_conda_package('numpy') hdi_run_config.environment.python.conda_dependencies = cd #<run_hdi> from azureml.core.runconfig import RunConfiguration # Configure the HDInsight run # Load the runconfig object from the myhdi.runconfig file generated in the previous attach operation run_hdi = RunConfiguration.load(project_object = project, run_name = 'myhdi') # Ask the system to prepare the conda environment automatically when it's used for the first time run_hdi.auto_prepare_environment = True>
import shutil shutil.copy('./scripts/train_Fashion_MNIST.py', project_folder) shutil.copy('./resources/configs/fashion_mnist_aci_dependencies.yml', config_folder) shutil.copy('./resources/configs/fashion_mnist_aci.runconfig', config_folder) # Create An Experiment from azureml.core import Experiment experiment_name = 'fashion-mnist' experiment = Experiment(workspace = ws, name = experiment_name) # Load Configuration from azureml.core.runconfig import RunConfiguration from azureml.core.conda_dependencies import CondaDependencies # create a new runconfig object run_config = RunConfiguration.load(path=project_folder, name='fashion_mnist_aci') # Submit Experiment from azureml.core.script_run_config import ScriptRunConfig script_run_config = ScriptRunConfig(source_directory=project_folder, script='train_Fashion_MNIST.py', run_config=run_config) run = experiment.submit(script_run_config) run.tag("Description","ACI trained Fashion MNIST model") run.wait_for_completion(show_output=True) # Show Metrics # get all metris logged in the run run.get_metrics()