Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove alpha from pipeline parameters #169

Merged
merged 11 commits into from
Feb 1, 2020
12 changes: 1 addition & 11 deletions .pipelines/diabetes_regression-ci-build-train.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,20 @@ stages:
echo "##vso[task.setvariable variable=AMLPIPELINEID;isOutput=true]$AMLPIPELINEID"
name: 'getpipelineid'
displayName: 'Get Pipeline ID'
- bash: |
# Generate a hyperparameter value as a random number between 0 and 1.
# A random value is used here to make the Azure ML dashboards "interesting" when testing
# the solution sample.
alpha=$(printf "0.%03d\n" $((($RANDOM*1000)/32767)))
echo "Alpha: $alpha"
echo "##vso[task.setvariable variable=ALPHA;isOutput=true]$alpha"
name: 'getalpha'
displayName: 'Generate random value for hyperparameter alpha'
- job: "Run_ML_Pipeline"
dependsOn: "Get_Pipeline_ID"
displayName: "Trigger ML Training Pipeline"
pool: server
variables:
AMLPIPELINE_ID: $[ dependencies.Get_Pipeline_ID.outputs['getpipelineid.AMLPIPELINEID'] ]
ALPHA: $[ dependencies.Get_Pipeline_ID.outputs['getalpha.ALPHA'] ]
steps:
- task: ms-air-aiagility.vss-services-azureml.azureml-restApi-task.MLPublishedPipelineRestAPITask@0
displayName: 'Invoke ML pipeline'
inputs:
azureSubscription: '$(WORKSPACE_SVC_CONNECTION)'
PipelineId: '$(AMLPIPELINE_ID)'
ExperimentName: '$(EXPERIMENT_NAME)'
PipelineParameters: '"ParameterAssignments": {"model_name": "$(MODEL_NAME)", "hyperparameter_alpha": "$(ALPHA)"}'
PipelineParameters: '"ParameterAssignments": {"model_name": "$(MODEL_NAME)"}'
- job: "Training_Run_Report"
dependsOn: "Run_ML_Pipeline"
condition: always()
Expand Down
3 changes: 3 additions & 0 deletions diabetes_regression/training/train.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"alpha": 0.4
}
25 changes: 16 additions & 9 deletions diabetes_regression/training/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
from sklearn.externals import joblib
import json


def train_model(run, data, alpha):
Expand All @@ -47,6 +48,12 @@ def train_model(run, data, alpha):
return reg


def get_model_parameters():
with open("train.json") as f:
sbaidachni marked this conversation as resolved.
Show resolved Hide resolved
data = json.load(f)
return data


def main():
print("Running train.py")

Expand All @@ -62,13 +69,6 @@ def main():
help="Name of the Model",
default="sklearn_regression_model.pkl",
)
parser.add_argument(
"--alpha",
type=float,
default=0.5,
help=("Ridge regression regularization strength hyperparameter; "
"must be a positive float.")
)

parser.add_argument(
"--dataset_name",
Expand All @@ -79,14 +79,21 @@ def main():

print("Argument [build_id]: %s" % args.build_id)
print("Argument [model_name]: %s" % args.model_name)
print("Argument [alpha]: %s" % args.alpha)
print("Argument [dataset_name]: %s" % args.dataset_name)

model_name = args.model_name
build_id = args.build_id
alpha = args.alpha
dataset_name = args.dataset_name

print("Getting training parameters")

pars = get_model_parameters()
alpha = pars.get("alpha")
if alpha is None:
alpha = 0.5

print("Parameter alpha: %s" % alpha)

run = Run.get_context()
ws = run.experiment.workspace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ def main():
name="model_name", default_value=e.model_name)
build_id_param = PipelineParameter(
name="build_id", default_value=e.build_id)
hyperparameter_alpha_param = PipelineParameter(
name="hyperparameter_alpha", default_value=0.5)

dataset_name = ""
if (e.datastore_name is not None and e.datafile_name is not None):
Expand All @@ -70,7 +68,6 @@ def main():
arguments=[
"--build_id", build_id_param,
"--model_name", model_name_param,
"--alpha", hyperparameter_alpha_param,
"--dataset_name", dataset_name,
],
runconfig=run_config,
Expand Down