Cancel run in azureml sdk2

93 views Asked by At

I'm using azureml sdk2 and I want to add execution cancel condition to my code but I don't know how to do it?

from azure.ai.ml import MLClient
ml_client = MLClient(
credential=credential,
subscription_id = "***",
resource_group_name = "***",
workspace_name = "***"
)
job = command(
    code="./temp-workspace/",  # location of source code
    command="python train_script.py",
    description = description,
    tags=tags,
    environment=myenv,
    compute=cpu_compute_target,
    experiment_name=experiment_name,
    display_name=registered_model_name,
    )
# submit the command
returned_job = ml_client.jobs.create_or_update(job)

how can i cancel this job in local run?

1

There are 1 answers

2
Rishabh Meshram On

To cancel the job with ml_client you can use below code snippet:

ml_client.jobs.begin_cancel(job_details.name)

Job started and cancelled with ml_client as shown: enter image description here

With above code the job was cancelled as per requirement. enter image description here