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
744 stars 118 forks source link

Fix #318 cannot pickle metrics #319

Closed huzecong closed 3 years ago

huzecong commented 3 years ago

This PR fixes #318: cannot pickle metrics in Python 3.6.

In Python 3.6 and below, pickling a Generic subclass that is specialized (e.g., Accuracy[float]) would cause an exception. To prevent troubles with Executor save & load, we use a dummy implementation of Generic through our home-brew GenericMeta. Basically, it is modified so that for any class Foo that inherits from Generic, Foo[T] just returns Foo.

Additional unit tests are also added to verify pickling behavior.

codecov[bot] commented 3 years ago

Codecov Report

Merging #319 into master will increase coverage by 0.00%. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #319   +/-   ##
=======================================
  Coverage   79.91%   79.92%           
=======================================
  Files         133      133           
  Lines       11135    11143    +8     
=======================================
+ Hits         8899     8906    +7     
- Misses       2236     2237    +1     
Impacted Files Coverage Δ
texar/torch/run/metric/base_metric.py 77.38% <100.00%> (+2.38%) :arrow_up:
texar/torch/data/data/data_iterators.py 81.88% <0.00%> (-0.37%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update fcd3aa0...7dc536f. Read the comment docs.