Skip to content

Add optional device_requests to DockerCommandLineCodeExecutor #6302

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

Closed
ekzhu opened this issue Apr 15, 2025 · 0 comments · Fixed by #6339
Closed

Add optional device_requests to DockerCommandLineCodeExecutor #6302

ekzhu opened this issue Apr 15, 2025 · 0 comments · Fixed by #6339
Labels
code-execution execute generated code help wanted Extra attention is needed proj-extensions
Milestone

Comments

@ekzhu
Copy link
Collaborator

ekzhu commented Apr 15, 2025

Discussed in #6237

Originally posted by millerh1 April 7, 2025
It seems like DockerCommandLineCodeExecutor doesn't use GPUs even when they are available. I think you would need to update _docker_code_executor.py to something like this:

# Create a device request asking for all GPUs (equivalent to --gpus all)
gpu_request = [DeviceRequest(count=-1, capabilities=[['gpu']])]

self._container = await asyncio.to_thread(
    client.containers.create,
    self._image,
    name=self.container_name,
    entrypoint=shell_command,
    command=command,
    tty=True,
    detach=True,
    auto_remove=self._auto_remove,
    volumes={str(self._bind_dir.resolve()): {"bind": "/workspace", "mode": "rw"}, **self._extra_volumes},
    working_dir="/workspace",
    extra_hosts=self._extra_hosts,
    # Pass the GPU request to the container creation call
    device_requests=gpu_request,
)
await asyncio.to_thread(self._container.start)

I tried this locally and it worked nicely. Is this of interest?

@ekzhu ekzhu added code-execution execute generated code help wanted Extra attention is needed proj-extensions labels Apr 15, 2025
@ekzhu ekzhu added this to the 0.4.x-python milestone Apr 15, 2025
@ekzhu ekzhu closed this as completed in 0015315 Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-execution execute generated code help wanted Extra attention is needed proj-extensions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant