Skip to content

Commit

Permalink
Problem: As a user, if I want to specify that I want to create an ins…
Browse files Browse the repository at this point in the history
…tance with a gpu requirement, I cannot.

Solution: Add a `gpus` field on the host requirements to share the information of what GPU the user needs.
  • Loading branch information
nesitor committed Nov 27, 2024
1 parent bc90d8f commit b367efe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
23 changes: 23 additions & 0 deletions aleph_message/models/execution/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ class Config:
extra = Extra.forbid


class GpuProperties(HashableModel):
"""GPU properties."""

vendor: str = Field(
description="GPU vendor name"
)
device_name: str = Field(
description="GPU vendor card name"
)
device_class: Literal["0300", "0302"] = Field(
description="GPU device class. Look at https://admin.pci-ids.ucw.cz/read/PD/03"
)
device_id: str = Field(
description="GPU vendor & device ids"
)

class Config:
extra = Extra.forbid


class HypervisorType(str, Enum):
qemu = "qemu"
firecracker = "firecracker"
Expand Down Expand Up @@ -177,6 +197,9 @@ class HostRequirements(HashableModel):
node: Optional[NodeRequirements] = Field(
default=None, description="Required Compute Resource Node properties"
)
gpus: Optional[List[GpuProperties]] = Field(
default=None, description="GPUs needed to pass-through from the host"
)

class Config:
# Allow users to add custom requirements
Expand Down
12 changes: 11 additions & 1 deletion aleph_message/models/execution/instance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

from pydantic import Field
from typing import Self

from aleph_message.models import PaymentType
from pydantic import Field, validator, root_validator

from aleph_message.models.abstract import HashableModel

Expand Down Expand Up @@ -32,3 +35,10 @@ class InstanceContent(BaseExecutableContent):
rootfs: RootfsVolume = Field(
description="Root filesystem of the system, will be booted by the kernel"
)

@root_validator(pre=True)
def check_gpu_requirement(self) -> Self:
if self.requirements and self.requirements.gpus:
if self.payment and not self.payment.is_stream:
raise ValueError('Stream payment type is needed for GPU requirement')
return self

0 comments on commit b367efe

Please sign in to comment.