Skip to content

🙌 OpenHands: AI-Driven Development

feat: Add GPU support (#6042)

மனோஜ்குமார் பழனிச்சாமி150463e629e1
diff --git a/openhands/core/config/sandbox_config.py b/openhands/core/config/sandbox_config.py
index 3c918444c4..a91c8b06a3 100644
--- a/openhands/core/config/sandbox_config.py
+++ b/openhands/core/config/sandbox_config.py
@@ -34,6 +34,7 @@ class SandboxConfig:
platform: The platform on which the image should be built. Default is None.
remote_runtime_resource_factor: Factor to scale the resource allocation for remote runtime.
Must be one of [1, 2, 4, 8]. Will only be used if the runtime is remote.
+ enable_gpu: Whether to enable GPU.
"""
remote_runtime_api_url: str = 'http://localhost:8000'
@@ -59,6 +60,7 @@ class SandboxConfig:
platform: str | None = None
close_delay: int = 15
remote_runtime_resource_factor: int = 1
+ enable_gpu: bool = False
def defaults_to_dict(self) -> dict:
"""Serialize fields to a dict for the frontend, including type hints, defaults, and whether it's optional."""
diff --git a/openhands/runtime/impl/docker/docker_runtime.py b/openhands/runtime/impl/docker/docker_runtime.py
index 62623d53a2..852e50f617 100644
--- a/openhands/runtime/impl/docker/docker_runtime.py
+++ b/openhands/runtime/impl/docker/docker_runtime.py
@@ -266,6 +266,14 @@ class DockerRuntime(ActionExecutionClient):
detach=True,
environment=environment,
volumes=volumes,
+ device_requests=(
+ [docker.types.DeviceRequest(
+ capabilities=[['gpu']],
+ count=-1
+ )]
+ if self.config.sandbox.enable_gpu
+ else None
+ ),
)
self.log('debug', f'Container started. Server url: {self.api_url}')
self.send_status_message('STATUS$CONTAINER_STARTED')