asyml / texar-pytorch

Integrating the Best of TF into PyTorch, for Machine Learning, Natural Language Processing, and Text Generation. This is part of the CASL project: http://casl-project.ai/
https://asyml.io
Apache License 2.0
745 stars 117 forks source link

Cannot pickle types such as metrics #318

Closed hunterhector closed 4 years ago

hunterhector commented 4 years ago

Description

Users may encounter the following error when trying to pickle the objects with generic types, such as Texar metrics (https://github.com/asyml/texar-pytorch/blob/master/texar/torch/evals/metrics.py), as shown in the following stack trace:

image

This is a known bug in Python 3.6 when pickling the genric types https://github.com/python/typing/issues/511

Workaround

The easiest way to get around this is to upgrade to 3.7, which fixes this problem here https://github.com/python/cpython/pull/6216

Action needed.

However, we may consider providing workarounds in Texar. It is also suggested to add unit tests on serialization for affected classes including the metrics class.