Skip to content
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

Add host_config_options to allow configuration of DockerTask for GPU resources #3234

Merged
merged 2 commits into from
Apr 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion luigi/contrib/docker_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,24 @@
def name(self):
return None

@property
def host_config_options(self):
'''
Override this to specify host_config options like gpu requests or shm
size e.g. `{"device_requests": [docker.types.DeviceRequest(count=1, capabilities=[["gpu"]])]}`

See https://docker-py.readthedocs.io/en/stable/api.html#docker.api.container.ContainerApiMixin.create_host_config
'''
return {}

Check warning on line 88 in luigi/contrib/docker_runner.py

View check run for this annotation

Codecov / codecov/patch

luigi/contrib/docker_runner.py#L88

Added line #L88 was not covered by tests

@property
def container_options(self):
'''
Override this to specify container options like user or ports e.g.
`{"user": f"{os.getuid()}:{os.getgid()}"}`

See https://docker-py.readthedocs.io/en/stable/api.html#docker.api.container.ContainerApiMixin.create_container
'''
return {}

@property
Expand Down Expand Up @@ -192,7 +208,8 @@
% (self._image, self.command, self._binds))

host_config = self._client.create_host_config(binds=self._binds,
network_mode=self.network_mode)
network_mode=self.network_mode,
**self.host_config_options)

container = self._client.create_container(self._image,
command=self.command,
Expand Down