-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup ProxyActor Config [1/N] (#132)
This PR provides cross_silo_send_resource_label and cross_silo_recv_resource_label config in fed.init and convert them to the "resources" field of ActorClass.options. Signed-off-by: paer <chenqixiang.cqx@antgroup.com> --------- Signed-off-by: paer <chenqixiang.cqx@antgroup.com> Co-authored-by: paer <chenqixiang.cqx@antgroup.com>
- Loading branch information
Showing
4 changed files
with
167 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Copyright 2023 The RayFed Team | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
import multiprocessing | ||
|
||
import pytest | ||
import fed | ||
import fed._private.compatible_utils as compatible_utils | ||
import ray | ||
|
||
|
||
def test_setup_proxy_success(): | ||
def run(party): | ||
compatible_utils.init_ray(address='local', resources={"127.0.0.1": 2}) | ||
cluster = { | ||
'alice': {'address': '127.0.0.1:11010'}, | ||
'bob': {'address': '127.0.0.1:11011'}, | ||
} | ||
send_proxy_resources = { | ||
"127.0.0.1": 1 | ||
} | ||
recv_proxy_resources = { | ||
"127.0.0.1": 1 | ||
} | ||
fed.init( | ||
cluster=cluster, | ||
party=party, | ||
cross_silo_send_resource_label=send_proxy_resources, | ||
cross_silo_recv_resource_label=recv_proxy_resources, | ||
) | ||
|
||
assert ray.get_actor("SendProxyActor") is not None | ||
assert ray.get_actor(f"RecverProxyActor-{party}") is not None | ||
|
||
fed.shutdown() | ||
ray.shutdown() | ||
|
||
p_alice = multiprocessing.Process(target=run, args=('alice',)) | ||
p_bob = multiprocessing.Process(target=run, args=('bob',)) | ||
p_alice.start() | ||
p_bob.start() | ||
p_alice.join() | ||
p_bob.join() | ||
assert p_alice.exitcode == 0 and p_bob.exitcode == 0 | ||
|
||
|
||
def test_setup_proxy_failed(): | ||
def run(party): | ||
compatible_utils.init_ray(address='local', resources={"127.0.0.1": 1}) | ||
cluster = { | ||
'alice': {'address': '127.0.0.1:11010'}, | ||
'bob': {'address': '127.0.0.1:11011'}, | ||
} | ||
send_proxy_resources = { | ||
"127.0.0.2": 1 # Insufficient resource | ||
} | ||
recv_proxy_resources = { | ||
"127.0.0.2": 1 # Insufficient resource | ||
} | ||
with pytest.raises(ray.exceptions.GetTimeoutError): | ||
fed.init( | ||
cluster=cluster, | ||
party=party, | ||
cross_silo_send_resource_label=send_proxy_resources, | ||
cross_silo_recv_resource_label=recv_proxy_resources, | ||
cross_silo_timeout_in_seconds=10, # Quick fail in test | ||
) | ||
|
||
fed.shutdown() | ||
ray.shutdown() | ||
|
||
p_alice = multiprocessing.Process(target=run, args=('alice',)) | ||
p_bob = multiprocessing.Process(target=run, args=('bob',)) | ||
p_alice.start() | ||
p_bob.start() | ||
p_alice.join() | ||
p_bob.join() | ||
assert p_alice.exitcode == 0 and p_bob.exitcode == 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
import sys | ||
|
||
sys.exit(pytest.main(["-sv", __file__])) |