Skip to content

Commit 398dcd7

Browse files
guptaakacopybara-github
authored andcommitted
Add support for a static colocated Python sidecar
PiperOrigin-RevId: 932698806
1 parent 1b72e01 commit 398dcd7

4 files changed

Lines changed: 95 additions & 3 deletions

File tree

pathwaysutils/experimental/shared_pathways_service/deploy_pathways_service.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
_SERVER_IMAGE = flags.DEFINE_string(
2727
"server_image", None, "Full path to the server Docker image"
2828
)
29+
_SIDECAR_IMAGE = flags.DEFINE_string(
30+
"sidecar_image",
31+
"us-docker.pkg.dev/cloud-tpu-v2-images/pathways-colocated-python/sidecar:20260423-python_3.12-jax_0.10.0",
32+
"Full path to the sidecar Docker image",
33+
)
2934
_TPU_TYPE = flags.DEFINE_enum(
3035
"tpu_type", "v6e", ["v5e", "v5p", "v6e", "tpu7x"], "TPU type"
3136
)
@@ -52,6 +57,7 @@
5257
False,
5358
"If true, only print the generated YAML without deploying.",
5459
)
60+
_SIDECAR_SHM_DIR = "/tmp/sidecar_dir"
5561

5662

5763
@dataclasses.dataclass(frozen=True)
@@ -191,6 +197,7 @@ def run_deployment(
191197
jobset_name,
192198
gcs_bucket,
193199
server_image,
200+
sidecar_image,
194201
template_file,
195202
dry_run,
196203
deploy_func: Callable[[dict[str, Any]], None] = deploy_jobset,
@@ -202,6 +209,8 @@ def run_deployment(
202209
context = {
203210
"JOBSET_NAME": jobset_name,
204211
"SERVER_IMAGE": server_image,
212+
"SIDECAR_IMAGE": sidecar_image,
213+
"SIDECAR_SHM_DIR": _SIDECAR_SHM_DIR,
205214
"GCS_SCRATCH_LOCATION": gcs_bucket,
206215
"NUM_SLICES": num_slices,
207216
"INSTANCE_TYPE": f"{tpu_config.instance_prefix}:{topology}",
@@ -246,6 +255,7 @@ def main(argv: Sequence[str]) -> None:
246255
jobset_name=_JOBSET_NAME.value,
247256
gcs_bucket=_GCS_BUCKET.value,
248257
server_image=server_image,
258+
sidecar_image=_SIDECAR_IMAGE.value,
249259
template_file=_TEMPLATE_FILE.value,
250260
dry_run=_DRY_RUN.value,
251261
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use the JAX image with the custom-built sidecar as the base.
2+
FROM us-docker.pkg.dev/cloud-tpu-v2-images/pathways-colocated-python/sidecar:20260423-python_3.12-jax_0.10.0
3+
4+
# Set the working directory
5+
WORKDIR /app
6+
7+
# 1. Upgrade pip and build tools
8+
RUN --mount=type=cache,target=/root/.cache/uv \
9+
uv pip install --upgrade pip setuptools wheel
10+
11+
# 2. Clone MaxText
12+
RUN git clone https://github.com/google/maxtext.git
13+
14+
# ADD THE CACHE MOUNT HERE
15+
# Install the same version of JAX and JAXlib as the base image.
16+
RUN --mount=type=cache,target=/root/.cache/uv \
17+
uv pip install -r maxtext/src/dependencies/requirements/base_requirements/requirements.txt && \
18+
uv pip install --upgrade jax==0.10.0 jaxlib==0.10.0
19+
20+
# 3. (optional) Copy your local edits to MaxText requirements and src, if any.
21+
# Make sure you're running this docker build from the root of your local MaxText
22+
# checkout.
23+
# COPY maxtext/src/dependencies/requirements/base_requirements/requirements.txt ./requirements.txt
24+
# COPY maxtext/src /app/maxtext/src
25+
26+
# Ensure MaxText src is in PYTHONPATH
27+
# ENV PYTHONPATH=/app/maxtext/src:$PYTHONPATH

pathwaysutils/experimental/shared_pathways_service/isc_pathways.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,26 @@ class ProxyOptions:
4848
use_insecure_credentials: Whether to use insecure gRPC credentials for the
4949
proxy server.
5050
xla_flags: A list of XLA flags to pass to the proxy server.
51+
sidecar: Whether to use the worker sidecar or not.
5152
"""
5253
use_insecure_credentials: bool = False
5354
xla_flags: list[str] = dataclasses.field(default_factory=list)
55+
sidecar: bool = False
5456

5557
@classmethod
5658
def from_list(cls, options: Iterable[str] | None) -> "ProxyOptions":
5759
"""Creates a ProxyOptions object from a list of 'key:value' strings."""
5860
use_insecure = False
61+
use_sidecar = False
5962
xla_flags = []
6063
for option in options or []:
6164
if ":" in option:
6265
key, value = option.split(":", 1)
6366
key_strip = key.strip().lower()
6467
if key_strip == "use_insecure_credentials":
6568
use_insecure = value.strip().lower() == "true"
69+
elif key_strip == "sidecar":
70+
use_sidecar = value.strip().lower() == "true"
6671
elif key_strip == "xla_flags":
6772
val_strip = value.strip()
6873
if (
@@ -78,7 +83,11 @@ def from_list(cls, options: Iterable[str] | None) -> "ProxyOptions":
7883
if xla_flags:
7984
validators.validate_xla_flags(xla_flags)
8085

81-
return cls(use_insecure_credentials=use_insecure, xla_flags=xla_flags)
86+
return cls(
87+
use_insecure_credentials=use_insecure,
88+
xla_flags=xla_flags,
89+
sidecar=use_sidecar,
90+
)
8291

8392

8493
def _deploy_pathways_proxy_server(
@@ -134,6 +143,9 @@ def _deploy_pathways_proxy_server(
134143
)
135144
proxy_args_str = "\n" + proxy_args_str
136145

146+
if proxy_options.sidecar:
147+
proxy_args_str += "\n - --sidecar_name=external"
148+
137149
template = string.Template(yaml_template)
138150
substituted_yaml = template.substitute(
139151
PROXY_JOB_NAME=proxy_job_name,

pathwaysutils/experimental/shared_pathways_service/yamls/pw-service.yaml

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ spec:
8787
- --server_port=29005
8888
- --resource_manager_address=$$(PATHWAYS_HEAD):29001
8989
- --gcs_scratch_location=${GCS_SCRATCH_LOCATION}
90+
- --cloud_pathways_sidecar_shm_directory=${SIDECAR_SHM_DIR}
9091
env:
9192
- name: TPU_MIN_LOG_LEVEL
9293
value: "0"
@@ -133,8 +134,47 @@ spec:
133134
limits:
134135
google.com/tpu: "${CHIPS_PER_VM}"
135136
volumeMounts:
136-
- mountPath: /tmp
137-
name: shared-tmp
137+
- name: shared-tmp
138+
mountPath: /tmp
139+
- name: sidecar-shared-memory
140+
mountPath: ${SIDECAR_SHM_DIR}
141+
initContainers:
142+
- name: colocated-python-sidecar
143+
image: ${SIDECAR_IMAGE}
144+
imagePullPolicy: Always
145+
env:
146+
- name: GRPC_SERVER_ADDRESS
147+
value: '''0.0.0.0:50051'''
148+
- name: CLOUD_PATHWAYS_SIDECAR_SHM_DIRECTORY
149+
value: ${SIDECAR_SHM_DIR}
150+
- name: PYTHONUNBUFFERED
151+
value: '1'
152+
# --- High Verbosity Logging Variables ---
153+
- name: LOGLEVEL
154+
value: 'DEBUG'
155+
- name: GLOG_minloglevel
156+
value: '0' # 0 = INFO level base
157+
- name: GLOG_v
158+
value: '5' # Extreme verbosity for all C++ modules
159+
- name: TF_CPP_MIN_LOG_LEVEL
160+
value: '0'
161+
- name: TF_CPP_MIN_VLOG_LEVEL
162+
value: '5' # TF/XLA verbose logging
163+
- name: TPU_MIN_LOG_LEVEL
164+
value: '0'
165+
- name: GLOG_vmodule
166+
value: 'jax_array_handlers=5,type_handlers=5,tensorstore_utils=5'
167+
# ----------------------------------------
168+
ports:
169+
- containerPort: 50051
170+
protocol: TCP
171+
resources: {}
172+
restartPolicy: Always
173+
volumeMounts:
174+
- name: shared-tmp
175+
mountPath: /tmp
176+
- name: sidecar-shared-memory
177+
mountPath: ${SIDECAR_SHM_DIR}
138178
dnsPolicy: ClusterFirstWithHostNet
139179
hostNetwork: true
140180
nodeSelector:
@@ -146,6 +186,9 @@ spec:
146186
hostPath:
147187
path: /tmp
148188
type: DirectoryOrCreate
189+
- name: sidecar-shared-memory
190+
emptyDir:
191+
medium: Memory
149192
startupPolicy:
150193
startupPolicyOrder: InOrder
151194
successPolicy:

0 commit comments

Comments
 (0)