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
Generalize and improve hook_args.py implementation #2591
Conversation
Check out this pull request on ReviewNB: https://app.reviewnb.com/OpenMined/PySyft/pull/2591 You'll be able to see notebook diffs and discuss changes. Powered by ReviewNB. |
5f305a5
to
38c8340
Compare
38c8340
to
feb1bc8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's really a huge move towards a framework generic PySyft!
You made an ambitious change by making all imports absolute, as it allows to get rid of the circular import error, I believe it a great choice. However, it will make it harder for people to import objects in their notebook and so on, so I think we should be generous in syft/init.py to provide many shortcuts just like we can currently call sy.PointerTensor(...)
. This should include all tensors, workers, and objects a normal user is expected to play with (I believe many of them are already there).
examples/tutorials/Part 01 - The Basic Tools of Private Deep Learning.ipynb
Outdated
Show resolved
Hide resolved
examples/tutorials/advanced/Build your own tensor type (advanced).ipynb
Outdated
Show resolved
Hide resolved
|
||
# This import statement is strictly here to trigger registration of syft | ||
# tensor types inside hook_args.py. | ||
import syft.frameworks.torch.hook.hook_args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand why you did this, but I wonder if there is not a more pythonic way to trigger this registration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
open to ideas!
In fact, I don't think many things other than the hook and workers are used in the notebooks. It seems very few tensors actually need to be exposed -- PointerTensor/MultiPointerTensor seem to be abstracted away from the user, and similar for the various precision & crypto tensors. I'm inclined to remove things that are only exposed for internal development. The more we add to |
import style ready for discussion in #2599
Well, unfortunately there are a number of places that rely on tensor being exposed in the Opened a discussion issue around this in #2600 |
This is ready for another review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very few last questions
Note to reviewer: code review will be easiest here if taken commit-by-commit. Care was taken to make sure that the commit messages are comprehensive and descriptive.
The main purpose of this PR is to generalize hook_args to non-torch frameworks. This was actually a very small amount of work and can be seen in the first and third commits in this PR, however I noticed several problems across the code base that I'm also addressing here:
syft/
package (which should mainly consist of the user-facing API). If there happen to be any leftover exceptions to this, they are only in packages with very low connectivity with their submodules and other modules, and they were left untouched by accident.syft.frameworks.torch.hook_args
module had quite a few circular dependencies with modules that define their own tensor types. The main reason for this was that hook_args needs these tensor types in itstype_rule
,forward_func
, andbackward_func
registries, however hook_args was also being used in many of these tensor types' definitions. To fix this, registering tensor types should now happen in the same module as their definition using these new functions.