runtime.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from typing import Optional, Union
  2. from gpustack_runtime.envs import (
  3. GPUSTACK_RUNTIME_DOCKER_PAUSE_IMAGE,
  4. GPUSTACK_RUNTIME_DOCKER_UNHEALTHY_RESTART_IMAGE,
  5. )
  6. from gpustack_runtime.deployer.docker import DockerWorkloadPlan
  7. from gpustack_runtime.deployer import WorkloadPlan, DockerDeployer, WorkloadStatus
  8. from gpustack.config.config import Config
  9. from gpustack.utils.config import apply_registry_override_to_image
  10. def transform_workload_plan(
  11. config: Config,
  12. workload: WorkloadPlan,
  13. fallback_registry: Optional[str] = None,
  14. ) -> Union[DockerWorkloadPlan, WorkloadPlan]:
  15. """
  16. If the deployer is docker, transform the generic WorkloadPlan to DockerWorkloadPlan,
  17. and fill the pause image and restart image with registry override.
  18. """
  19. if not DockerDeployer().is_supported():
  20. return workload
  21. pause_image = apply_registry_override_to_image(
  22. config, GPUSTACK_RUNTIME_DOCKER_PAUSE_IMAGE, fallback_registry
  23. )
  24. restart_image = apply_registry_override_to_image(
  25. config, GPUSTACK_RUNTIME_DOCKER_UNHEALTHY_RESTART_IMAGE, fallback_registry
  26. )
  27. docker_workload = DockerWorkloadPlan(
  28. pause_image=pause_image,
  29. unhealthy_restart_image=restart_image,
  30. **workload.__dict__,
  31. )
  32. return docker_workload
  33. def is_benchmark_workload(status: WorkloadStatus) -> bool:
  34. """
  35. Check if a workload is a benchmark workload.
  36. A workload is considered a benchmark workload if it has the 'type' label
  37. set to 'benchmark'.
  38. Args:
  39. status: The workload status to check.
  40. Returns:
  41. True if the workload is a benchmark workload, False otherwise.
  42. """
  43. if not status.labels:
  44. return False
  45. return status.labels.get("type") == "benchmark"