Skip to content

Commit 17bc04e

Browse files
authored
Merge pull request #6 from Microsoft/feature/cli-auth
Feature/cli auth
2 parents e86d9f6 + 29c4a92 commit 17bc04e

16 files changed

+106
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ venv/
8989
ENV/
9090
env.bak/
9191
venv.bak/
92+
*.vscode
9293

9394
# Spyder project settings
9495
.spyderproject

aml_config/security_config.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@
55
"remote_vm_name" : "<>",
66
"remote_vm_username" : "<>",
77
"remote_vm_password" : "<>",
8-
"remote_vm_ip" : "<>"
8+
"remote_vm_ip" : "<>",
9+
"experiment_name" : "<>",
10+
"aml_cluster_name" : "<>",
11+
"vnet_resourcegroup_name" : "<>",
12+
"vnet_name" : "<>",
13+
"subnet_name" : "<>"
914
}

aml_service/00-WorkSpace.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
name=workspace_name,
4646
subscription_id=subscription_id,
4747
resource_group=resource_group,
48-
auth=cli_auth
48+
auth=cli_auth,
4949
)
5050

5151
except:
@@ -57,8 +57,7 @@
5757
resource_group=resource_group,
5858
# create_resource_group=True,
5959
location=location,
60-
auth=cli_auth
61-
60+
auth=cli_auth,
6261
)
6362

6463
# print Workspace details

aml_service/01-Experiment.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@
2626
import os
2727
from azureml.core import Experiment
2828
from azureml.core import Workspace
29+
from azureml.core.authentication import AzureCliAuthentication
30+
31+
cli_auth = AzureCliAuthentication()
2932

3033

3134
def getExperiment():
32-
ws = Workspace.from_config()
35+
ws = Workspace.from_config(auth=cli_auth)
3336
script_folder = "."
3437
experiment_name = "devops-ai-demo"
3538
exp = Experiment(workspace=ws, name=experiment_name)

aml_service/02-AttachTrainingVM.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
from azureml.core.compute import RemoteCompute
3434
from azureml.core.compute import DsvmCompute
3535
from azureml.core.compute_target import ComputeTargetException
36+
from azureml.core.authentication import AzureCliAuthentication
3637

38+
cli_auth = AzureCliAuthentication()
3739

3840
# Get workspace
39-
ws = Workspace.from_config()
41+
ws = Workspace.from_config(auth=cli_auth)
4042

4143
# Read the New VM Config
4244
with open("aml_config/security_config.json") as f:

aml_service/03-AttachAmlCluster.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
Copyright (C) Microsoft Corporation. All rights reserved.​
3+
4+
Microsoft Corporation (“Microsoft”) grants you a nonexclusive, perpetual,
5+
royalty-free right to use, copy, and modify the software code provided by us
6+
("Software Code"). You may not sublicense the Software Code or any use of it
7+
(except to your affiliates and to vendors to perform work on your behalf)
8+
through distribution, network access, service agreement, lease, rental, or
9+
otherwise. This license does not purport to express any claim of ownership over
10+
data you may have shared with Microsoft in the creation of the Software Code.
11+
Unless applicable law gives you more rights, Microsoft reserves all other
12+
rights not expressly granted herein, whether by implication, estoppel or
13+
otherwise. ​
14+
15+
THE SOFTWARE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
16+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
MICROSOFT OR ITS LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
21+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23+
ARISING IN ANY WAY OUT OF THE USE OF THE SOFTWARE CODE, EVEN IF ADVISED OF THE
24+
POSSIBILITY OF SUCH DAMAGE.
25+
"""
26+
27+
from azureml.core import Workspace
28+
from azureml.core.compute import ComputeTarget, AmlCompute
29+
from azureml.core.compute_target import ComputeTargetException
30+
from azureml.core.authentication import AzureCliAuthentication
31+
import os, json
32+
33+
cli_auth = AzureCliAuthentication()
34+
# Get workspace
35+
ws = Workspace.from_config(auth=cli_auth)
36+
37+
# Read the New VM Config
38+
with open("aml_config/security_config.json") as f:
39+
config = json.load(f)
40+
41+
aml_cluster_name = config["aml_cluster_name"]
42+
43+
# un-comment the below lines if you want to put AML Compute under Vnet. Also update /aml_config/security_config.json
44+
# vnet_resourcegroup_name = config['vnet_resourcegroup_name']
45+
# vnet_name = config['vnet_name']
46+
# subnet_name = config['subnet_name']
47+
48+
# Verify that cluster does not exist already
49+
try:
50+
cpu_cluster = ComputeTarget(workspace=ws, name=aml_cluster_name)
51+
print("Found existing cluster, use it.")
52+
except ComputeTargetException:
53+
compute_config = AmlCompute.provisioning_configuration(
54+
vm_size="STANDARD_D2_V2",
55+
vm_priority="dedicated",
56+
min_nodes=1,
57+
max_nodes=3,
58+
idle_seconds_before_scaledown="300",
59+
# #Uncomment the below lines for VNet support
60+
# vnet_resourcegroup_name=vnet_resourcegroup_name,
61+
# vnet_name=vnet_name,
62+
# subnet_name=subnet_name
63+
)
64+
cpu_cluster = ComputeTarget.create(ws, aml_cluster_name, compute_config)
65+
66+
cpu_cluster.wait_for_completion(show_output=True)

aml_service/10-TrainOnLocal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from azureml.core import ScriptRunConfig
3131
import json
3232
from azureml.core.authentication import AzureCliAuthentication
33+
3334
cli_auth = AzureCliAuthentication()
3435

3536
# Get workspace

aml_service/11-TrainOnLocalEnv.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@
3232
from azureml.core import Experiment
3333
from azureml.core import ScriptRunConfig
3434

35+
from azureml.core.authentication import AzureCliAuthentication
36+
37+
cli_auth = AzureCliAuthentication()
38+
3539
# Get workspace
36-
ws = Workspace.from_config()
40+
ws = Workspace.from_config(auth=cli_auth)
3741

3842
# Attach Experiment
3943
experiment_name = "devops-ai-demo"

aml_service/12-TrainOnVM.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030
from azureml.core.runconfig import RunConfiguration
3131
from azureml.core import ScriptRunConfig
3232
import azureml.core
33+
from azureml.core.authentication import AzureCliAuthentication
3334

34-
35+
cli_auth = AzureCliAuthentication()
3536
# Get workspace
36-
ws = Workspace.from_config()
37+
ws = Workspace.from_config(auth=cli_auth)
38+
3739

3840
# Read the New VM Config
3941
with open("aml_config/security_config.json") as f:

aml_service/15-EvaluateModel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import azureml.core
3131
from azureml.core import Run
3232
from azureml.core.authentication import AzureCliAuthentication
33+
3334
cli_auth = AzureCliAuthentication()
3435

3536
# Get workspace

0 commit comments

Comments
 (0)