Skip to content

Commit 9903e56

Browse files
committed
quickstart added
1 parent a039166 commit 9903e56

File tree

24 files changed

+1478
-0
lines changed

24 files changed

+1478
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 01-create-workspace.py
2+
from azureml.core import Workspace
3+
4+
# Example locations: 'westeurope' or 'eastus2' or 'westus2' or 'southeastasia'.
5+
ws = Workspace.create(name='<my_workspace_name>',
6+
subscription_id='<azure-subscription-id>',
7+
resource_group='<myresourcegroup>',
8+
create_resource_group=True,
9+
location='<NAME_OF_REGION>')
10+
11+
# write out the workspace details to a configuration file: .azureml/config.json
12+
ws.write_config(path='.azureml')
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# 02-create-compute.py
2+
from azureml.core import Workspace
3+
from azureml.core.compute import ComputeTarget, AmlCompute
4+
from azureml.core.compute_target import ComputeTargetException
5+
6+
ws = Workspace.from_config()
7+
8+
# Choose a name for your CPU cluster
9+
cpu_cluster_name = "cpu-cluster"
10+
11+
# Verify that cluster does not exist already
12+
try:
13+
cpu_cluster = ComputeTarget(workspace=ws, name=cpu_cluster_name)
14+
print('Found existing cluster, use it.')
15+
except ComputeTargetException:
16+
cfg = AmlCompute.provisioning_configuration(
17+
vm_size='STANDARD_D2_V2',
18+
max_nodes=4,
19+
idle_seconds_before_scaledown=2400
20+
)
21+
cpu_cluster = ComputeTarget.create(ws, cpu_cluster_name, cfg)
22+
23+
cpu_cluster.wait_for_completion(show_output=True)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 03-run-hello.py
2+
from azureml.core import Workspace, Experiment, ScriptRunConfig
3+
4+
ws = Workspace.from_config()
5+
experiment = Experiment(workspace=ws, name='day1-experiment-hello')
6+
7+
config = ScriptRunConfig(source_directory='./src',
8+
script='hello.py',
9+
compute_target='cpu-cluster')
10+
11+
run = experiment.submit(config)
12+
aml_url = run.get_portal_url()
13+
print(aml_url)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# 04-run-pytorch.py
2+
from azureml.core import Workspace
3+
from azureml.core import Experiment
4+
from azureml.core import Environment
5+
from azureml.core import ScriptRunConfig
6+
7+
if __name__ == "__main__":
8+
ws = Workspace.from_config()
9+
experiment = Experiment(workspace=ws, name='day1-experiment-train')
10+
config = ScriptRunConfig(source_directory='./src',
11+
script='train.py',
12+
compute_target='cpu-cluster')
13+
14+
# set up pytorch environment
15+
env = Environment.from_conda_specification(
16+
name='pytorch-env',
17+
file_path='./environments/pytorch-env.yml'
18+
)
19+
config.run_config.environment = env
20+
21+
run = experiment.submit(config)
22+
23+
aml_url = run.get_portal_url()
24+
print(aml_url)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# 05-upload-data.py
2+
from azureml.core import Workspace
3+
ws = Workspace.from_config()
4+
datastore = ws.get_default_datastore()
5+
datastore.upload(src_dir='./data',
6+
target_path='datasets/cifar10',
7+
overwrite=True)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# 06-run-pytorch-data.py
2+
from azureml.core import Workspace
3+
from azureml.core import Experiment
4+
from azureml.core import Environment
5+
from azureml.core import ScriptRunConfig
6+
from azureml.core import Dataset
7+
8+
if __name__ == "__main__":
9+
ws = Workspace.from_config()
10+
datastore = ws.get_default_datastore()
11+
dataset = Dataset.File.from_files(path=(datastore, 'datasets/cifar10'))
12+
13+
experiment = Experiment(workspace=ws, name='day1-experiment-data')
14+
15+
config = ScriptRunConfig(
16+
source_directory='./src',
17+
script='train.py',
18+
compute_target='cpu-cluster',
19+
arguments=[
20+
'--data_path', dataset.as_named_input('input').as_mount(),
21+
'--learning_rate', 0.003,
22+
'--momentum', 0.92],
23+
)
24+
# set up pytorch environment
25+
env = Environment.from_conda_specification(
26+
name='pytorch-env',
27+
file_path='./environments/pytorch-env.yml'
28+
)
29+
config.run_config.environment = env
30+
31+
run = experiment.submit(config)
32+
aml_url = run.get_portal_url()
33+
print("Submitted to compute cluster. Click link below")
34+
print("")
35+
print(aml_url)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Get Started (day 1) with Azure Machine Learning: IDE Users
2+
3+
This folder has been setup for IDE user (for example, VS Code or Pycharm) following the [Get started (day 1) with Azure Machine Learning tutorial series](https://aka.ms/day1aml).
4+
5+
The directory is structured as follows:
6+
7+
```Text
8+
IDE-users
9+
└──environments
10+
| └──pytorch-env.yml
11+
└──src
12+
| └──hello.py
13+
| └──model.py
14+
| └──train.py
15+
└──01-create-workspace.py
16+
└──02-create-compute.py
17+
└──03-run-hello.py
18+
└──04-run-pytorch.py
19+
└──05-upload-data.py
20+
└──06-run-pytorch-data.py
21+
```
22+
23+
Please refer to [the documentation](https://aka.ms/day1aml) for more details on these files.
24+
25+
![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/tutorials/get-started-day1/IDE/README.png)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
name: pytorch-env
3+
channels:
4+
- defaults
5+
- pytorch
6+
dependencies:
7+
- python=3.6.2
8+
- pytorch
9+
- torchvision
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
print("hello world!")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import torch.nn as nn
2+
import torch.nn.functional as F
3+
4+
5+
class Net(nn.Module):
6+
def __init__(self):
7+
super(Net, self).__init__()
8+
self.conv1 = nn.Conv2d(3, 6, 5)
9+
self.pool = nn.MaxPool2d(2, 2)
10+
self.conv2 = nn.Conv2d(6, 16, 5)
11+
self.fc1 = nn.Linear(16 * 5 * 5, 120)
12+
self.fc2 = nn.Linear(120, 84)
13+
self.fc3 = nn.Linear(84, 10)
14+
15+
def forward(self, x):
16+
x = self.pool(F.relu(self.conv1(x)))
17+
x = self.pool(F.relu(self.conv2(x)))
18+
x = x.view(-1, 16 * 5 * 5)
19+
x = F.relu(self.fc1(x))
20+
x = F.relu(self.fc2(x))
21+
x = self.fc3(x)
22+
return x

0 commit comments

Comments
 (0)