From 7871e37ec076b0de8d3a06dbda18ab4c063f5421 Mon Sep 17 00:00:00 2001 From: amlrelsa-ms Date: Wed, 28 Oct 2020 21:24:40 +0000 Subject: [PATCH] update samples from Release-72 as a part of SDK release --- README.md | 2 -- .../forecasting-beer-remote/infer.py | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 40269cc8..c85002c1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # Azure Machine Learning service example notebooks -> A community-driven repository of training and scoring examples can be found at https://github.com/Azure/azureml-examples - This repository contains example notebooks demonstrating the [Azure Machine Learning](https://azure.microsoft.com/en-us/services/machine-learning-service/) Python SDK which allows you to build, train, deploy and manage machine learning solutions using Azure. The AML SDK allows you the choice of using local or cloud compute resources, while managing and maintaining the complete data science workflow from the cloud. ![Azure ML Workflow](https://raw.githubusercontent.com/MicrosoftDocs/azure-docs/master/articles/machine-learning/media/concept-azure-machine-learning-architecture/workflow.png) diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-beer-remote/infer.py b/how-to-use-azureml/automated-machine-learning/forecasting-beer-remote/infer.py index 11141d72..246a8ada 100644 --- a/how-to-use-azureml/automated-machine-learning/forecasting-beer-remote/infer.py +++ b/how-to-use-azureml/automated-machine-learning/forecasting-beer-remote/infer.py @@ -10,6 +10,8 @@ from sklearn.metrics import mean_absolute_error, mean_squared_error from azureml.automl.runtime.shared.score import scoring, constants from azureml.core import Run +import torch + def align_outputs(y_predicted, X_trans, X_test, y_test, predicted_column_name='predicted', @@ -221,6 +223,10 @@ def MAPE(actual, pred): return np.mean(APE(actual_safe, pred_safe)) +def map_location_cuda(storage, loc): + return storage.cuda() + + parser = argparse.ArgumentParser() parser.add_argument( '--max_horizon', type=int, dest='max_horizon', @@ -274,8 +280,13 @@ X_lookback_df = lookback_dataset.drop_columns(columns=[target_column_name]) y_lookback_df = lookback_dataset.with_timestamp_columns( None).keep_columns(columns=[target_column_name]) -fitted_model = joblib.load(model_path) - +# Load the trained model with torch. +if torch.cuda.is_available(): + map_location = map_location_cuda +else: + map_location = 'cpu' +with open(model_path, 'rb') as fh: + fitted_model = torch.load(fh, map_location=map_location) if hasattr(fitted_model, 'get_lookback'): lookback = fitted_model.get_lookback()