From 6a61f8331e35b0edd10362cf5820daea6effd991 Mon Sep 17 00:00:00 2001 From: hsukyle Date: Thu, 21 Jun 2018 22:09:34 -0700 Subject: [PATCH 1/3] small update to launch_shell mount_points was not being passed to Local.launch_command() --- doodad/launch_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doodad/launch_tools.py b/doodad/launch_tools.py index 292f630..9f5addb 100644 --- a/doodad/launch_tools.py +++ b/doodad/launch_tools.py @@ -13,7 +13,7 @@ def launch_shell( ): if mount_points is None: mount_points = [] - mode.launch_command(command, dry=dry) + mode.launch_command(command, dry=dry, mount_points=mount_points) def launch_python( From 2ff5e47a5db598adceaba2bd05a06caa6e866136 Mon Sep 17 00:00:00 2001 From: hsukyle Date: Thu, 28 Jun 2018 17:55:28 -0700 Subject: [PATCH 2/3] add ability to restrict gpu available to local docker image --- doodad/launch_tools.py | 3 ++- doodad/mode.py | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/doodad/launch_tools.py b/doodad/launch_tools.py index 9f5addb..048262f 100644 --- a/doodad/launch_tools.py +++ b/doodad/launch_tools.py @@ -10,10 +10,11 @@ def launch_shell( mode=LOCAL, dry=False, mount_points=None, + verbose=False ): if mount_points is None: mount_points = [] - mode.launch_command(command, dry=dry, mount_points=mount_points) + mode.launch_command(command, dry=dry, mount_points=mount_points, verbose=verbose) def launch_python( diff --git a/doodad/mode.py b/doodad/mode.py index 8e88aa4..c5324cd 100644 --- a/doodad/mode.py +++ b/doodad/mode.py @@ -67,11 +67,12 @@ def launch_command(self, cmd, mount_points=None, dry=False, verbose=False): class DockerMode(LaunchMode): - def __init__(self, image='ubuntu:16.04', gpu=False): + def __init__(self, image='ubuntu:16.04', gpu=False, gpu_id=-1): super(DockerMode, self).__init__() self.docker_image = image self.docker_name = uuid.uuid4() self.gpu = gpu + self.gpu_id = gpu_id # default of -1 results in all local gpus made available def get_docker_cmd(self, main_cmd, extra_args='', use_tty=True, verbose=True, pythonpath=None, pre_cmd=None, post_cmd=None, checkpoint=False, no_root=False): @@ -82,6 +83,8 @@ def get_docker_cmd(self, main_cmd, extra_args='', use_tty=True, verbose=True, py if verbose: if self.gpu: cmd_list.append('echo \"Running in docker (gpu)\"') + if self.gpu_id > -1: + cmd_list.append('echo \"Restricting to gpu_id=%d\"' % self.gpu_id) else: cmd_list.append('echo \"Running in docker\"') if pythonpath: @@ -107,12 +110,15 @@ def get_docker_cmd(self, main_cmd, extra_args='', use_tty=True, verbose=True, py use_tty = False extra_args += ' -d ' # detach is optional + docker_prefix = 'docker run' + if self.gpu: + docker_prefix = 'nvidia-' + docker_prefix + if self.gpu_id > -1: + docker_prefix = '%s -e NVIDIA_VISIBLE_DEVICES=%d' % (docker_prefix, self.gpu_id) if use_tty: - docker_prefix = 'docker run %s -ti %s /bin/bash -c ' % (extra_args, self.docker_image) + docker_prefix = '%s %s -ti %s /bin/bash -c ' % (docker_prefix, extra_args, self.docker_image) else: - docker_prefix = 'docker run %s %s /bin/bash -c ' % (extra_args, self.docker_image) - if self.gpu: - docker_prefix = 'nvidia-'+docker_prefix + docker_prefix = '%s %s %s /bin/bash -c ' % (docker_prefix, extra_args, self.docker_image) main_cmd = cmd_list.to_string() full_cmd = docker_prefix + ("\'%s\'" % main_cmd) return full_cmd @@ -123,7 +129,7 @@ def __init__(self, checkpoints=None, **kwargs): super(LocalDocker, self).__init__(**kwargs) self.checkpoints = checkpoints - def launch_command(self, cmd, mount_points=None, dry=False, verbose=False): + def launch_command(self, cmd, mount_points=None, dry=False, verbose=False, extra_args=''): mnt_args = '' py_path = [] for mount in mount_points: @@ -137,7 +143,7 @@ def launch_command(self, cmd, mount_points=None, dry=False, verbose=False): else: raise NotImplementedError(type(mount)) - full_cmd = self.get_docker_cmd(cmd, extra_args=mnt_args, pythonpath=py_path, + full_cmd = self.get_docker_cmd(cmd, extra_args=extra_args + mnt_args, pythonpath=py_path, checkpoint=self.checkpoints) if verbose: print(full_cmd) From 3ade980f5cf50238a8d9b800fe8da9ba275e7052 Mon Sep 17 00:00:00 2001 From: hsukyle Date: Wed, 1 Aug 2018 18:42:22 -0700 Subject: [PATCH 3/3] gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 7604ea9..4817bdc 100644 --- a/.gitignore +++ b/.gitignore @@ -101,3 +101,6 @@ ENV/ # mypy .mypy_cache/ + +# PyCharm +.idea/