Skip to content

Fix #318 cannot pickle metrics #319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 12, 2020
Merged

Conversation

huzecong
Copy link
Collaborator

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.

Pickling certain metrics while specifying input type as generic type
parameter would result in a failure in Python 3.6. Previous tests didn't
cover this case.
Worked around this limitation by using a dummy `Generic` in Python 3.6
and below.
@codecov
Copy link

codecov bot commented Sep 12, 2020

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%) ⬆️
texar/torch/data/data/data_iterators.py 81.88% <0.00%> (-0.37%) ⬇️

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.

Copy link
Member

@hunterhector hunterhector left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix, approved.

@hunterhector hunterhector merged commit a2f1186 into asyml:master Sep 12, 2020
@huzecong huzecong deleted the fix-metric-pickle branch September 12, 2020 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot pickle types such as metrics
2 participants