Skip to content

Make grad_fn serializable#2871

Merged
LaRiffle merged 23 commits intoOpenMined:masterfrom
sukhadj:master
Jan 12, 2020
Merged

Make grad_fn serializable#2871
LaRiffle merged 23 commits intoOpenMined:masterfrom
sukhadj:master

Conversation

@sukhadj
Copy link
Member

@sukhadj sukhadj commented Dec 30, 2019

Solves #2797
This PR makes grad_fn serializable.

@karlhigley
Copy link
Contributor

For testing, you can add examples in the serde test helpers and add GradFunc to the list of classes tested for round-trip serialization here.

@karlhigley
Copy link
Contributor

@sukhadj This has a few small conflicts with master. Could you resolve them so we can get the CI tests running?

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.

Excellent starting point!

setuptools>=41.0.0
sphinx-markdown-builder>=0.4.1
Sphinx>=2.1.1 No newline at end of file
Sphinx>=2.1.1
Copy link
Contributor

Choose a reason for hiding this comment

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

smae

- Change Autograd.__init__() to assign grad_fn
- Make simplify and detail of GradFunc lighter
@karlhigley
Copy link
Contributor

Most of the CI test failures are due to a version mismatch between syft-proto and PySyft which will be resolved when #2876 is merged. This PR still needs serialization tests for GradFunc though.

@sukhadj
Copy link
Member Author

sukhadj commented Jan 2, 2020

@karlhigley I will add tests for GradFunc soon 😃

@sukhadj
Copy link
Member Author

sukhadj commented Jan 2, 2020

@karlhigley @LaRiffle Should we add tests for each gradient function?
Or will the test for one class (any or specific) suffice?

@karlhigley
Copy link
Contributor

@sukhadj I don’t mean to hassle you about tests, I’m just excited about this one! 😅

I’d pick a gradient function that exercises as much of the code as possible and use that as your test example.

@sukhadj
Copy link
Member Author

sukhadj commented Jan 2, 2020

@karlhigley I believe we currently have some problems mul and pow. So will go ahead with simple AddBackward for now 😄

@sukhadj
Copy link
Member Author

sukhadj commented Jan 4, 2020

Hey @karlhigley @LaRiffle , the tests are failing due to inconsistent serialization (and one because of syntax error 😅 ).
I have opened the issue #2882. Any thoughts? 😃

- Update additive sharining simplify to have consistent garbage_collect_data
- Fix serde test for GradFunc
- Remove attributes check temporarily
@sukhadj
Copy link
Member Author

sukhadj commented Jan 4, 2020

There seems to be one more problem here.
The comparison of _attributes is not working. Will be working on that 💯

@sukhadj sukhadj changed the title (WIP) Make grad_fn serializable Make grad_fn serializable Jan 8, 2020
@karlhigley
Copy link
Contributor

It's interesting that the round-trip serialization test passes, but the simplification test fails. Makes me wonder if the simplification test assertion has the correct expected value. 🤔

@sukhadj
Copy link
Member Author

sukhadj commented Jan 9, 2020

It's interesting that the round-trip serialization test passes, but the simplification test fails. Makes me wonder if the simplification test assertion has the correct expected value. thinking

Hey, so currently comparison function we employ just compares if class name matches but not the attributes. I'm working on comparison of _attributes. Not sure if we should just check equality of list 😃

@sukhadj
Copy link
Member Author

sukhadj commented Jan 11, 2020

Hey @LaRiffle @karlhigley need review on this

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.

Looks good on the whole once the test coverage issue gets resolved.

try:
# either its a tensor
assert detailed_attr.get().equal(t)
except AttributeError:
Copy link
Contributor

Choose a reason for hiding this comment

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

This except clause is a good idea but doesn't get exercised by the test suite, which causes a CI test failure due to insufficient coverage. Since it isn't used yet, probably okay to remove/comment it and leave a note that compare only works for tensors.

for _, share in shares.items():
share.garbage_collect_data = value

def get_garbage_collect_data(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a good addition, but doesn't look like it actually gets called anywhere yet. Did I miss it?

Copy link
Member Author

@sukhadj sukhadj Jan 11, 2020

Choose a reason for hiding this comment

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

It was used in how previously garbage_collect_data was handled.

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.

Great job! :)


cls = getattr(gradients, cls)

return cls(*grad_fn_attrs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Tiny

if cls == "GradFunc":
     cls =  GradFunc
else:
     cls = getattr(gradients, cls)

return cls(*grad_fn_attrs)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done


self.grad_fn = None
if "grad_fn" in kwargs.keys():
self.grad_fn = kwargs["grad_fn"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can do
self.grad_fn = kwargs.get("grad_fn")

Copy link
Member Author

Choose a reason for hiding this comment

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

Yess 😄

@LaRiffle LaRiffle merged commit c1c5aee into OpenMined:master Jan 12, 2020
@karlhigley
Copy link
Contributor

🎉

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.

3 participants