-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Deactivate plans in plans #2791
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
LaRiffle
merged 5 commits into
OpenMined:master
from
gmuraru:gm-deactivate-plans-in-plans
Dec 27, 2019
+204
−8
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2ccf339
Add possiblity to run plan in plans
gmuraru 534d33d
Typos fix
gmuraru ce97ac1
Add tests for new plan in plans
gmuraru 034121e
Merge branch 'master' into gm-deactivate-plans-in-plans
gmuraru c953647
Merge branch 'master' into gm-deactivate-plans-in-plans
LaRiffle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1046,3 +1046,158 @@ def plan_abs(data): | |
| pointers = plan_abs.get_pointers() | ||
|
|
||
| assert len(pointers) == 2 | ||
|
|
||
|
|
||
| def test_plan_nested_no_build_inner(workers): | ||
| alice = workers["alice"] | ||
| expected_res = th.tensor(200) | ||
|
|
||
| @sy.func2plan() | ||
| def plan_double(data): | ||
| return 2 * data | ||
|
|
||
| @sy.func2plan() | ||
| def plan_abs(data): | ||
| return plan_double(data).abs() | ||
|
|
||
| x = th.tensor(100) | ||
| plan_abs.build(x) | ||
|
|
||
| # Run plan locally | ||
| assert plan_abs(x) == expected_res | ||
|
|
||
| # Run plan remote | ||
| x_ptr = x.send(alice) | ||
| plan_abs_ptr = plan_abs.send(alice) | ||
| res = plan_abs_ptr(x_ptr) | ||
|
|
||
| assert res.get() == expected_res | ||
|
|
||
|
|
||
| def test_plan_nested_build_inner_plan_before(workers): | ||
| alice = workers["alice"] | ||
| expected_res = th.tensor(200) | ||
|
|
||
| @sy.func2plan(args_shape=[(1,)]) | ||
| def plan_double(data): | ||
| return -2 * data | ||
|
|
||
| @sy.func2plan() | ||
| def plan_abs(data): | ||
| return plan_double(data).abs() | ||
|
|
||
| x = th.tensor(100) | ||
| plan_abs.build(x) | ||
|
|
||
| # Run plan locally | ||
| assert plan_abs(x) == expected_res | ||
|
|
||
| x_ptr = x.send(alice) | ||
| plan_abs_ptr = plan_abs.send(alice) | ||
| res = plan_abs_ptr(x_ptr) | ||
|
|
||
| assert res.get() == expected_res | ||
|
|
||
|
|
||
| def test_plan_nested_build_inner_plan_after(workers): | ||
| alice = workers["alice"] | ||
| expected_res = th.tensor(200) | ||
|
|
||
| @sy.func2plan() | ||
| def plan_double(data): | ||
| return -2 * data | ||
|
|
||
| @sy.func2plan() | ||
| def plan_abs(data): | ||
| return plan_double(data).abs() | ||
|
|
||
| x = th.tensor(100) | ||
| plan_abs.build(x) | ||
| plan_double.build(x) | ||
|
|
||
| # Test locally | ||
| assert plan_abs(x) == expected_res | ||
|
|
||
| # Test remote | ||
| x_ptr = x.send(alice) | ||
| plan_double_ptr = plan_abs.send(alice) | ||
| res = plan_double_ptr(x_ptr) | ||
|
|
||
| assert res.get() == expected_res | ||
|
|
||
|
|
||
| def test_plan_nested_build_inner_plan_state(hook, workers): | ||
| alice = workers["alice"] | ||
| expected_res = th.tensor(199) | ||
|
|
||
| with hook.local_worker.registration_enabled(): | ||
|
|
||
| @sy.func2plan(args_shape=[(1,)], state=(th.tensor([1]),)) | ||
| def plan_double(data, state): | ||
| (bias,) = state.read() | ||
| return -2 * data + bias | ||
|
|
||
| @sy.func2plan() | ||
| def plan_abs(data): | ||
| return plan_double(data).abs() | ||
|
|
||
| x = th.tensor(100) | ||
| plan_abs.build(x) | ||
|
|
||
| # Test locally | ||
| assert plan_abs(x) == expected_res | ||
|
|
||
| # Test remote | ||
| x_ptr = x.send(alice) | ||
| plan_abs_ptr = plan_abs.send(alice) | ||
| plan_abs_ptr(x_ptr) | ||
|
|
||
| res = plan_abs_ptr(x_ptr) | ||
| assert res.get() == expected_res | ||
|
|
||
|
|
||
| def test_plan_nested_build_multiple_plans_state(hook, workers): | ||
| alice = workers["alice"] | ||
| expected_res = th.tensor(1043) | ||
|
|
||
| with hook.local_worker.registration_enabled(): | ||
|
|
||
| @sy.func2plan(args_shape=[(1,)], state=(th.tensor([3]),)) | ||
| def plan_3(data, state): | ||
| (bias,) = state.read() | ||
| return data + bias + 42 | ||
|
|
||
| @sy.func2plan(args_shape=[(1,)]) | ||
| def plan_2_2(data): | ||
| return data + 1331 | ||
|
|
||
| @sy.func2plan(args_shape=[(1,)], state=(th.tensor([2]),)) | ||
| def plan_2_1(data, state): | ||
| (bias,) = state.read() | ||
| return -2 * plan_3(data) + bias | ||
|
|
||
| @sy.func2plan() | ||
| def plan_1(data): | ||
| res = plan_2_1(data) | ||
| return plan_2_2(res) | ||
|
|
||
| # (-2 * (x + tensor(3) + 42) + tensor(2) + 1331) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can remove this - It was only a simple way that I thought of to show what each plan/function is doing |
||
| # ------------------- | ||
| # plan_3 | ||
| # -------------------------------------- | ||
| # plan_2_1 | ||
| # ----------------------------------------------- | ||
| # plan_2_2 | ||
|
|
||
| x = th.tensor(100) | ||
| plan_1.build(x) | ||
|
|
||
| # Test locally | ||
| assert plan_1(x) == expected_res | ||
|
|
||
| # Test remote | ||
| x_ptr = x.send(alice) | ||
| plan_1_ptr = plan_1.send(alice) | ||
|
|
||
| res = plan_1_ptr(x_ptr) | ||
| assert res.get() == expected_res | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think this was not needed