diff --git a/cli/responsible-ai/cli-responsibleaidashboard-housing-classification/cli-responsibleaidashboard-housing-classification.yml b/cli/responsible-ai/cli-responsibleaidashboard-housing-classification/cli-responsibleaidashboard-housing-classification.yml index 92459965c8..f405402503 100644 --- a/cli/responsible-ai/cli-responsibleaidashboard-housing-classification/cli-responsibleaidashboard-housing-classification.yml +++ b/cli/responsible-ai/cli-responsibleaidashboard-housing-classification/cli-responsibleaidashboard-housing-classification.yml @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/cli/responsible-ai/cli-responsibleaidashboard-housing-classification/train.py b/cli/responsible-ai/cli-responsibleaidashboard-housing-classification/train.py index 2830219e41..c2458c9ffa 100644 --- a/cli/responsible-ai/cli-responsibleaidashboard-housing-classification/train.py +++ b/cli/responsible-ai/cli-responsibleaidashboard-housing-classification/train.py @@ -4,6 +4,7 @@ import argparse import json import os +import tempfile from sklearn.ensemble import RandomForestClassifier from sklearn.compose import ColumnTransformer @@ -18,8 +19,6 @@ import time -from azureml.core.run import Run - def parse_args(): # setup arg parser @@ -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") @@ -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") diff --git a/cli/responsible-ai/cli-responsibleaidashboard-housing-classification/train_housing.yml b/cli/responsible-ai/cli-responsibleaidashboard-housing-classification/train_housing.yml index 3342bc6932..3ef2ae6b59 100644 --- a/cli/responsible-ai/cli-responsibleaidashboard-housing-classification/train_housing.yml +++ b/cli/responsible-ai/cli-responsibleaidashboard-housing-classification/train_housing.yml @@ -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}} diff --git a/cli/responsible-ai/cli-responsibleaidashboard-programmer-regression/cli-responsibleaidashboard-programmer-regression.yml b/cli/responsible-ai/cli-responsibleaidashboard-programmer-regression/cli-responsibleaidashboard-programmer-regression.yml index 56b700011a..5c661dcebc 100644 --- a/cli/responsible-ai/cli-responsibleaidashboard-programmer-regression/cli-responsibleaidashboard-programmer-regression.yml +++ b/cli/responsible-ai/cli-responsibleaidashboard-programmer-regression/cli-responsibleaidashboard-programmer-regression.yml @@ -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: @@ -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: @@ -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: @@ -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: @@ -81,7 +81,7 @@ 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 @@ -89,7 +89,7 @@ jobs: 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: @@ -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: diff --git a/cli/responsible-ai/cli-responsibleaidashboard-programmer-regression/train.py b/cli/responsible-ai/cli-responsibleaidashboard-programmer-regression/train.py index 6c0fffde35..865d824a07 100644 --- a/cli/responsible-ai/cli-responsibleaidashboard-programmer-regression/train.py +++ b/cli/responsible-ai/cli-responsibleaidashboard-programmer-regression/train.py @@ -4,6 +4,7 @@ import argparse import json import os +import tempfile from sklearn.ensemble import RandomForestRegressor from sklearn.compose import ColumnTransformer @@ -18,8 +19,6 @@ import time -from azureml.core.run import Run - def parse_args(): # setup arg parser @@ -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") @@ -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") diff --git a/cli/responsible-ai/cli-responsibleaidashboard-programmer-regression/train_programmers.yml b/cli/responsible-ai/cli-responsibleaidashboard-programmer-regression/train_programmers.yml index 3342bc6932..3ef2ae6b59 100644 --- a/cli/responsible-ai/cli-responsibleaidashboard-programmer-regression/train_programmers.yml +++ b/cli/responsible-ai/cli-responsibleaidashboard-programmer-regression/train_programmers.yml @@ -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}}