Azure / Azure/MachineLearningNotebooks

TCNForecaster's `output/model.pt` can't be deserialized

Open
#1,613 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
4.4k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

I set `enable_dnn=True` in the `AutoMLConfig`. The TCNForecaster that is therefore trained stores the model in `outputs/model.pt`.

I try to open the model with this code:

```python
with open(model_path, 'rb') as model_file:
model = torch.load(model_file, map_location='cpu')
```

This code is taken from `outputs/scoring_file_v_.py`. But running this locally or on an compute instance leads to the following error:

```shell
Traceback (most recent call last):
File "test_tcn.py", line 5, in
model = torch.load(model_file, map_location='cpu')
File "/Users/simons/anaconda3/envs/tcn_test/lib/python3.7/site-packages/torch/serialization.py", line 594, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "/Users/simons/anaconda3/envs/tcn_test/lib/python3.7/site-packages/torch/serialization.py", line 853, in _load
result = unpickler.load()
File "/Users/simons/anaconda3/envs/tcn_test/lib/python3.7/site-packages/azureml/contrib/automl/dnn/forecasting/wrapper/forecast_tcn_wrapper.py", line 376, in __setstate__
super(ForecastTCNWrapper, self).__setstate__(state)
File "/Users/simons/anaconda3/envs/tcn_test/lib/python3.7/site-packages/azureml/contrib/automl/dnn/forecasting/wrapper/forecast_wrapper.py", line 302, in __setstate__
self.forecaster.device = 'cuda' if torch.cuda.is_available() else 'cpu'
AttributeError: 'NoneType' object has no attribute 'device'
```

I used the exact same code 2 weeks ago and it worked. I guess that something was changed in the serialization of the model. If there is a new, could you please provide a code snippet which is used to deserialize the model.

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: be87853c-7d77-ec34-2bd2-a2f1e7104a3e
* Version Independent ID: 9c3f1114-c842-d0dd-ee02-7fae9974a545
* Content: [azureml.train.automl.AutoMLConfig class - Azure Machine Learning Python](https://docs.microsoft.com/en-us/python/api/azureml-train-automl-client/azureml.train.automl.automlconfig(class)?view=azure-ml-py)
* Content Source: [AzureML-Docset/stable/docs-ref-autogen/azureml-train-automl-client/azureml.train.automl.AutoMLConfig(class).yml](https://github.com/MicrosoftDocs/MachineLearning-Python-pr/blob/live/AzureML-Docset/stable/docs-ref-autogen/azureml-train-automl-client/azureml.train.automl.AutoMLConfig(class).yml)
* Service: **machine-learning**
* Sub-service: **core**
* GitHub Login: @DebFro
* Microsoft Alias: **debfro**

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.