-
Notifications
You must be signed in to change notification settings - Fork 710
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
Parameter Server: Run TF server by default #36
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
95ddfa8
implement default PS image
wbuchwalter 69ac7cc
Add default PS PodSpec
wbuchwalter c9f2d66
add tests
wbuchwalter de8f8f4
PS: Use ConfigMap instead of custom image
wbuchwalter 8082db3
move default PS clusterspec transform in Create
wbuchwalter 7fa80cb
implement reviewer comments
wbuchwalter 8b233ef
update docker image
wbuchwalter d5907df
make path to grpc server part of config
wbuchwalter 3f4f176
Merge branch 'master' of https://github.com/jlewi/mlkube.io into auto-ps
wbuchwalter c104f0e
fix and add unit tests
wbuchwalter 188e5cd
fix and add unit tests
wbuchwalter c6f047d
remove build_and_push.sh
wbuchwalter 7176834
fix build_and_push
wbuchwalter c8f00b5
Merge branch 'auto-ps' of github.com:wbuchwalter/mlkube.io into auto-ps
wbuchwalter 9f24996
Merge branch 'master' of https://github.com/jlewi/mlkube.io into auto-ps
wbuchwalter 9a62ee9
implement reviewer comments
wbuchwalter 2c32e0b
Do not push with GCB
wbuchwalter bb3fa53
Merge remote-tracking branch 'origin' into auto-ps
wbuchwalter 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,163 @@ | ||
#!/usr/bin/python | ||
# Copyright 2016 The TensorFlow Authors. 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. | ||
# ============================================================================== | ||
""" | ||
TODO: Once grpc_tensorflow_server.py is included in tensorflow | ||
docker image we should use it instead" | ||
|
||
Python-based TensorFlow GRPC server. | ||
|
||
Takes input arguments cluster_spec, job_name and task_id, and start a blocking | ||
TensorFlow GRPC server. | ||
|
||
Usage: | ||
grpc_tensorflow_server.py --cluster_spec=SPEC --job_name=NAME --task_id=ID | ||
|
||
Where: | ||
SPEC is <JOB>(,<JOB>)* | ||
JOB is <NAME>|<HOST:PORT>(;<HOST:PORT>)* | ||
NAME is a valid job name ([a-z][0-9a-z]*) | ||
HOST is a hostname or IP address | ||
PORT is a port number | ||
""" | ||
|
||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import argparse | ||
import sys | ||
|
||
from tensorflow.core.protobuf import config_pb2 | ||
from tensorflow.core.protobuf import tensorflow_server_pb2 | ||
from tensorflow.python.platform import app | ||
from tensorflow.python.training import server_lib | ||
|
||
|
||
def parse_cluster_spec(cluster_spec, cluster, verbose=False): | ||
"""Parse content of cluster_spec string and inject info into cluster protobuf. | ||
|
||
Args: | ||
cluster_spec: cluster specification string, e.g., | ||
"local|localhost:2222;localhost:2223" | ||
cluster: cluster protobuf. | ||
verbose: If verbose logging is requested. | ||
|
||
Raises: | ||
ValueError: if the cluster_spec string is invalid. | ||
""" | ||
|
||
job_strings = cluster_spec.split(",") | ||
|
||
if not cluster_spec: | ||
raise ValueError("Empty cluster_spec string") | ||
|
||
for job_string in job_strings: | ||
job_def = cluster.job.add() | ||
|
||
if job_string.count("|") != 1: | ||
raise ValueError("Not exactly one instance of '|' in cluster_spec") | ||
|
||
job_name = job_string.split("|")[0] | ||
|
||
if not job_name: | ||
raise ValueError("Empty job_name in cluster_spec") | ||
|
||
job_def.name = job_name | ||
|
||
if verbose: | ||
print("Added job named \"%s\"" % job_name) | ||
|
||
job_tasks = job_string.split("|")[1].split(";") | ||
for i in range(len(job_tasks)): | ||
if not job_tasks[i]: | ||
raise ValueError("Empty task string at position %d" % i) | ||
|
||
job_def.tasks[i] = job_tasks[i] | ||
|
||
if verbose: | ||
print(" Added task \"%s\" to job \"%s\"" % (job_tasks[i], job_name)) | ||
|
||
|
||
def main(unused_args): | ||
# Create Protobuf ServerDef | ||
server_def = tensorflow_server_pb2.ServerDef(protocol="grpc") | ||
|
||
# Cluster info | ||
parse_cluster_spec(FLAGS.cluster_spec, server_def.cluster, FLAGS.verbose) | ||
|
||
# Job name | ||
if not FLAGS.job_name: | ||
raise ValueError("Empty job_name") | ||
server_def.job_name = FLAGS.job_name | ||
|
||
# Task index | ||
if FLAGS.task_id < 0: | ||
raise ValueError("Invalid task_id: %d" % FLAGS.task_id) | ||
server_def.task_index = FLAGS.task_id | ||
|
||
config = config_pb2.ConfigProto(gpu_options=config_pb2.GPUOptions( | ||
per_process_gpu_memory_fraction=FLAGS.gpu_memory_fraction)) | ||
|
||
# Create GRPC Server instance | ||
server = server_lib.Server(server_def, config=config) | ||
|
||
# join() is blocking, unlike start() | ||
server.join() | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.register("type", "bool", lambda v: v.lower() == "true") | ||
parser.add_argument( | ||
"--cluster_spec", | ||
type=str, | ||
default="", | ||
help="""\ | ||
Cluster spec: SPEC. SPEC is <JOB>(,<JOB>)*," JOB is | ||
<NAME>|<HOST:PORT>(;<HOST:PORT>)*," NAME is a valid job name | ||
([a-z][0-9a-z]*)," HOST is a hostname or IP address," PORT is a | ||
port number." E.g., local|localhost:2222;localhost:2223, | ||
ps|ps0:2222;ps1:2222\ | ||
""" | ||
) | ||
parser.add_argument( | ||
"--job_name", | ||
type=str, | ||
default="", | ||
help="Job name: e.g., local" | ||
) | ||
parser.add_argument( | ||
"--task_id", | ||
type=int, | ||
default=0, | ||
help="Task index, e.g., 0" | ||
) | ||
parser.add_argument( | ||
"--gpu_memory_fraction", | ||
type=float, | ||
default=1.0, | ||
help="Fraction of GPU memory allocated",) | ||
parser.add_argument( | ||
"--verbose", | ||
type="bool", | ||
nargs="?", | ||
const=True, | ||
default=False, | ||
help="Verbose mode" | ||
) | ||
|
||
FLAGS, unparsed = parser.parse_known_args() | ||
app.run(main=main, argv=[sys.argv[0]] + unparsed) |
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
Oops, something went wrong.
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.
nit: I think there should be spaces after the plus signs. Maybe run gofmt?
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.
If I add this spaces back and run gofmt, it will remove them.
I am running go
1.9.1
, could you have a different go version with different gofmt rules?