gpu_devices.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from typing import ClassVar, List, Optional
  2. from pydantic import BaseModel
  3. from sqlmodel import SQLModel
  4. from gpustack.mixins import BaseModelMixin
  5. from gpustack.schemas.common import ListParams, PaginatedList
  6. from gpustack.schemas.workers import GPUDeviceStatus
  7. # GPUDevice is a view created from the `workers` table.
  8. class GPUDeviceBase(GPUDeviceStatus, BaseModel):
  9. id: str
  10. worker_id: int
  11. worker_name: str
  12. worker_ip: str
  13. worker_ifname: str
  14. cluster_id: int
  15. # NULL = belongs to a worker on a global cluster.
  16. owner_principal_id: Optional[int] = None
  17. class GPUDevice(GPUDeviceBase, SQLModel, BaseModelMixin, table=True):
  18. __tablename__ = "gpu_devices_view"
  19. __mapper_args__ = {'primary_key': ["id"]}
  20. class GPUDeviceListParams(ListParams):
  21. sortable_fields: ClassVar[List[str]] = [
  22. "name",
  23. "index",
  24. "cluster_id",
  25. "worker_name",
  26. "vendor",
  27. "temperature",
  28. "core.utilization_rate",
  29. "memory.utilization_rate",
  30. "created_at",
  31. "updated_at",
  32. ]
  33. class GPUDevicePublic(GPUDeviceBase):
  34. pass
  35. GPUDevicesPublic = PaginatedList[GPUDevicePublic]