Skip to content

Commit 740a0bb

Browse files
lukebaumanncopybara-github
authored andcommitted
Add Shared Pathways Service support to PathwaysJobSet.
PiperOrigin-RevId: 949604465
1 parent 8ecfff2 commit 740a0bb

2 files changed

Lines changed: 66 additions & 2 deletions

File tree

pathwaysutils/experimental/gke/jobset.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def __init__(
103103
elastic_slices: int = 0,
104104
labels: Mapping[str, str] | None = None,
105105
annotations: Mapping[str, str] | None = None,
106+
shared_pathways_service: bool = False,
106107
):
107108
"""Initializes the instance.
108109
@@ -124,6 +125,13 @@ def __init__(
124125
labels: Optional labels for the JobSet.
125126
annotations: Optional annotations for the JobSet.
126127
"""
128+
if shared_pathways_service and user_pod_template:
129+
raise ValueError(
130+
"Cannot enable shared_pathways_service when user_pod_template is"
131+
" provided."
132+
)
133+
self._shared_pathways_service = shared_pathways_service
134+
127135
self._name = name
128136
self._namespace = namespace
129137
self._jobset_api_version = jobset_api_version
@@ -161,6 +169,7 @@ def __init__(
161169
user_pod_template=user_pod_template,
162170
main_container_name=main_container_name,
163171
elastic_slices=elastic_slices,
172+
shared_pathways_service=shared_pathways_service,
164173
)
165174

166175
# Build worker template.
@@ -176,7 +185,7 @@ def __init__(
176185
)
177186

178187
self._success_policy = None
179-
if user_pod_template:
188+
if user_pod_template or shared_pathways_service:
180189
self._success_policy = {
181190
"operator": "All",
182191
"targetReplicatedJobs": [PATHWAYS_HEAD_JOB_NAME],
@@ -199,6 +208,7 @@ def _build_head_job_template(
199208
user_pod_template: Mapping[str, Any] | None,
200209
main_container_name: str,
201210
elastic_slices: int,
211+
shared_pathways_service: bool,
202212
) -> client.V1JobTemplateSpec:
203213
"""Builds the head job template for the JobSet.
204214
@@ -357,10 +367,13 @@ def _build_head_job_template(
357367
labels = user_pod_template.get("metadata", {}).get("labels", {})
358368
else:
359369
# Headless mode.
370+
containers = [rm_container]
371+
if not shared_pathways_service:
372+
containers.append(proxy_container)
360373
head_pod_spec = client.V1PodSpec(
361374
host_network=True,
362375
dns_policy="ClusterFirstWithHostNet",
363-
containers=[rm_container, proxy_container],
376+
containers=containers,
364377
)
365378
annotations = {}
366379
labels = {}

pathwaysutils/test/experimental/gke/jobset_test.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,57 @@ def test_failure_policy(self):
921921
config = pw_jobset.to_dict()
922922
self.assertEqual(config["spec"]["failurePolicy"]["maxRestarts"], 5)
923923

924+
def test_shared_pathways_service(self):
925+
pw_jobset = self._create_jobset(
926+
name="test-sps",
927+
shared_pathways_service=True,
928+
)
929+
930+
config = pw_jobset.to_dict()
931+
helper = JobSetManifestHelper(config)
932+
933+
self.assertEqual(
934+
config["spec"]["successPolicy"],
935+
{
936+
"operator": "All",
937+
"targetReplicatedJobs": ["pathways-head"],
938+
},
939+
)
940+
941+
self.assertTrue(config["spec"]["network"]["enableDNSHostnames"])
942+
self.assertTrue(config["spec"]["network"]["publishNotReadyAddresses"])
943+
944+
self.assertIn("pathways-head", helper.jobs)
945+
pod_spec = helper.pod_specs["pathways-head"]
924946

947+
# Head job should only have pathways-rm container, no pathways-proxy.
948+
self.assertIn("pathways-rm", helper.containers["pathways-head"])
949+
self.assertNotIn("pathways-proxy", helper.containers["pathways-head"])
950+
self.assertLen(pod_spec["containers"], 1)
951+
952+
def test_shared_pathways_service_with_user_template_fails(self):
953+
user_pod_template = {
954+
"spec": {
955+
"containers": [{
956+
"name": "jax-tpu",
957+
"image": "gcr.io/my-project/jax-tpu:latest",
958+
}]
959+
}
960+
}
961+
with self.assertRaisesRegex(
962+
ValueError,
963+
"Cannot enable shared_pathways_service when user_pod_template is"
964+
" provided.",
965+
):
966+
jobset.PathwaysJobSet(
967+
name="test-sps",
968+
namespace="default",
969+
pathways_dir="gs://bucket/scratch",
970+
tpu_type="v5e",
971+
topology="2x2",
972+
num_slices=2,
973+
shared_pathways_service=True,
974+
user_pod_template=user_pod_template,
975+
)
925976
if __name__ == "__main__":
926977
absltest.main()

0 commit comments

Comments
 (0)