-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: WeichenXu <weichen.xu@databricks.com>
- Loading branch information
1 parent
1df0938
commit 67947d0
Showing
9 changed files
with
249 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2019 Uber Technologies, Inc. All Rights Reserved. | ||
# | ||
# 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 | ||
# | ||
# http://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 cloudpickle | ||
import sys | ||
from horovod.run.rendezvous.http_client import read_data_from_kvstore, put_data_into_kvstore | ||
|
||
if __name__ == '__main__': | ||
_, driver_addr, run_func_server_port_str = sys.argv | ||
run_func_server_port = int(run_func_server_port_str) | ||
pickled_func = read_data_from_kvstore(driver_addr, run_func_server_port, 'runfunc', 'func') | ||
func = cloudpickle.loads(pickled_func) | ||
ret_val = func() | ||
if ret_val: | ||
pickled_ret_val = cloudpickle.dumps(ret_val) | ||
put_data_into_kvstore(driver_addr, run_func_server_port, | ||
'runfunc', 'result', pickled_ret_val) |
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
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,48 @@ | ||
# Copyright 2019 Uber Technologies, Inc. All Rights Reserved. | ||
# | ||
# 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 | ||
# | ||
# http://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 sys | ||
import base64 | ||
if sys.version < '3': | ||
from urllib2 import urlopen | ||
from urllib2 import Request | ||
from urllib2 import HTTPError, URLError | ||
else: | ||
from urllib.request import urlopen | ||
from urllib.request import Request | ||
from urllib.error import HTTPError, URLError | ||
|
||
|
||
def read_data_from_kvstore(addr, port, scope, key): | ||
try: | ||
url = "http://{addr}:{port}/{scope}/{key}".format( | ||
addr=addr, port=str(port), scope=scope, key=key | ||
) | ||
req = Request(url) | ||
resp = urlopen(req) | ||
return base64.b64decode(resp.read()) | ||
except (HTTPError, URLError) as e: | ||
raise RuntimeError("Read data from KVStore server failed.", e) | ||
|
||
|
||
def put_data_into_kvstore(addr, port, scope, key, value): | ||
try: | ||
url = "http://{addr}:{port}/{scope}/{key}".format( | ||
addr=addr, port=str(port), scope=scope, key=key | ||
) | ||
req = Request(url, data=base64.b64encode(value)) | ||
req.get_method = lambda: "PUT" # for urllib2 compatibility | ||
urlopen(req) | ||
except (HTTPError, URLError) as e: | ||
raise RuntimeError("Put data input KVStore server failed.", e) |
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
Oops, something went wrong.