Skip to content
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

Add Crypten changes to master #3377

Merged
merged 4 commits into from
Apr 24, 2020
Merged

Conversation

gmuraru
Copy link
Member

@gmuraru gmuraru commented Apr 20, 2020

Description

Update master with the core changes made on the crypten branch

Type of change

Please mark options that are relevant.

  • Added/Modified tutorials
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

@gmuraru gmuraru requested a review from a team as a code owner April 20, 2020 12:39
@karlhigley
Copy link
Contributor

What bug(s) does this fix?

@@ -60,6 +60,11 @@ def trace_wrapper(*args, **kwargs):
recording sub actions
"""

if not hasattr(syft, "hook") or syft.hook == None:
# Make sure that in the "hooking process" we do not access the
# syft.hook because it is not initialized
Copy link
Contributor

Choose a reason for hiding this comment

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

When was this happening?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy pasted from the Crypten branch merge :3
The trace for the error was this:


    @pytest.fixture(scope="session", autouse=True)
    def hook():
>       hook = TorchHook(torch)

test/conftest.py:130: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
syft/frameworks/torch/hook/hook.py:145: in __init__
    self._hook_native_tensor(crypten.mpc.MPCTensor, TorchTensor)
syft/frameworks/torch/hook/hook.py:277: in _hook_native_tensor
    self._hook_native_methods(tensor_type)
syft/generic/frameworks/hook/hook.py:102: in _hook_native_methods
    native_method = getattr(tensor_type, attr)
../../../miniconda3/envs/pysyft/lib/python3.7/site-packages/crypten/cryptensor.py:39: in __getattribute__
    dummy = cls(None)
../../../miniconda3/envs/pysyft/lib/python3.7/site-packages/crypten/mpc/mpc.py:73: in __init__
    super().__init__(requires_grad=requires_grad)
../../../miniconda3/envs/pysyft/lib/python3.7/site-packages/crypten/cryptensor.py:132: in __init__
    self._reset_gradients()

What (I think is happening) -- when we hook we use the getattr -- but that method is changed in the CrypTensorMetaclass (metaclass for the MPCTensor). The problem is when we hook a method and that method is called in the getattr (in getattr we call an already hooked method and we do not have the syft.hook initialized -- syft.hook is initialized at the end of the TorchHook init method)

@@ -27,6 +27,19 @@ def __init__(self, owner=None, id=None, tags: set = None, description: str = Non
self.expected_shape = tuple(shape) if shape is not None else None
self.child = None

def __getattribute__(self, name):
Copy link
Contributor

Choose a reason for hiding this comment

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

Remind me what this was for? IIRC, it was proposed as a way to do tracing, but maybe it has other uses too. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

This one is for accessing methods that are necessary in the AbstractTensor class (the PlaceHolder is a child of that class).
In case we have PlaceHolder > CrypTensor, we might call methods from CrypTensor that are not necessary for PlaceHolder.
Another way to do this is to hook all methods from CrypTensor (this to be done in the crypten branch), but in that scenario, we might have methods that might not be generic -- like get_plain_text (this is implemented only in CrypTensor)

Copy link
Contributor

Choose a reason for hiding this comment

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

Medium-term plan for Placeholder is to make it a plain wrapper that no longer inherits from AbstractTensor and uses roughly this approach to forwarding method calls, so I'm not opposed in general. Just wondering why we need it in master if it's currently only used for Crypten, which couldn't be merged into master last I knew.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking it is a good idea to sync with master the changes that affect the plans, roles or core functionalities (such that the master will have those changes as fast as possible).

Those changes are some (possible) solutions to some problems we faced when merging some PRs.
I was thinking it might be a good idea to have those changes (that affect the syft core) into the master branch.

@codecov
Copy link

codecov bot commented Apr 20, 2020

Codecov Report

Merging #3377 into master will increase coverage by 0.05%.
The diff coverage is 63.63%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3377      +/-   ##
==========================================
+ Coverage   94.66%   94.72%   +0.05%     
==========================================
  Files         150      151       +1     
  Lines       15917    16337     +420     
==========================================
+ Hits        15068    15475     +407     
- Misses        849      862      +13     
Impacted Files Coverage Δ
syft/generic/frameworks/hook/trace.py 97.43% <50.00%> (-2.57%) ⬇️
syft/execution/placeholder.py 89.02% <57.14%> (-2.98%) ⬇️
...ft/frameworks/torch/tensors/interpreters/native.py 90.55% <100.00%> (-0.50%) ⬇️
syft/sandbox.py 92.45% <100.00%> (ø)
syft/serde/msgpack/serde.py 96.00% <0.00%> (-0.32%) ⬇️
...orks/torch/tensors/interpreters/additive_shared.py 93.21% <0.00%> (-0.13%) ⬇️
syft/codes.py 100.00% <0.00%> (ø)
test/execution/test_plan.py 100.00% <0.00%> (ø)
test/serde/serde_helpers.py 100.00% <0.00%> (ø)
... and 21 more

@@ -164,5 +164,5 @@ def distribute_dataset(data, workers):
print("Done!")


def hook(gbs):
def make_hook(gbs):
Copy link
Member Author

Choose a reason for hiding this comment

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

It is not necessarily a bug, but it might cause a name collision when import hook from syft (in case we do not have the hook initialized syft.hook will be a function)

@gmuraru gmuraru merged commit d6b77f7 into OpenMined:master Apr 24, 2020
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.

None yet

3 participants