From 763ea6c7bb30da231f85ad0c0783be398c64408f Mon Sep 17 00:00:00 2001 From: kevin Date: Fri, 27 Sep 2024 23:31:32 +0000 Subject: [PATCH] p Signed-off-by: kevin --- scripts/pipeline_generator/plugin.py | 72 ++++++++++--------- .../tests/pipeline_generator/test_plugin.py | 4 +- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/scripts/pipeline_generator/plugin.py b/scripts/pipeline_generator/plugin.py index db093bc..3a79e0e 100644 --- a/scripts/pipeline_generator/plugin.py +++ b/scripts/pipeline_generator/plugin.py @@ -6,6 +6,39 @@ DOCKER_PLUGIN_NAME = "docker#v5.2.0" KUBERNETES_PLUGIN_NAME = "kubernetes" +DEFAULT_DOCKER_ENVIRONMENT_VARIBLES = [ + f"HF_HOME={HF_HOME}", + "VLLM_USAGE_SOURCE=ci-test", + "HF_TOKEN", + "BUILDKITE_ANALYTICS_TOKEN" +] +DEFAULT_DOCKER_VOLUMES = [ + "/dev/shm:/dev/shm", + f"{HF_HOME}:{HF_HOME}" +] +DEFAULT_KUBERNETES_CONTAINER_VOLUME_MOUNTS = [ + {"name": "devshm", "mountPath": "/dev/shm"}, + {"name": "hf-cache", "mountPath": HF_HOME} +] +DEFAULT_KUBERNETES_CONTAINER_ENVIRONMENT_VARIABLES = [ + {"name": "HF_HOME", "value": HF_HOME}, + {"name": "VLLM_USAGE_SOURCE", "value": "ci-test"}, + { + "name": "HF_TOKEN", + "valueFrom": { + "secretKeyRef": { + "name": "hf-token-secret", + "key": "token" + } + } + }, +] +DEFAULT_KUBERNETES_POD_VOLUMES = [ + {"name": "devshm", "emptyDir": {"medium": "Memory"}}, + {"name": "hf-cache", "hostPath": {"path": HF_HOME, "type": "Directory"}} +] +DEFAULT_KUBERNETES_NODE_SELECTOR = {"nvidia.com/gpu.product": "NVIDIA-A100-SXM4-80GB"} + class DockerPluginConfig(BaseModel): """ @@ -19,16 +52,8 @@ class DockerPluginConfig(BaseModel): gpus: Optional[str] = "all" mount_buildkite_agent: Optional[bool] = Field(default=False, alias="mount-buildkite-agent") command: List[str] = Field(default_factory=list) - environment: List[str] = [ - f"HF_HOME={HF_HOME}", - "VLLM_USAGE_SOURCE=ci-test", - "HF_TOKEN", - "BUILDKITE_ANALYTICS_TOKEN" - ] - volumes: List[str] = [ - "/dev/shm:/dev/shm", - f"{HF_HOME}:{HF_HOME}" - ] + environment: List[str] = DEFAULT_DOCKER_ENVIRONMENT_VARIBLES + volumes: List[str] = DEFAULT_DOCKER_VOLUMES class KubernetesPodContainerConfig(BaseModel): @@ -40,25 +65,10 @@ class KubernetesPodContainerConfig(BaseModel): resources: Dict[str, Dict[str, int]] volume_mounts: List[Dict[str, str]] = Field( alias="volumeMounts", - default=[ - {"name": "devshm", "mountPath": "/dev/shm"}, - {"name": "hf-cache", "mountPath": HF_HOME} - ] + default=DEFAULT_KUBERNETES_CONTAINER_VOLUME_MOUNTS ) env: List[Dict[str, str]] = Field( - default=[ - {"name": "HF_HOME", "value": HF_HOME}, - {"name": "VLLM_USAGE_SOURCE", "value": "ci-test"}, - { - "name": "HF_TOKEN", - "valueFrom": { - "secretKeyRef": { - "name": "hf-token-secret", - "key": "token" - } - } - }, - ], + default=DEFAULT_KUBERNETES_CONTAINER_ENVIRONMENT_VARIABLES, ) @@ -69,14 +79,11 @@ class KubernetesPodSpec(BaseModel): containers: List[KubernetesPodContainerConfig] priority_class_name: str = Field(default="ci", alias="priorityClassName") node_selector: Dict[str, Any] = Field( - default={"nvidia.com/gpu.product": "NVIDIA-A100-SXM4-80GB"}, + default=DEFAULT_KUBERNETES_NODE_SELECTOR, alias="nodeSelector" ) volumes: List[Dict[str, Any]] = Field( - default=[ - {"name": "devshm", "emptyDir": {"medium": "Memory"}}, - {"name": "hf-cache", "hostPath": {"path": HF_HOME, "type": "Directory"}} - ] + default=DEFAULT_KUBERNETES_POD_VOLUMES ) @@ -88,6 +95,7 @@ class KubernetesPluginConfig(BaseModel): def get_kubernetes_plugin_config(container_image: str, test_bash_command: List[str], num_gpus: int) -> Dict: + test_bash_command[-1] = f'"{test_bash_command[-1]}"' pod_spec = KubernetesPodSpec( containers=[ KubernetesPodContainerConfig( diff --git a/scripts/tests/pipeline_generator/test_plugin.py b/scripts/tests/pipeline_generator/test_plugin.py index 7e85ac0..4ced8ab 100644 --- a/scripts/tests/pipeline_generator/test_plugin.py +++ b/scripts/tests/pipeline_generator/test_plugin.py @@ -11,7 +11,7 @@ def test_get_kubernetes_plugin_config(): docker_image_path = "test_image:latest" - test_bash_command = ["echo", "Hello, Kubernetes!"] + test_bash_command = ["bash", "-c", "echo A"] num_gpus = 1 expected_config = { @@ -20,7 +20,7 @@ def test_get_kubernetes_plugin_config(): "containers": [ { "image": docker_image_path, - "command": [" ".join(test_bash_command)], + "command": ['bash -c "echo A"'], "resources": {"limits": {"nvidia.com/gpu": num_gpus}}, "volumeMounts": [ {"name": "devshm", "mountPath": "/dev/shm"},