Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

create_rai_job:
type: command
component: azureml://registries/azureml/components/rai_tabular_insight_constructor/versions/0.18.0
component: azureml://registries/azureml/components/rai_tabular_insight_constructor/versions/0.21.0
limits:
timeout: 3600
inputs:
Expand All @@ -54,7 +54,7 @@ jobs:

explain_01:
type: command
component: azureml://registries/azureml/components/rai_tabular_explanation/versions/0.18.0
component: azureml://registries/azureml/components/rai_tabular_explanation/versions/0.21.0
limits:
timeout: 7200
inputs:
Expand All @@ -63,7 +63,7 @@ jobs:

causal_01:
type: command
component: azureml://registries/azureml/components/rai_tabular_causal/versions/0.18.0
component: azureml://registries/azureml/components/rai_tabular_causal/versions/0.21.0
limits:
timeout: 7200
inputs:
Expand All @@ -75,7 +75,7 @@ jobs:

counterfactual_01:
type: command
component: azureml://registries/azureml/components/rai_tabular_counterfactual/versions/0.18.0
component: azureml://registries/azureml/components/rai_tabular_counterfactual/versions/0.21.0
limits:
timeout: 7200
inputs:
Expand All @@ -88,14 +88,14 @@ jobs:
limits:
timeout: 7200
type: command
component: azureml://registries/azureml/components/rai_tabular_erroranalysis/versions/0.18.0
component: azureml://registries/azureml/components/rai_tabular_erroranalysis/versions/0.21.0
inputs:
rai_insights_dashboard: ${{parent.jobs.create_rai_job.outputs.rai_insights_dashboard}}
max_depth: 3

gather_01:
type: command
component: azureml://registries/azureml/components/rai_tabular_insight_gather/versions/0.18.0
component: azureml://registries/azureml/components/rai_tabular_insight_gather/versions/0.21.0
limits:
timeout: 7200
inputs:
Expand All @@ -107,7 +107,7 @@ jobs:

scorecard_01:
type: command
component: azureml://registries/azureml/components/rai_tabular_score_card/versions/0.18.0
component: azureml://registries/azureml/components/rai_tabular_score_card/versions/0.21.0
inputs:
dashboard: ${{parent.jobs.gather_01.outputs.dashboard}}
pdf_generation_config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import argparse
import json
import os
import tempfile

from sklearn.ensemble import RandomForestClassifier
from sklearn.compose import ColumnTransformer
Expand All @@ -18,8 +19,6 @@

import time

from azureml.core.run import Run


def parse_args():
# setup arg parser
Expand Down Expand Up @@ -69,11 +68,8 @@ def get_classification_model_pipeline(continuous_features, categorical_features)


def main(args):
current_experiment = Run.get_context().experiment
tracking_uri = current_experiment.workspace.get_mlflow_tracking_uri()
tracking_uri = mlflow.get_tracking_uri()
print("tracking_uri: {0}".format(tracking_uri))
mlflow.set_tracking_uri(tracking_uri)
mlflow.set_experiment(current_experiment.name)

# Read in data
print("Reading data")
Expand All @@ -93,18 +89,39 @@ def main(args):
model = pipeline.fit(X_train, y_train)

# Saving model with mlflow
print("Saving model with MLFlow to temporary directory")
print("Saving model with MLFlow to model_output directory")
mlflow.sklearn.save_model(sk_model=model, path=args.model_output)

suffix = int(time.time())
registered_name = "{0}_{1}".format(args.model_name, suffix)
print(f"Registering model as {registered_name}")

mlflow.sklearn.log_model(
sk_model=model,
registered_model_name=registered_name,
artifact_path=registered_name,
)
# Use save_model and create_model_version with file:// URI to let Azure ML handle the upload
with tempfile.TemporaryDirectory() as temp_dir:
model_dir = os.path.join(temp_dir, registered_name)
mlflow.sklearn.save_model(model, model_dir)

# Use the older model registry API directly to avoid logged-models search
from mlflow.tracking import MlflowClient

client = MlflowClient()

try:
# Try to create the registered model (will fail if it already exists)
client.create_registered_model(registered_name)
print(f"Created new registered model: {registered_name}")
except Exception as e:
print(f"Registered model {registered_name} already exists: {e}")

# Create a new version of the model using file:// URI
# Azure ML will handle the upload and generate the proper azureml:// URI
file_uri = f"file://{model_dir}"
print("Registering model with file_uri: {0}".format(file_uri))

model_version = client.create_model_version(
name=registered_name, source=file_uri
)
print(f"Created model version {model_version.version} for {registered_name}")

model_info = {"id": "{0}:1".format(registered_name)}
output_path = os.path.join(args.model_output_json, "model_info.json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ outputs:
type: path

code: ./train.py
environment: azureml://registries/azureml/environments/responsibleai-tabular/versions/14
environment: azureml://registries/azureml/environments/responsibleai-tabular/versions/26
command: >-
python train.py
--training_data ${{inputs.training_data}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

create_rai_job:
type: command
component: azureml://registries/azureml/components/rai_tabular_insight_constructor/versions/0.18.0
component: azureml://registries/azureml/components/rai_tabular_insight_constructor/versions/0.21.0
limits:
timeout: 3600
inputs:
Expand All @@ -47,7 +47,7 @@ jobs:

explain_01:
type: command
component: azureml://registries/azureml/components/rai_tabular_explanation/versions/0.18.0
component: azureml://registries/azureml/components/rai_tabular_explanation/versions/0.21.0
limits:
timeout: 7200
inputs:
Expand All @@ -56,7 +56,7 @@ jobs:

causal_01:
type: command
component: azureml://registries/azureml/components/rai_tabular_causal/versions/0.18.0
component: azureml://registries/azureml/components/rai_tabular_causal/versions/0.21.0
limits:
timeout: 7200
inputs:
Expand All @@ -68,7 +68,7 @@ jobs:

counterfactual_01:
type: command
component: azureml://registries/azureml/components/rai_tabular_counterfactual/versions/0.18.0
component: azureml://registries/azureml/components/rai_tabular_counterfactual/versions/0.21.0
limits:
timeout: 7200
inputs:
Expand All @@ -81,15 +81,15 @@ jobs:
limits:
timeout: 7200
type: command
component: azureml://registries/azureml/components/rai_tabular_erroranalysis/versions/0.18.0
component: azureml://registries/azureml/components/rai_tabular_erroranalysis/versions/0.21.0
inputs:
rai_insights_dashboard: ${{parent.jobs.create_rai_job.outputs.rai_insights_dashboard}}
max_depth: 3
filter_features: '["style", "Employer"]'

gather_01:
type: command
component: azureml://registries/azureml/components/rai_tabular_insight_gather/versions/0.18.0
component: azureml://registries/azureml/components/rai_tabular_insight_gather/versions/0.21.0
limits:
timeout: 7200
inputs:
Expand All @@ -101,7 +101,7 @@ jobs:

scorecard_01:
type: command
component: azureml://registries/azureml/components/rai_tabular_score_card/versions/0.18.0
component: azureml://registries/azureml/components/rai_tabular_score_card/versions/0.21.0
inputs:
dashboard: ${{parent.jobs.gather_01.outputs.dashboard}}
pdf_generation_config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import argparse
import json
import os
import tempfile

from sklearn.ensemble import RandomForestRegressor
from sklearn.compose import ColumnTransformer
Expand All @@ -18,8 +19,6 @@

import time

from azureml.core.run import Run


def parse_args():
# setup arg parser
Expand Down Expand Up @@ -69,11 +68,8 @@ def get_regression_model_pipeline(continuous_features, categorical_features):


def main(args):
current_experiment = Run.get_context().experiment
tracking_uri = current_experiment.workspace.get_mlflow_tracking_uri()
tracking_uri = mlflow.get_tracking_uri()
print("tracking_uri: {0}".format(tracking_uri))
mlflow.set_tracking_uri(tracking_uri)
mlflow.set_experiment(current_experiment.name)

# Read in data
print("Reading data")
Expand All @@ -93,18 +89,39 @@ def main(args):
model = pipeline.fit(X_train, y_train)

# Saving model with mlflow
print("Saving model with MLFlow to temporary directory")
print("Saving model with MLFlow to model_output directory")
mlflow.sklearn.save_model(sk_model=model, path=args.model_output)

suffix = int(time.time())
registered_name = "{0}_{1}".format(args.model_name, suffix)
print(f"Registering model as {registered_name}")

mlflow.sklearn.log_model(
sk_model=model,
registered_model_name=registered_name,
artifact_path=registered_name,
)
# Use save_model and create_model_version with file:// URI to let Azure ML handle the upload
with tempfile.TemporaryDirectory() as temp_dir:
model_dir = os.path.join(temp_dir, registered_name)
mlflow.sklearn.save_model(model, model_dir)

# Use the older model registry API directly to avoid logged-models search
from mlflow.tracking import MlflowClient

client = MlflowClient()

try:
# Try to create the registered model (will fail if it already exists)
client.create_registered_model(registered_name)
print(f"Created new registered model: {registered_name}")
except Exception as e:
print(f"Registered model {registered_name} already exists: {e}")

# Create a new version of the model using file:// URI
# Azure ML will handle the upload and generate the proper azureml:// URI
file_uri = f"file://{model_dir}"
print("Registering model with file_uri: {0}".format(file_uri))

model_version = client.create_model_version(
name=registered_name, source=file_uri
)
print(f"Created model version {model_version.version} for {registered_name}")

model_info = {"id": "{0}:1".format(registered_name)}
output_path = os.path.join(args.model_output_json, "model_info.json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ outputs:
type: path

code: ./train.py
environment: azureml://registries/azureml/environments/responsibleai-tabular/versions/14
environment: azureml://registries/azureml/environments/responsibleai-tabular/versions/26
command: >-
python train.py
--training_data ${{inputs.training_data}}
Expand Down
Loading