This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cancel queued AzureML jobs when starting a PR build (#640)
AzureML jobs from failed previous PR builds do not get cancelled, consuming excessive resources. Now kill all queued and running jobs before starting new ones.
- Loading branch information
Showing
9 changed files
with
112 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: AzureML_SDK | ||
channels: | ||
- defaults | ||
dependencies: | ||
- pip=20.1.1 | ||
- python=3.7.3 | ||
- pip: | ||
- azureml-sdk==1.36.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# ------------------------------------------------------------------------------------------ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
# ------------------------------------------------------------------------------------------ | ||
import os | ||
|
||
from azureml._restclient.constants import RunStatus | ||
from azureml.core import Experiment, Run, Workspace | ||
from azureml.core.authentication import ServicePrincipalAuthentication | ||
|
||
|
||
def cancel_running_and_queued_jobs() -> None: | ||
environ = os.environ | ||
print("Authenticating") | ||
auth = ServicePrincipalAuthentication( | ||
tenant_id='72f988bf-86f1-41af-91ab-2d7cd011db47', | ||
service_principal_id=environ["APPLICATION_ID"], | ||
service_principal_password=environ["APPLICATION_KEY"]) | ||
print("Getting AML workspace") | ||
workspace = Workspace.get( | ||
name="InnerEye-DeepLearning", | ||
auth=auth, | ||
subscription_id=environ["SUBSCRIPTION_ID"], | ||
resource_group="InnerEye-DeepLearning") | ||
branch = environ["BRANCH"] | ||
print(f"Branch: {branch}") | ||
if not branch.startswith("refs/pull/"): | ||
print("This branch is not a PR branch, hence not cancelling anything.") | ||
exit(0) | ||
experiment_name = branch.replace("/", "_") | ||
print(f"Experiment: {experiment_name}") | ||
experiment = Experiment(workspace, name=experiment_name) | ||
print(f"Retrieved experiment {experiment.name}") | ||
for run in experiment.get_runs(include_children=True, properties={}): | ||
assert isinstance(run, Run) | ||
status_suffix = f"'{run.status}' run {run.id} ({run.display_name})" | ||
if run.status in (RunStatus.COMPLETED, RunStatus.FAILED, RunStatus.FINALIZING, RunStatus.CANCELED, | ||
RunStatus.CANCEL_REQUESTED): | ||
print(f"Skipping {status_suffix}") | ||
else: | ||
print(f"Cancelling {status_suffix}") | ||
run.cancel() | ||
|
||
|
||
if __name__ == "__main__": | ||
cancel_running_and_queued_jobs() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
steps: | ||
- checkout: self | ||
|
||
- template: prepare_conda.yml | ||
|
||
# https://docs.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#pythonanaconda | ||
- task: Cache@2 | ||
displayName: Use cached Conda environment AzureML_SDK | ||
inputs: | ||
# Beware of changing the cache key or path independently, safest to change in sync | ||
key: 'usr_share_miniconda_azureml_conda | "$(Agent.OS)" | azure-pipelines/azureml-conda-environment.yml' | ||
path: /usr/share/miniconda/envs | ||
cacheHitVar: CONDA_CACHE_RESTORED | ||
|
||
- script: conda env create --file azure-pipelines/azureml-conda-environment.yml | ||
displayName: Create Conda environment AzureML_SDK | ||
condition: eq(variables.CONDA_CACHE_RESTORED, 'false') | ||
|
||
- bash: | | ||
source activate AzureML_SDK | ||
python azure-pipelines/cancel_aml_jobs.py | ||
displayName: Cancel jobs from previous run | ||
env: | ||
SUBSCRIPTION_ID: $(InnerEyeDevSubscriptionID) | ||
APPLICATION_ID: $(InnerEyeDeepLearningServicePrincipalID) | ||
APPLICATION_KEY: $(InnerEyeDeepLearningServicePrincipalKey) | ||
BRANCH: $(Build.SourceBranch) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
steps: | ||
- bash: | | ||
subdir=bin | ||
echo "Adding this directory to PATH: $CONDA/$subdir" | ||
echo "##vso[task.prependpath]$CONDA/$subdir" | ||
displayName: Add conda to PATH | ||
condition: succeeded() | ||
- bash: | | ||
sudo chown -R $USER /usr/share/miniconda | ||
condition: and(succeeded(), eq( variables['Agent.OS'], 'Linux' )) | ||
displayName: Take ownership of conda installation |