mirror of
https://github.com/Azure/MachineLearningNotebooks.git
synced 2025-12-20 01:27:06 -05:00
Compare commits
31 Commits
ak/revert-
...
sdk-codete
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a145086d8 | ||
|
|
cb695c91ce | ||
|
|
de505d67bd | ||
|
|
f19cfa4630 | ||
|
|
7eed2e4b56 | ||
|
|
57b0f701f8 | ||
|
|
7db93bcb1d | ||
|
|
fcbe925640 | ||
|
|
bedfbd649e | ||
|
|
fb760f648d | ||
|
|
a9a0713d2f | ||
|
|
c9d018b52c | ||
|
|
53dbd0afcf | ||
|
|
e3a64b1f16 | ||
|
|
732eecfc7c | ||
|
|
6995c086ff | ||
|
|
80bba4c7ae | ||
|
|
3c581b533f | ||
|
|
cc688caa4e | ||
|
|
da225e116e | ||
|
|
73c5d02880 | ||
|
|
e472b54f1b | ||
|
|
716c6d8bb1 | ||
|
|
23189c6f40 | ||
|
|
361b57ed29 | ||
|
|
3f531fd211 | ||
|
|
111f5e8d73 | ||
|
|
96c59d5c2b | ||
|
|
ce3214b7c6 | ||
|
|
53199d17de | ||
|
|
54c883412c |
7
.amlignore
Normal file
7
.amlignore
Normal file
@@ -0,0 +1,7 @@
|
||||
.ipynb_checkpoints
|
||||
azureml-logs
|
||||
.azureml
|
||||
.git
|
||||
outputs
|
||||
azureml-setup
|
||||
docs
|
||||
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"python.pythonPath": "C:\\Users\\sgilley\\.azureml\\envs\\jan3\\python.exe"
|
||||
}
|
||||
15
aml_config/conda_dependencies.yml
Normal file
15
aml_config/conda_dependencies.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
# Conda environment specification. The dependencies defined in this file will
|
||||
|
||||
# be automatically provisioned for runs with userManagedDependencies=False.
|
||||
|
||||
|
||||
# Details about the Conda environment file format:
|
||||
|
||||
# https://conda.io/docs/user-guide/tasks/manage-environments.html#create-env-file-manually
|
||||
|
||||
|
||||
name: project_environment
|
||||
dependencies:
|
||||
# The python interpreter version.
|
||||
|
||||
# Currently Azure ML only supports 3.5.2 and later.
|
||||
115
aml_config/docker.runconfig
Normal file
115
aml_config/docker.runconfig
Normal file
@@ -0,0 +1,115 @@
|
||||
# The script to run.
|
||||
script: train.py
|
||||
# The arguments to the script file.
|
||||
arguments: []
|
||||
# The name of the compute target to use for this run.
|
||||
target: local
|
||||
# Framework to execute inside. Allowed values are "Python" , "PySpark", "CNTK", "TensorFlow", and "PyTorch".
|
||||
framework: PySpark
|
||||
# Communicator for the given framework. Allowed values are "None" , "ParameterServer", "OpenMpi", and "IntelMpi".
|
||||
communicator: None
|
||||
# Automatically prepare the run environment as part of the run itself.
|
||||
autoPrepareEnvironment: true
|
||||
# Maximum allowed duration for the run.
|
||||
maxRunDurationSeconds:
|
||||
# Number of nodes to use for running job.
|
||||
nodeCount: 1
|
||||
# Environment details.
|
||||
environment:
|
||||
# Environment variables set for the run.
|
||||
environmentVariables:
|
||||
EXAMPLE_ENV_VAR: EXAMPLE_VALUE
|
||||
# Python details
|
||||
python:
|
||||
# user_managed_dependencies=True indicates that the environmentwill be user managed. False indicates that AzureML willmanage the user environment.
|
||||
userManagedDependencies: false
|
||||
# The python interpreter path
|
||||
interpreterPath: python
|
||||
# Path to the conda dependencies file to use for this run. If a project
|
||||
# contains multiple programs with different sets of dependencies, it may be
|
||||
# convenient to manage those environments with separate files.
|
||||
condaDependenciesFile: aml_config/conda_dependencies.yml
|
||||
# Docker details
|
||||
docker:
|
||||
# Set True to perform this run inside a Docker container.
|
||||
enabled: true
|
||||
# Base image used for Docker-based runs.
|
||||
baseImage: mcr.microsoft.com/azureml/base:0.2.0
|
||||
# Set False if necessary to work around shared volume bugs.
|
||||
sharedVolumes: true
|
||||
# Run with NVidia Docker extension to support GPUs.
|
||||
gpuSupport: false
|
||||
# Extra arguments to the Docker run command.
|
||||
arguments: []
|
||||
# Image registry that contains the base image.
|
||||
baseImageRegistry:
|
||||
# DNS name or IP address of azure container registry(ACR)
|
||||
address:
|
||||
# The username for ACR
|
||||
username:
|
||||
# The password for ACR
|
||||
password:
|
||||
# Spark details
|
||||
spark:
|
||||
# List of spark repositories.
|
||||
repositories:
|
||||
- https://mmlspark.azureedge.net/maven
|
||||
packages:
|
||||
- group: com.microsoft.ml.spark
|
||||
artifact: mmlspark_2.11
|
||||
version: '0.12'
|
||||
precachePackages: true
|
||||
# Databricks details
|
||||
databricks:
|
||||
# List of maven libraries.
|
||||
mavenLibraries: []
|
||||
# List of PyPi libraries
|
||||
pypiLibraries: []
|
||||
# List of RCran libraries
|
||||
rcranLibraries: []
|
||||
# List of JAR libraries
|
||||
jarLibraries: []
|
||||
# List of Egg libraries
|
||||
eggLibraries: []
|
||||
# History details.
|
||||
history:
|
||||
# Enable history tracking -- this allows status, logs, metrics, and outputs
|
||||
# to be collected for a run.
|
||||
outputCollection: true
|
||||
# whether to take snapshots for history.
|
||||
snapshotProject: true
|
||||
# Spark configuration details.
|
||||
spark:
|
||||
configuration:
|
||||
spark.app.name: Azure ML Experiment
|
||||
spark.yarn.maxAppAttempts: 1
|
||||
# HDI details.
|
||||
hdi:
|
||||
# Yarn deploy mode. Options are cluster and client.
|
||||
yarnDeployMode: cluster
|
||||
# Tensorflow details.
|
||||
tensorflow:
|
||||
# The number of worker tasks.
|
||||
workerCount: 1
|
||||
# The number of parameter server tasks.
|
||||
parameterServerCount: 1
|
||||
# Mpi details.
|
||||
mpi:
|
||||
# When using MPI, number of processes per node.
|
||||
processCountPerNode: 1
|
||||
# data reference configuration details
|
||||
dataReferences: {}
|
||||
# Project share datastore reference.
|
||||
sourceDirectoryDataStore:
|
||||
# AmlCompute details.
|
||||
amlcompute:
|
||||
# VM size of the Cluster to be created.Allowed values are Azure vm sizes.The list of vm sizes is available in 'https://docs.microsoft.com/en-us/azure/cloud-services/cloud-services-sizes-specs
|
||||
vmSize:
|
||||
# VM priority of the Cluster to be created.Allowed values are "dedicated" , "lowpriority".
|
||||
vmPriority:
|
||||
# A bool that indicates if the cluster has to be retained after job completion.
|
||||
retainCluster: false
|
||||
# Name of the cluster to be created. If not specified, runId will be used as cluster name.
|
||||
name:
|
||||
# Maximum number of nodes in the AmlCompute cluster to be created. Minimum number of nodes will always be set to 0.
|
||||
clusterMaxNodeCount: 1
|
||||
115
aml_config/local.runconfig
Normal file
115
aml_config/local.runconfig
Normal file
@@ -0,0 +1,115 @@
|
||||
# The script to run.
|
||||
script: train.py
|
||||
# The arguments to the script file.
|
||||
arguments: []
|
||||
# The name of the compute target to use for this run.
|
||||
target: local
|
||||
# Framework to execute inside. Allowed values are "Python" , "PySpark", "CNTK", "TensorFlow", and "PyTorch".
|
||||
framework: Python
|
||||
# Communicator for the given framework. Allowed values are "None" , "ParameterServer", "OpenMpi", and "IntelMpi".
|
||||
communicator: None
|
||||
# Automatically prepare the run environment as part of the run itself.
|
||||
autoPrepareEnvironment: true
|
||||
# Maximum allowed duration for the run.
|
||||
maxRunDurationSeconds:
|
||||
# Number of nodes to use for running job.
|
||||
nodeCount: 1
|
||||
# Environment details.
|
||||
environment:
|
||||
# Environment variables set for the run.
|
||||
environmentVariables:
|
||||
EXAMPLE_ENV_VAR: EXAMPLE_VALUE
|
||||
# Python details
|
||||
python:
|
||||
# user_managed_dependencies=True indicates that the environmentwill be user managed. False indicates that AzureML willmanage the user environment.
|
||||
userManagedDependencies: false
|
||||
# The python interpreter path
|
||||
interpreterPath: python
|
||||
# Path to the conda dependencies file to use for this run. If a project
|
||||
# contains multiple programs with different sets of dependencies, it may be
|
||||
# convenient to manage those environments with separate files.
|
||||
condaDependenciesFile: aml_config/conda_dependencies.yml
|
||||
# Docker details
|
||||
docker:
|
||||
# Set True to perform this run inside a Docker container.
|
||||
enabled: false
|
||||
# Base image used for Docker-based runs.
|
||||
baseImage: mcr.microsoft.com/azureml/base:0.2.0
|
||||
# Set False if necessary to work around shared volume bugs.
|
||||
sharedVolumes: true
|
||||
# Run with NVidia Docker extension to support GPUs.
|
||||
gpuSupport: false
|
||||
# Extra arguments to the Docker run command.
|
||||
arguments: []
|
||||
# Image registry that contains the base image.
|
||||
baseImageRegistry:
|
||||
# DNS name or IP address of azure container registry(ACR)
|
||||
address:
|
||||
# The username for ACR
|
||||
username:
|
||||
# The password for ACR
|
||||
password:
|
||||
# Spark details
|
||||
spark:
|
||||
# List of spark repositories.
|
||||
repositories:
|
||||
- https://mmlspark.azureedge.net/maven
|
||||
packages:
|
||||
- group: com.microsoft.ml.spark
|
||||
artifact: mmlspark_2.11
|
||||
version: '0.12'
|
||||
precachePackages: true
|
||||
# Databricks details
|
||||
databricks:
|
||||
# List of maven libraries.
|
||||
mavenLibraries: []
|
||||
# List of PyPi libraries
|
||||
pypiLibraries: []
|
||||
# List of RCran libraries
|
||||
rcranLibraries: []
|
||||
# List of JAR libraries
|
||||
jarLibraries: []
|
||||
# List of Egg libraries
|
||||
eggLibraries: []
|
||||
# History details.
|
||||
history:
|
||||
# Enable history tracking -- this allows status, logs, metrics, and outputs
|
||||
# to be collected for a run.
|
||||
outputCollection: true
|
||||
# whether to take snapshots for history.
|
||||
snapshotProject: true
|
||||
# Spark configuration details.
|
||||
spark:
|
||||
configuration:
|
||||
spark.app.name: Azure ML Experiment
|
||||
spark.yarn.maxAppAttempts: 1
|
||||
# HDI details.
|
||||
hdi:
|
||||
# Yarn deploy mode. Options are cluster and client.
|
||||
yarnDeployMode: cluster
|
||||
# Tensorflow details.
|
||||
tensorflow:
|
||||
# The number of worker tasks.
|
||||
workerCount: 1
|
||||
# The number of parameter server tasks.
|
||||
parameterServerCount: 1
|
||||
# Mpi details.
|
||||
mpi:
|
||||
# When using MPI, number of processes per node.
|
||||
processCountPerNode: 1
|
||||
# data reference configuration details
|
||||
dataReferences: {}
|
||||
# Project share datastore reference.
|
||||
sourceDirectoryDataStore:
|
||||
# AmlCompute details.
|
||||
amlcompute:
|
||||
# VM size of the Cluster to be created.Allowed values are Azure vm sizes.The list of vm sizes is available in 'https://docs.microsoft.com/en-us/azure/cloud-services/cloud-services-sizes-specs
|
||||
vmSize:
|
||||
# VM priority of the Cluster to be created.Allowed values are "dedicated" , "lowpriority".
|
||||
vmPriority:
|
||||
# A bool that indicates if the cluster has to be retained after job completion.
|
||||
retainCluster: false
|
||||
# Name of the cluster to be created. If not specified, runId will be used as cluster name.
|
||||
name:
|
||||
# Maximum number of nodes in the AmlCompute cluster to be created. Minimum number of nodes will always be set to 0.
|
||||
clusterMaxNodeCount: 1
|
||||
1
aml_config/project.json
Normal file
1
aml_config/project.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Id": "local-compute", "Scope": "/subscriptions/65a1016d-0f67-45d2-b838-b8f373d6d52e/resourceGroups/sheri/providers/Microsoft.MachineLearningServices/workspaces/sheritestqs3/projects/local-compute"}
|
||||
174
ignore/doc-qa/how-to-deploy-to-aci/how-to-deploy-to-aci.py
Normal file
174
ignore/doc-qa/how-to-deploy-to-aci/how-to-deploy-to-aci.py
Normal file
@@ -0,0 +1,174 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
import azureml.core
|
||||
print('SDK version' + azureml.core.VERSION)
|
||||
|
||||
# PREREQ: load workspace info
|
||||
# import azureml.core
|
||||
|
||||
# <loadWorkspace>
|
||||
from azureml.core import Workspace
|
||||
ws = Workspace.from_config()
|
||||
# </loadWorkspace>
|
||||
|
||||
scorepy_content = "import json\nimport numpy as np\nimport os\nimport pickle\nfrom sklearn.externals import joblib\nfrom sklearn.linear_model import LogisticRegression\n\nfrom azureml.core.model import Model\n\ndef init():\n global model\n # retreive the path to the model file using the model name\n model_path = Model.get_model_path('sklearn_mnist')\n model = joblib.load(model_path)\n\ndef run(raw_data):\n data = np.array(json.loads(raw_data)['data'])\n # make prediction\n y_hat = model.predict(data)\n return json.dumps(y_hat.tolist())"
|
||||
print(scorepy_content)
|
||||
with open("score.py","w") as f:
|
||||
f.write(scorepy_content)
|
||||
|
||||
|
||||
# PREREQ: create environment file
|
||||
from azureml.core.conda_dependencies import CondaDependencies
|
||||
|
||||
myenv = CondaDependencies()
|
||||
myenv.add_conda_package("scikit-learn")
|
||||
|
||||
with open("myenv.yml","w") as f:
|
||||
f.write(myenv.serialize_to_string())
|
||||
|
||||
#<configImage>
|
||||
from azureml.core.image import ContainerImage
|
||||
|
||||
image_config = ContainerImage.image_configuration(execution_script = "score.py",
|
||||
runtime = "python",
|
||||
conda_file = "myenv.yml",
|
||||
description = "Image with mnist model",
|
||||
tags = {"data": "mnist", "type": "classification"}
|
||||
)
|
||||
#</configImage>
|
||||
|
||||
# <configAci>
|
||||
from azureml.core.webservice import AciWebservice
|
||||
|
||||
aciconfig = AciWebservice.deploy_configuration(cpu_cores = 1,
|
||||
memory_gb = 1,
|
||||
tags = {"data": "mnist", "type": "classification"},
|
||||
description = 'Handwriting recognition')
|
||||
# </configAci>
|
||||
|
||||
#<registerModel>
|
||||
from azureml.core.model import Model
|
||||
|
||||
model_name = "sklearn_mnist"
|
||||
model = Model.register(model_path = "sklearn_mnist_model.pkl",
|
||||
model_name = model_name,
|
||||
tags = {"data": "mnist", "type": "classification"},
|
||||
description = "Mnist handwriting recognition",
|
||||
workspace = ws)
|
||||
#</registerModel>
|
||||
|
||||
# <retrieveModel>
|
||||
from azureml.core.model import Model
|
||||
|
||||
model_name = "sklearn_mnist"
|
||||
model=Model(ws, model_name)
|
||||
# </retrieveModel>
|
||||
|
||||
|
||||
# ## DEPLOY FROM REGISTERED MODEL
|
||||
|
||||
# <option2Deploy>
|
||||
from azureml.core.webservice import Webservice
|
||||
|
||||
service_name = 'aci-mnist-2'
|
||||
service = Webservice.deploy_from_model(deployment_config = aciconfig,
|
||||
image_config = image_config,
|
||||
models = [model], # this is the registered model object
|
||||
name = service_name,
|
||||
workspace = ws)
|
||||
service.wait_for_deployment(show_output = True)
|
||||
print(service.state)
|
||||
# </option2Deploy>
|
||||
|
||||
service.delete()
|
||||
|
||||
# ## DEPLOY FROM IMAGE
|
||||
|
||||
|
||||
# <option3CreateImage>
|
||||
from azureml.core.image import ContainerImage
|
||||
|
||||
image = ContainerImage.create(name = "myimage1",
|
||||
models = [model], # this is the registered model object
|
||||
image_config = image_config,
|
||||
workspace = ws)
|
||||
|
||||
image.wait_for_creation(show_output = True)
|
||||
# </option3CreateImage>
|
||||
|
||||
# <option3Deploy>
|
||||
from azureml.core.webservice import Webservice
|
||||
|
||||
service_name = 'aci-mnist-13'
|
||||
service = Webservice.deploy_from_image(deployment_config = aciconfig,
|
||||
image = image,
|
||||
name = service_name,
|
||||
workspace = ws)
|
||||
service.wait_for_deployment(show_output = True)
|
||||
print(service.state)
|
||||
# </option3Deploy>
|
||||
|
||||
service.delete()
|
||||
|
||||
|
||||
# ## DEPLOY FROM MODEL FILE
|
||||
# First change score.py!
|
||||
|
||||
|
||||
|
||||
scorepy_content = "import json\nimport numpy as np\nimport os\nimport pickle\nfrom sklearn.externals import joblib\nfrom sklearn.linear_model import LogisticRegression\n\nfrom azureml.core.model import Model\n\ndef init():\n global model\n # retreive the path to the model file using the model name\n model_path = Model.get_model_path('sklearn_mnist_model.pkl')\n model = joblib.load(model_path)\n\ndef run(raw_data):\n data = np.array(json.loads(raw_data)['data'])\n # make prediction\n y_hat = model.predict(data)\n return json.dumps(y_hat.tolist())"
|
||||
with open("score.py","w") as f:
|
||||
f.write(scorepy_content)
|
||||
|
||||
|
||||
|
||||
# <option1Deploy>
|
||||
from azureml.core.webservice import Webservice
|
||||
|
||||
service_name = 'aci-mnist-1'
|
||||
service = Webservice.deploy(deployment_config = aciconfig,
|
||||
image_config = image_config,
|
||||
model_paths = ['sklearn_mnist_model.pkl'],
|
||||
name = service_name,
|
||||
workspace = ws)
|
||||
|
||||
service.wait_for_deployment(show_output = True)
|
||||
print(service.state)
|
||||
# </option1Deploy>
|
||||
|
||||
# <testService>
|
||||
# Load Data
|
||||
import os
|
||||
import urllib
|
||||
|
||||
os.makedirs('./data', exist_ok = True)
|
||||
|
||||
urllib.request.urlretrieve('http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz', filename = './data/test-images.gz')
|
||||
|
||||
from utils import load_data
|
||||
X_test = load_data('./data/test-images.gz', False) / 255.0
|
||||
|
||||
from sklearn import datasets
|
||||
import numpy as np
|
||||
import json
|
||||
|
||||
# find 5 random samples from test set
|
||||
n = 5
|
||||
sample_indices = np.random.permutation(X_test.shape[0])[0:n]
|
||||
|
||||
test_samples = json.dumps({"data": X_test[sample_indices].tolist()})
|
||||
test_samples = bytes(test_samples, encoding = 'utf8')
|
||||
|
||||
# predict using the deployed model
|
||||
prediction = service.run(input_data = test_samples)
|
||||
print(prediction)
|
||||
# </testService>
|
||||
|
||||
# <deleteService>
|
||||
service.delete()
|
||||
# </deleteService>
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
ignore/doc-qa/how-to-deploy-to-aci/sklearn_mnist_model.pkl
Normal file
BIN
ignore/doc-qa/how-to-deploy-to-aci/sklearn_mnist_model.pkl
Normal file
Binary file not shown.
27
ignore/doc-qa/how-to-deploy-to-aci/utils.py
Normal file
27
ignore/doc-qa/how-to-deploy-to-aci/utils.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
import gzip
|
||||
import numpy as np
|
||||
import struct
|
||||
|
||||
|
||||
# load compressed MNIST gz files and return numpy arrays
|
||||
def load_data(filename, label=False):
|
||||
with gzip.open(filename) as gz:
|
||||
struct.unpack('I', gz.read(4))
|
||||
n_items = struct.unpack('>I', gz.read(4))
|
||||
if not label:
|
||||
n_rows = struct.unpack('>I', gz.read(4))[0]
|
||||
n_cols = struct.unpack('>I', gz.read(4))[0]
|
||||
res = np.frombuffer(gz.read(n_items[0] * n_rows * n_cols), dtype=np.uint8)
|
||||
res = res.reshape(n_items[0], n_rows * n_cols)
|
||||
else:
|
||||
res = np.frombuffer(gz.read(n_items[0]), dtype=np.uint8)
|
||||
res = res.reshape(n_items[0], 1)
|
||||
return res
|
||||
|
||||
|
||||
# one-hot encode a 1-D array
|
||||
def one_hot_encode(array, num_of_classes):
|
||||
return np.eye(num_of_classes)[array.reshape(-1)]
|
||||
39
ignore/doc-qa/how-to-set-up-training-targets/Local.py
Normal file
39
ignore/doc-qa/how-to-set-up-training-targets/Local.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# Code for Local computer and Submit training run sections
|
||||
|
||||
# Check core SDK version number
|
||||
import azureml.core
|
||||
|
||||
print("SDK version:", azureml.core.VERSION)
|
||||
|
||||
#<run_local>
|
||||
from azureml.core.runconfig import RunConfiguration
|
||||
|
||||
# Edit a run configuration property on the fly.
|
||||
run_local = RunConfiguration()
|
||||
|
||||
run_local.environment.python.user_managed_dependencies = True
|
||||
#</run_local>
|
||||
|
||||
from azureml.core import Workspace
|
||||
ws = Workspace.from_config()
|
||||
|
||||
|
||||
# Set up an experiment
|
||||
# <experiment>
|
||||
from azureml.core import Experiment
|
||||
experiment_name = 'my_experiment'
|
||||
|
||||
exp = Experiment(workspace=ws, name=experiment_name)
|
||||
# </experiment>
|
||||
|
||||
# Submit the experiment using the run configuration
|
||||
#<local_submit>
|
||||
from azureml.core import ScriptRunConfig
|
||||
import os
|
||||
|
||||
script_folder = os.getcwd()
|
||||
src = ScriptRunConfig(source_directory = script_folder, script = 'train.py', run_config = run_local)
|
||||
run = exp.submit(src)
|
||||
run.wait_for_completion(show_output = True)
|
||||
#</local_submit>
|
||||
|
||||
48
ignore/doc-qa/how-to-set-up-training-targets/amlcompute.py
Normal file
48
ignore/doc-qa/how-to-set-up-training-targets/amlcompute.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# Code for Azure Machine Learning Compute - Run-based creation
|
||||
|
||||
# Check core SDK version number
|
||||
import azureml.core
|
||||
|
||||
print("SDK version:", azureml.core.VERSION)
|
||||
|
||||
|
||||
from azureml.core import Workspace
|
||||
ws = Workspace.from_config()
|
||||
|
||||
|
||||
# Set up an experiment
|
||||
from azureml.core import Experiment
|
||||
experiment_name = 'my-experiment'
|
||||
script_folder= "./"
|
||||
|
||||
exp = Experiment(workspace=ws, name=experiment_name)
|
||||
|
||||
|
||||
#<run_temp_compute>
|
||||
from azureml.core.compute import ComputeTarget, AmlCompute
|
||||
|
||||
# First, list the supported VM families for Azure Machine Learning Compute
|
||||
print(AmlCompute.supported_vmsizes(workspace=ws))
|
||||
|
||||
from azureml.core.runconfig import RunConfiguration
|
||||
# Create a new runconfig object
|
||||
run_temp_compute = RunConfiguration()
|
||||
|
||||
# Signal that you want to use AmlCompute to execute the script
|
||||
run_temp_compute.target = "amlcompute"
|
||||
|
||||
# AmlCompute is created in the same region as your workspace
|
||||
# Set the VM size for AmlCompute from the list of supported_vmsizes
|
||||
run_temp_compute.amlcompute.vm_size = 'STANDARD_D2_V2'
|
||||
#</run_temp_compute>
|
||||
|
||||
|
||||
# Submit the experiment using the run configuration
|
||||
from azureml.core import ScriptRunConfig
|
||||
|
||||
src = ScriptRunConfig(source_directory = script_folder, script = 'train.py', run_config = run_temp_compute)
|
||||
run = exp.submit(src)
|
||||
run.wait_for_completion(show_output = True)
|
||||
|
||||
|
||||
|
||||
70
ignore/doc-qa/how-to-set-up-training-targets/amlcompute2.py
Normal file
70
ignore/doc-qa/how-to-set-up-training-targets/amlcompute2.py
Normal file
@@ -0,0 +1,70 @@
|
||||
# Code for Azure Machine Learning Compute - Persistent compute
|
||||
|
||||
# Check core SDK version number
|
||||
import azureml.core
|
||||
|
||||
print("SDK version:", azureml.core.VERSION)
|
||||
|
||||
from azureml.core import Workspace
|
||||
ws = Workspace.from_config()
|
||||
|
||||
|
||||
# Set up an experiment
|
||||
from azureml.core import Experiment
|
||||
experiment_name = 'my-experiment'
|
||||
script_folder= "./"
|
||||
|
||||
exp = Experiment(workspace=ws, name=experiment_name)
|
||||
|
||||
#<cpu_cluster>
|
||||
from azureml.core.compute import ComputeTarget, AmlCompute
|
||||
from azureml.core.compute_target import ComputeTargetException
|
||||
|
||||
# Choose a name for your CPU cluster
|
||||
cpu_cluster_name = "cpucluster"
|
||||
|
||||
# Verify that cluster does not exist already
|
||||
try:
|
||||
cpu_cluster = ComputeTarget(workspace=ws, name=cpu_cluster_name)
|
||||
print('Found existing cluster, use it.')
|
||||
except ComputeTargetException:
|
||||
# To use a different region for the compute, add a location='<region>' parameter
|
||||
compute_config = AmlCompute.provisioning_configuration(vm_size='STANDARD_D2_V2',
|
||||
max_nodes=4)
|
||||
cpu_cluster = ComputeTarget.create(ws, cpu_cluster_name, compute_config)
|
||||
|
||||
cpu_cluster.wait_for_completion(show_output=True)
|
||||
#</cpu_cluster>
|
||||
|
||||
#<run_amlcompute>
|
||||
from azureml.core.runconfig import RunConfiguration
|
||||
from azureml.core.conda_dependencies import CondaDependencies
|
||||
from azureml.core.runconfig import DEFAULT_CPU_IMAGE
|
||||
|
||||
# Create a new runconfig object
|
||||
run_amlcompute = RunConfiguration()
|
||||
|
||||
# Use the cpu_cluster you created above.
|
||||
run_amlcompute.target = cpu_cluster
|
||||
|
||||
# Enable Docker
|
||||
run_amlcompute.environment.docker.enabled = True
|
||||
|
||||
# Set Docker base image to the default CPU-based image
|
||||
run_amlcompute.environment.docker.base_image = DEFAULT_CPU_IMAGE
|
||||
|
||||
# Use conda_dependencies.yml to create a conda environment in the Docker image for execution
|
||||
run_amlcompute.environment.python.user_managed_dependencies = False
|
||||
|
||||
# Specify CondaDependencies obj, add necessary packages
|
||||
run_amlcompute.environment.python.conda_dependencies = CondaDependencies.create(conda_packages=['scikit-learn'])
|
||||
#</run_amlcompute>
|
||||
|
||||
# Submit the experiment using the run configuration
|
||||
#<amlcompute_submit>
|
||||
from azureml.core import ScriptRunConfig
|
||||
|
||||
src = ScriptRunConfig(source_directory = script_folder, script = 'train.py', run_config = run_amlcompute)
|
||||
run = exp.submit(src)
|
||||
run.wait_for_completion(show_output = True)
|
||||
#</amlcompute_submit>
|
||||
26
ignore/doc-qa/how-to-set-up-training-targets/dsvm.py
Normal file
26
ignore/doc-qa/how-to-set-up-training-targets/dsvm.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Code for Remote virtual machines
|
||||
|
||||
compute_target_name = "sheri-linuxvm"
|
||||
|
||||
#<run_dsvm>
|
||||
import azureml.core
|
||||
from azureml.core.runconfig import RunConfiguration
|
||||
from azureml.core.conda_dependencies import CondaDependencies
|
||||
|
||||
run_dsvm = RunConfiguration(framework = "python")
|
||||
|
||||
# Set the compute target to the Linux DSVM
|
||||
run_dsvm.target = compute_target_name
|
||||
|
||||
# Use Docker in the remote VM
|
||||
run_dsvm.environment.docker.enabled = True
|
||||
|
||||
# Use the CPU base image
|
||||
# To use GPU in DSVM, you must also use the GPU base Docker image "azureml.core.runconfig.DEFAULT_GPU_IMAGE"
|
||||
run_dsvm.environment.docker.base_image = azureml.core.runconfig.DEFAULT_CPU_IMAGE
|
||||
print('Base Docker image is:', run_dsvm.environment.docker.base_image)
|
||||
|
||||
# Specify the CondaDependencies object
|
||||
run_dsvm.environment.python.conda_dependencies = CondaDependencies.create(conda_packages=['scikit-learn'])
|
||||
#</run_dsvm>
|
||||
print(run_dsvm)
|
||||
27
ignore/doc-qa/how-to-set-up-training-targets/hdi.py
Normal file
27
ignore/doc-qa/how-to-set-up-training-targets/hdi.py
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
from azureml.core import Workspace
|
||||
ws = Workspace.from_config()
|
||||
|
||||
from azureml.core.compute import ComputeTarget
|
||||
|
||||
# refers to an existing compute resource attached to the workspace!
|
||||
hdi_compute = ComputeTarget(workspace=ws, name='sherihdi')
|
||||
|
||||
|
||||
#<run_hdi>
|
||||
from azureml.core.runconfig import RunConfiguration
|
||||
from azureml.core.conda_dependencies import CondaDependencies
|
||||
|
||||
|
||||
# use pyspark framework
|
||||
run_hdi = RunConfiguration(framework="pyspark")
|
||||
|
||||
# Set compute target to the HDI cluster
|
||||
run_hdi.target = hdi_compute.name
|
||||
|
||||
# specify CondaDependencies object to ask system installing numpy
|
||||
cd = CondaDependencies()
|
||||
cd.add_conda_package('numpy')
|
||||
run_hdi.environment.python.conda_dependencies = cd
|
||||
#</run_hdi>
|
||||
print(run_hdi)
|
||||
9
ignore/doc-qa/how-to-set-up-training-targets/mylib.py
Normal file
9
ignore/doc-qa/how-to-set-up-training-targets/mylib.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
# Licensed under the MIT license.
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
def get_alphas():
|
||||
# list of numbers from 0.0 to 1.0 with a 0.05 interval
|
||||
return np.arange(0.0, 1.0, 0.05)
|
||||
52
ignore/doc-qa/how-to-set-up-training-targets/remote.py
Normal file
52
ignore/doc-qa/how-to-set-up-training-targets/remote.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# Code for Remote virtual machines
|
||||
|
||||
compute_target_name = "attach-dsvm"
|
||||
|
||||
#<run_dsvm>
|
||||
import azureml.core
|
||||
from azureml.core.runconfig import RunConfiguration, DEFAULT_CPU_IMAGE
|
||||
from azureml.core.conda_dependencies import CondaDependencies
|
||||
|
||||
run_dsvm = RunConfiguration(framework = "python")
|
||||
|
||||
# Set the compute target to the Linux DSVM
|
||||
run_dsvm.target = compute_target_name
|
||||
|
||||
# Use Docker in the remote VM
|
||||
run_dsvm.environment.docker.enabled = True
|
||||
|
||||
# Use the CPU base image
|
||||
# To use GPU in DSVM, you must also use the GPU base Docker image "azureml.core.runconfig.DEFAULT_GPU_IMAGE"
|
||||
run_dsvm.environment.docker.base_image = azureml.core.runconfig.DEFAULT_CPU_IMAGE
|
||||
print('Base Docker image is:', run_dsvm.environment.docker.base_image)
|
||||
|
||||
# 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>
|
||||
25
ignore/doc-qa/how-to-set-up-training-targets/runconfig.py
Normal file
25
ignore/doc-qa/how-to-set-up-training-targets/runconfig.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Code for What's a run configuration
|
||||
|
||||
# <run_system_managed>
|
||||
from azureml.core.runconfig import RunConfiguration
|
||||
from azureml.core.conda_dependencies import CondaDependencies
|
||||
|
||||
run_system_managed = RunConfiguration()
|
||||
|
||||
# Specify the conda dependencies with scikit-learn
|
||||
run_system_managed.environment.python.conda_dependencies = CondaDependencies.create(conda_packages=['scikit-learn'])
|
||||
# </run_system_managed>
|
||||
print(run_system_managed)
|
||||
|
||||
|
||||
# <run_user_managed>
|
||||
from azureml.core.runconfig import RunConfiguration
|
||||
|
||||
run_user_managed = RunConfiguration()
|
||||
run_user_managed.environment.python.user_managed_dependencies = True
|
||||
|
||||
# Choose a specific Python environment by pointing to a Python path. For example:
|
||||
# run_config.environment.python.interpreter_path = '/home/ninghai/miniconda3/envs/sdk2/bin/python'
|
||||
# </run_user_managed>
|
||||
print(run_user_managed)
|
||||
|
||||
45
ignore/doc-qa/how-to-set-up-training-targets/train.py
Normal file
45
ignore/doc-qa/how-to-set-up-training-targets/train.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
# Licensed under the MIT license.
|
||||
|
||||
from sklearn.datasets import load_diabetes
|
||||
from sklearn.linear_model import Ridge
|
||||
from sklearn.metrics import mean_squared_error
|
||||
from sklearn.model_selection import train_test_split
|
||||
from azureml.core.run import Run
|
||||
from sklearn.externals import joblib
|
||||
import os
|
||||
import numpy as np
|
||||
import mylib
|
||||
|
||||
os.makedirs('./outputs', exist_ok=True)
|
||||
|
||||
X, y = load_diabetes(return_X_y=True)
|
||||
|
||||
run = Run.get_context()
|
||||
|
||||
X_train, X_test, y_train, y_test = train_test_split(X, y,
|
||||
test_size=0.2,
|
||||
random_state=0)
|
||||
data = {"train": {"X": X_train, "y": y_train},
|
||||
"test": {"X": X_test, "y": y_test}}
|
||||
|
||||
# list of numbers from 0.0 to 1.0 with a 0.05 interval
|
||||
alphas = mylib.get_alphas()
|
||||
|
||||
for alpha in alphas:
|
||||
# Use Ridge algorithm to create a regression model
|
||||
reg = Ridge(alpha=alpha)
|
||||
reg.fit(data["train"]["X"], data["train"]["y"])
|
||||
|
||||
preds = reg.predict(data["test"]["X"])
|
||||
mse = mean_squared_error(preds, data["test"]["y"])
|
||||
run.log('alpha', alpha)
|
||||
run.log('mse', mse)
|
||||
|
||||
model_file_name = 'ridge_{0:.2f}.pkl'.format(alpha)
|
||||
# save model in the outputs folder so it automatically get uploaded
|
||||
with open(model_file_name, "wb") as file:
|
||||
joblib.dump(value=reg, filename=os.path.join('./outputs/',
|
||||
model_file_name))
|
||||
|
||||
print('alpha is {0:.2f}, and mse is {1:0.2f}'.format(alpha, mse))
|
||||
@@ -0,0 +1,55 @@
|
||||
# code snippets for the quickstart-create-workspace-with-python article
|
||||
# <import>
|
||||
import azureml.core
|
||||
print(azureml.core.VERSION)
|
||||
# </import>
|
||||
|
||||
# this is NOT a snippet. If this code changes, go fix it in the article!
|
||||
from azureml.core import Workspace
|
||||
ws = Workspace.create(name='myworkspace',
|
||||
subscription_id='<subscription-id>',
|
||||
resource_group='myresourcegroup',
|
||||
create_resource_group=True,
|
||||
location='eastus2' # or other supported Azure region
|
||||
)
|
||||
|
||||
# <getDetails>
|
||||
ws.get_details()
|
||||
# </getDetails>
|
||||
|
||||
# <writeConfig>
|
||||
# Create the configuration file.
|
||||
ws.write_config()
|
||||
|
||||
# Use this code to load the workspace from
|
||||
# other scripts and notebooks in this directory.
|
||||
# ws = Workspace.from_config()
|
||||
# </writeConfig>
|
||||
|
||||
# <useWs>
|
||||
from azureml.core import Experiment
|
||||
|
||||
# Create a new experiment in your workspace.
|
||||
exp = Experiment(workspace=ws, name='myexp')
|
||||
|
||||
# Start a run and start the logging service.
|
||||
run = exp.start_logging()
|
||||
|
||||
# Log a single number.
|
||||
run.log('my magic number', 42)
|
||||
|
||||
# Log a list (Fibonacci numbers).
|
||||
run.log_list('my list', [1, 1, 2, 3, 5, 8, 13, 21, 34, 55])
|
||||
|
||||
# Finish the run.
|
||||
run.complete()
|
||||
# </useWs>
|
||||
|
||||
# <viewLog>
|
||||
print(run.get_portal_url())
|
||||
# </viewLog>
|
||||
|
||||
|
||||
# <delete>
|
||||
ws.delete(delete_dependent_resources=True)
|
||||
# </delete>
|
||||
67
ignore/doc-qa/testnotebook.ipynb
Normal file
67
ignore/doc-qa/testnotebook.ipynb
Normal file
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Testing notebook include"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"name": "import"
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Azure ML SDK Version: 1.0.83\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%matplotlib inline\n",
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"\n",
|
||||
"import azureml.core\n",
|
||||
"from azureml.core import Workspace\n",
|
||||
"\n",
|
||||
"# check core SDK version number\n",
|
||||
"print(\"Azure ML SDK Version: \", azureml.core.VERSION)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"celltoolbar": "Edit Metadata",
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.6 - AzureML",
|
||||
"language": "python",
|
||||
"name": "python3-azureml"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.6.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -58,6 +58,7 @@
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"name": "import",
|
||||
"tags": [
|
||||
"check version"
|
||||
]
|
||||
@@ -723,4 +724,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user