Skip to content

Complete serde unit tests#2762

Merged
iamtrask merged 34 commits intoOpenMined:masterfrom
vvmnnnkv:refactor-serde
Dec 8, 2019
Merged

Complete serde unit tests#2762
iamtrask merged 34 commits intoOpenMined:masterfrom
vvmnnnkv:refactor-serde

Conversation

@vvmnnnkv
Copy link
Member

This is for issue #2654
PR tries to fully cover serde with unit tests. As a byproduct it also kind of documents how serde simplifies values (by providing reference simplification samples) and reveals some inconsistencies in how simplification is done.

New test/test_serde_full.py contains 3 generic tests:

  1. test_serde_coverage: check that all serde types (loaded in serde.py) are included in tests
  2. test_serde_roundtrip: roundtrip a value through serde and compare it to itself after that
  3. test_serde_simplify: simplify a value and compare it to reference value

samples dict that contains samples for each serde type is supplied to these tests.

Additionally, there're few fixes here to make tests pass:

  • Exceptions simplify/detail
  • Autograd tensor init (to properly use values sent by detail fn)

I had to exclude this file from black formatting because it squashes reference simplification examples and makes them less clear.

@vvmnnnkv vvmnnnkv mentioned this pull request Nov 30, 2019
@cereallarceny
Copy link
Member

Wow. I'm so proud of you @vvmnnnkv. This is one hell of a PR, nicely done. Let's get this reviewed and merged!

@iamtrask
Copy link
Member

iamtrask commented Dec 2, 2019

Indeed! Quite an epic PR! Well done sir!

Looks like there are two Travis errors for now. One is a failing unit test for "serde coverage" and another is a failing style test because some part of our unit tests aren't getting run (likely because it . fails before it finishes)

Copy link
Member

@iamtrask iamtrask left a comment

Choose a reason for hiding this comment

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

fix travis errors :)

Copy link
Contributor

@karlhigley karlhigley left a comment

Choose a reason for hiding this comment

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

These look great! Looking forward to using these as a reference to update the AndroidWorker.



########################################################################
# Functions that return list of serde samples in the following format:
Copy link
Contributor

Choose a reason for hiding this comment

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

Since these tests also function as documentation for consumers (like the JS and Android workers), they would be a little easier to read if the samples were dictionaries. Readers wouldn't have to keep the format in mind from this comment at the top. Might also be helpful in the case where a change breaks one or two tests and someone navigates directly to them without reading the whole file.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree on this point, but more because of test_serde_simplify which is not 100% clear because it uses indices of the tuple.
By the way, I see that when you define a compare function, you always do for 1 (custom_detailed_values_comparison_function ?) and the other one (custom_simplified_values_comparison_function ?) is always None, is this last one needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

@karlhigley Please take a look now?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, that helps! Turns out I was misreading the examples the first time. 😅

Copy link
Contributor

@LaRiffle LaRiffle left a comment

Choose a reason for hiding this comment

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

That's amazing.
And so clean :O


def test_serde_coverage():
"""Checks all types in serde are tested"""
for cls, _ in serde.simplifiers.items():
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@vvmnnnkv
Copy link
Member Author

vvmnnnkv commented Dec 4, 2019

Fixed old problems, but now need to add new PrivateTensor and PromiseTensor to pass tests 😅

@cereallarceny
Copy link
Member

Looks good to me. Let's get this merged @LaRiffle @iamtrask @karlhigley

Copy link
Member

@cereallarceny cereallarceny left a comment

Choose a reason for hiding this comment

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

PR of the year ♥️♥️♥️

@iamtrask
Copy link
Member

iamtrask commented Dec 7, 2019

Looks like there are lines in test_serde_full.py which aren't getting run - this is causing Travis to fail.

@vvmnnnkv
Copy link
Member Author

vvmnnnkv commented Dec 8, 2019

These were lines of code converted to torchscript (e.g. via @torch.jit.script or torch.jit.ScriptModule). They are not executed, so just skipped them from report with pragma: no cover (I've noticed similar thing is done in test/test_serde.py)

@vvmnnnkv vvmnnnkv requested a review from iamtrask December 8, 2019 15:24
@iamtrask iamtrask merged commit 7096f13 into OpenMined:master Dec 8, 2019
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.

5 participants