xpk 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. xpk/__init__.py +15 -0
  2. xpk/api/__init__.py +15 -0
  3. xpk/api/storage_crd.yaml +52 -0
  4. xpk/commands/__init__.py +15 -0
  5. xpk/commands/batch.py +131 -0
  6. xpk/commands/cluster.py +808 -0
  7. xpk/commands/cluster_gcluster.py +269 -0
  8. xpk/commands/common.py +44 -0
  9. xpk/commands/config.py +29 -0
  10. xpk/commands/info.py +243 -0
  11. xpk/commands/inspector.py +357 -0
  12. xpk/commands/job.py +199 -0
  13. xpk/commands/kind.py +283 -0
  14. xpk/commands/kjob_common.py +44 -0
  15. xpk/commands/run.py +128 -0
  16. xpk/commands/shell.py +140 -0
  17. xpk/commands/storage.py +267 -0
  18. xpk/commands/version.py +27 -0
  19. xpk/commands/workload.py +889 -0
  20. xpk/core/__init__.py +15 -0
  21. xpk/core/blueprint/__init__.py +15 -0
  22. xpk/core/blueprint/blueprint_definitions.py +62 -0
  23. xpk/core/blueprint/blueprint_generator.py +708 -0
  24. xpk/core/capacity.py +185 -0
  25. xpk/core/cluster.py +564 -0
  26. xpk/core/cluster_private.py +200 -0
  27. xpk/core/commands.py +356 -0
  28. xpk/core/config.py +179 -0
  29. xpk/core/docker_container.py +225 -0
  30. xpk/core/docker_image.py +210 -0
  31. xpk/core/docker_manager.py +308 -0
  32. xpk/core/docker_resources.py +350 -0
  33. xpk/core/filestore.py +251 -0
  34. xpk/core/gcloud_context.py +196 -0
  35. xpk/core/gcluster_manager.py +176 -0
  36. xpk/core/gcsfuse.py +50 -0
  37. xpk/core/kjob.py +444 -0
  38. xpk/core/kueue.py +358 -0
  39. xpk/core/monitoring.py +134 -0
  40. xpk/core/nap.py +361 -0
  41. xpk/core/network.py +377 -0
  42. xpk/core/nodepool.py +581 -0
  43. xpk/core/pathways.py +377 -0
  44. xpk/core/ray.py +222 -0
  45. xpk/core/remote_state/__init__.py +15 -0
  46. xpk/core/remote_state/fuse_remote_state.py +99 -0
  47. xpk/core/remote_state/remote_state_client.py +38 -0
  48. xpk/core/resources.py +238 -0
  49. xpk/core/scheduling.py +253 -0
  50. xpk/core/storage.py +581 -0
  51. xpk/core/system_characteristics.py +1432 -0
  52. xpk/core/vertex.py +105 -0
  53. xpk/core/workload.py +341 -0
  54. xpk/core/workload_decorators/__init__.py +15 -0
  55. xpk/core/workload_decorators/rdma_decorator.py +129 -0
  56. xpk/core/workload_decorators/storage_decorator.py +52 -0
  57. xpk/core/workload_decorators/tcpxo_decorator.py +190 -0
  58. xpk/main.py +75 -0
  59. xpk/parser/__init__.py +15 -0
  60. xpk/parser/batch.py +43 -0
  61. xpk/parser/cluster.py +662 -0
  62. xpk/parser/common.py +259 -0
  63. xpk/parser/config.py +49 -0
  64. xpk/parser/core.py +135 -0
  65. xpk/parser/info.py +64 -0
  66. xpk/parser/inspector.py +65 -0
  67. xpk/parser/job.py +147 -0
  68. xpk/parser/kind.py +95 -0
  69. xpk/parser/run.py +47 -0
  70. xpk/parser/shell.py +59 -0
  71. xpk/parser/storage.py +316 -0
  72. xpk/parser/validators.py +39 -0
  73. xpk/parser/version.py +23 -0
  74. xpk/parser/workload.py +726 -0
  75. xpk/templates/__init__.py +15 -0
  76. xpk/templates/storage.yaml +13 -0
  77. xpk/utils/__init__.py +15 -0
  78. xpk/utils/console.py +55 -0
  79. xpk/utils/file.py +82 -0
  80. xpk/utils/gcs_utils.py +125 -0
  81. xpk/utils/kubectl.py +57 -0
  82. xpk/utils/network.py +168 -0
  83. xpk/utils/objects.py +88 -0
  84. xpk/utils/templates.py +28 -0
  85. xpk/utils/validation.py +80 -0
  86. xpk/utils/yaml.py +30 -0
  87. xpk-0.0.1.dist-info/LICENSE +202 -0
  88. xpk-0.0.1.dist-info/METADATA +1498 -0
  89. xpk-0.0.1.dist-info/RECORD +92 -0
  90. xpk-0.0.1.dist-info/WHEEL +5 -0
  91. xpk-0.0.1.dist-info/entry_points.txt +2 -0
  92. xpk-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1498 @@
1
+ Metadata-Version: 2.2
2
+ Name: xpk
3
+ Version: 0.0.1
4
+ Summary: xpk helps Cloud developers to orchestrate training jobs on accelerators on GKE.
5
+ Author-email: XPK team <xpk-code-reviewers@google.com>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/google/xpk
8
+ Project-URL: Bug Tracker, https://github.com/google/xpk/issues
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: cloud-accelerator-diagnostics==0.1.1
15
+ Requires-Dist: tabulate==0.9.0
16
+ Requires-Dist: ruamel.yaml==0.18.10
17
+ Requires-Dist: pyyaml==6.0.2
18
+ Requires-Dist: docker==7.1.0
19
+ Requires-Dist: kubernetes==31.0.0
20
+ Requires-Dist: google-cloud==0.34.0
21
+ Requires-Dist: google-api-core==2.24.1
22
+ Requires-Dist: packaging==24.2
23
+ Requires-Dist: google-cloud-filestore==1.12.0
24
+ Requires-Dist: google-cloud-storage==2.19.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: pyink==24.3.0; extra == "dev"
27
+ Requires-Dist: pylint>=2.6.0; extra == "dev"
28
+ Requires-Dist: pre-commit; extra == "dev"
29
+ Requires-Dist: pytest; extra == "dev"
30
+ Requires-Dist: docker==7.1.0; extra == "dev"
31
+
32
+ <!--
33
+ Copyright 2023 Google LLC
34
+
35
+ Licensed under the Apache License, Version 2.0 (the "License");
36
+ you may not use this file except in compliance with the License.
37
+ You may obtain a copy of the License at
38
+
39
+ https://www.apache.org/licenses/LICENSE-2.0
40
+
41
+ Unless required by applicable law or agreed to in writing, software
42
+ distributed under the License is distributed on an "AS IS" BASIS,
43
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44
+ See the License for the specific language governing permissions and
45
+ limitations under the License.
46
+ -->
47
+
48
+ [![Build Tests](https://github.com/google/xpk/actions/workflows/build_tests.yaml/badge.svg)](https://github.com/google/xpk/actions/workflows/build_tests.yaml)
49
+ [![Nightly Tests](https://github.com/google/xpk/actions/workflows/nightly_tests.yaml/badge.svg)](https://github.com/google/xpk/actions/workflows/nightly_tests.yaml)
50
+ [![Develop Tests](https://github.com/AI-Hypercomputer/xpk/actions/workflows/build_tests.yaml/badge.svg?branch=develop)](https://github.com/AI-Hypercomputer/xpk/actions/workflows/build_tests.yaml)
51
+ [![Develop Nightly Tests](https://github.com/AI-Hypercomputer/xpk/actions/workflows/nightly_tests.yaml/badge.svg?branch=develop)](https://github.com/AI-Hypercomputer/xpk/actions/workflows/nightly_tests.yaml)
52
+
53
+ # Overview
54
+
55
+ xpk (Accelerated Processing Kit, pronounced x-p-k,) is a software tool to help
56
+ Cloud developers to orchestrate training jobs on accelerators such as TPUs and
57
+ GPUs on GKE. xpk handles the "multihost pods" of TPUs, GPUs (HGX H100) and CPUs
58
+ (n2-standard-32) as first class citizens.
59
+
60
+ xpk decouples provisioning capacity from running jobs. There are two structures:
61
+ clusters (provisioned VMs) and workloads (training jobs). Clusters represent the
62
+ physical resources you have available. Workloads represent training jobs -- at
63
+ any time some of these will be completed, others will be running and some will
64
+ be queued, waiting for cluster resources to become available.
65
+
66
+ The ideal workflow starts by provisioning the clusters for all of the ML
67
+ hardware you have reserved. Then, without re-provisioning, submit jobs as
68
+ needed. By eliminating the need for re-provisioning between jobs, using Docker
69
+ containers with pre-installed dependencies and cross-ahead of time compilation,
70
+ these queued jobs run with minimal start times. Further, because workloads
71
+ return the hardware back to the shared pool when they complete, developers can
72
+ achieve better use of finite hardware resources. And automated tests can run
73
+ overnight while resources tend to be underutilized.
74
+
75
+ xpk supports the following TPU types:
76
+ * v4
77
+ * v5e
78
+ * v5p
79
+ * Trillium (v6e)
80
+
81
+ and the following GPU types:
82
+ * A100
83
+ * A3-Highgpu (h100)
84
+ * A3-Mega (h100-mega) - [Create cluster](#provisioning-a3-ultra-and-a3-mega-clusters-gpu-machines), [Create workloads](#workloads-for-a3-ultra-and-a3-mega-clusters-gpu-machines)
85
+ * A3-Ultra (h200) - [Create cluster](#provisioning-a3-ultra-and-a3-mega-clusters-gpu-machines), [Create workloads](#workloads-for-a3-ultra-and-a3-mega-clusters-gpu-machines)
86
+
87
+ and the following CPU types:
88
+ * n2-standard-32
89
+
90
+ xpk also supports Google Cloud Storage solutions:
91
+ * [Cloud Storage FUSE](#fuse)
92
+ * [Filestore](#filestore)
93
+
94
+ # Permissions needed on Cloud Console:
95
+
96
+ * Artifact Registry Writer
97
+ * Compute Admin
98
+ * Kubernetes Engine Admin
99
+ * Logging Admin
100
+ * Monitoring Admin
101
+ * Service Account User
102
+ * Storage Admin
103
+ * Vertex AI Administrator
104
+ * Filestore Editor (This role is neccessary if you want to run `storage create` command with `--type=gcpfilestore`)
105
+
106
+ # Prerequisites
107
+
108
+ Following tools must be installed:
109
+
110
+ - python >= 3.10 (download from [here](https://www.python.org/downloads/))
111
+ - pip ([installation instruction](https://pip.pypa.io/en/stable/installation/))
112
+ - python venv ([installation instruction](https://virtualenv.pypa.io/en/latest/installation.html))
113
+ (all three of above can be installed at once from [here](https://packaging.python.org/en/latest/guides/installing-using-linux-tools/#installing-pip-setuptools-wheel-with-linux-package-managers))
114
+ - gcloud (install from [here](https://cloud.google.com/sdk/gcloud#download_and_install_the))
115
+ - Run `gcloud init`
116
+ - [Authenticate](https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login) to Google Cloud
117
+ - kubectl (install from [here](https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl#install_kubectl))
118
+ - Install `gke-gcloud-auth-plugin` from [here](https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl#install_plugin)
119
+ - docker ([installation instruction](https://docs.docker.com/engine/install/))
120
+ - Run `gcloud auth configure-docker` to ensure images can be uploaded to registry
121
+ - make - please run below command.
122
+ ```shell
123
+ # sudo may be required
124
+ apt-get -y install make
125
+ ```
126
+ In addition, below dependencies can be installed either using provided links or using `make install` command, if xpk is downloaded via `git clone` command:
127
+ - kueuectl (install from [here](https://kueue.sigs.k8s.io/docs/reference/kubectl-kueue/installation/))
128
+ - kjob (installation instructions [here](https://github.com/kubernetes-sigs/kjob/blob/main/docs/installation.md))
129
+
130
+ # Installation
131
+ To install xpk, install required tools mentioned in [prerequisites](#prerequisites). [Makefile](https://github.com/AI-Hypercomputer/xpk/blob/main/Makefile) provides a way to install all neccessary tools. XPK can be installed via pip:
132
+
133
+ ```shell
134
+ pip install xpk
135
+ ```
136
+
137
+ If you see an error saying: `This environment is externally managed`, please use a virtual environment.
138
+
139
+ ```shell
140
+ ## One time step of creating the venv
141
+ VENV_DIR=~/venvp3
142
+ python3 -m venv $VENV_DIR
143
+ ## Enter your venv.
144
+ source $VENV_DIR/bin/activate
145
+ ## Clone the repository and installing dependencies.
146
+ pip install xpk
147
+ ```
148
+
149
+ If you are running XPK by cloning GitHub repository, first run the
150
+ following commands to begin using XPK commands:
151
+
152
+ ```shell
153
+ git clone https://github.com/google/xpk.git
154
+ cd xpk
155
+ # Install required dependencies with make
156
+ make install && export PATH=$PATH:$PWD/bin
157
+ ```
158
+
159
+ If you want to have installed dependecies persist in your PATH please run:
160
+ `echo $PWD/bin` and add its value to `PATH` in .bashrc or .zshrc
161
+
162
+ If you see an error saying: `This environment is externally managed`, please use a virtual environment.
163
+
164
+ Example:
165
+
166
+ ```shell
167
+ ## One time step of creating the venv
168
+ VENV_DIR=~/venvp3
169
+ python3 -m venv $VENV_DIR
170
+ ## Enter your venv.
171
+ source $VENV_DIR/bin/activate
172
+ ## Clone the repository and installing dependencies.
173
+ git clone https://github.com/google/xpk.git
174
+ cd xpk
175
+ # Install required dependencies with make
176
+ make install && export PATH=$PATH:$PWD/bin
177
+ ```
178
+
179
+ # XPK for Large Scale (>1k VMs)
180
+
181
+ Follow user instructions in [xpk-large-scale-guide.sh](xpk-large-scale-guide.sh)
182
+ to use xpk for a GKE cluster greater than 1000 VMs. Run these steps to set up a
183
+ GKE cluster with large scale training and high throughput support with XPK, and
184
+ run jobs with XPK. We recommend you manually copy commands per step and verify
185
+ the outputs of each step.
186
+
187
+ # Example usages:
188
+
189
+ To get started, be sure to set your GCP Project and Zone as usual via `gcloud
190
+ config set`.
191
+
192
+ Below are reference commands. A typical journey starts with a `Cluster Create`
193
+ followed by many `Workload Create`s. To understand the state of the system you
194
+ might want to use `Cluster List` or `Workload List` commands. Finally, you can
195
+ cleanup with a `Cluster Delete`.
196
+
197
+ If you have failures with workloads not running, use `xpk inspector` to investigate
198
+ more.
199
+
200
+ If you need your Workloads to have persistent storage, use `xpk storage` to find out more.
201
+
202
+ ## Cluster Create
203
+
204
+ First set the project and zone through gcloud config or xpk arguments.
205
+
206
+ ```shell
207
+ PROJECT_ID=my-project-id
208
+ ZONE=us-east5-b
209
+ # gcloud config:
210
+ gcloud config set project $PROJECT_ID
211
+ gcloud config set compute/zone $ZONE
212
+ # xpk arguments
213
+ xpk .. --zone $ZONE --project $PROJECT_ID
214
+ ```
215
+
216
+ The cluster created is a regional cluster to enable the GKE control plane across
217
+ all zones.
218
+
219
+ * Cluster Create (provision reserved capacity):
220
+
221
+ ```shell
222
+ # Find your reservations
223
+ gcloud compute reservations list --project=$PROJECT_ID
224
+ # Run cluster create with reservation.
225
+ python3 xpk.py cluster create \
226
+ --cluster xpk-test --tpu-type=v5litepod-256 \
227
+ --num-slices=2 \
228
+ --reservation=$RESERVATION_ID
229
+ ```
230
+
231
+ * Cluster Create (provision on-demand capacity):
232
+
233
+ ```shell
234
+ python3 xpk.py cluster create \
235
+ --cluster xpk-test --tpu-type=v5litepod-16 \
236
+ --num-slices=4 --on-demand
237
+ ```
238
+
239
+ * Cluster Create (provision spot / preemptable capacity):
240
+
241
+ ```shell
242
+ python3 xpk.py cluster create \
243
+ --cluster xpk-test --tpu-type=v5litepod-16 \
244
+ --num-slices=4 --spot
245
+ ```
246
+
247
+ * Cluster Create for Pathways:
248
+ Pathways compatible cluster can be created using `cluster create-pathways`.
249
+ ```shell
250
+ python3 xpk.py cluster create-pathways \
251
+ --cluster xpk-pw-test \
252
+ --num-slices=4 --on-demand \
253
+ --tpu-type=v5litepod-16
254
+ ```
255
+
256
+ * Cluster Create for Ray:
257
+ A cluster with KubeRay enabled and a RayCluster can be created using `cluster create-ray`.
258
+ ```shell
259
+ python3 xpk.py cluster create-ray \
260
+ --cluster xpk-rc-test \
261
+ --ray-version=2.39.0 \
262
+ --num-slices=4 --on-demand \
263
+ --tpu-type=v5litepod-8
264
+ ```
265
+
266
+ * Cluster Create can be called again with the same `--cluster name` to modify
267
+ the number of slices or retry failed steps.
268
+
269
+ For example, if a user creates a cluster with 4 slices:
270
+
271
+ ```shell
272
+ python3 xpk.py cluster create \
273
+ --cluster xpk-test --tpu-type=v5litepod-16 \
274
+ --num-slices=4 --reservation=$RESERVATION_ID
275
+ ```
276
+
277
+ and recreates the cluster with 8 slices. The command will rerun to create 4
278
+ new slices:
279
+
280
+ ```shell
281
+ python3 xpk.py cluster create \
282
+ --cluster xpk-test --tpu-type=v5litepod-16 \
283
+ --num-slices=8 --reservation=$RESERVATION_ID
284
+ ```
285
+
286
+ and recreates the cluster with 6 slices. The command will rerun to delete 2
287
+ slices. The command will warn the user when deleting slices.
288
+ Use `--force` to skip prompts.
289
+
290
+ ```shell
291
+ python3 xpk.py cluster create \
292
+ --cluster xpk-test --tpu-type=v5litepod-16 \
293
+ --num-slices=6 --reservation=$RESERVATION_ID
294
+
295
+ # Skip delete prompts using --force.
296
+
297
+ python3 xpk.py cluster create --force \
298
+ --cluster xpk-test --tpu-type=v5litepod-16 \
299
+ --num-slices=6 --reservation=$RESERVATION_ID
300
+ ```
301
+
302
+ and recreates the cluster with 4 slices of v4-8. The command will rerun to delete
303
+ 6 slices of v5litepod-16 and create 4 slices of v4-8. The command will warn the
304
+ user when deleting slices. Use `--force` to skip prompts.
305
+
306
+ ```shell
307
+ python3 xpk.py cluster create \
308
+ --cluster xpk-test --tpu-type=v4-8 \
309
+ --num-slices=4 --reservation=$RESERVATION_ID
310
+
311
+ # Skip delete prompts using --force.
312
+
313
+ python3 xpk.py cluster create --force \
314
+ --cluster xpk-test --tpu-type=v4-8 \
315
+ --num-slices=4 --reservation=$RESERVATION_ID
316
+ ```
317
+
318
+ ### Create Private Cluster
319
+
320
+ XPK allows you to create a private GKE cluster for enhanced security. In a private cluster, nodes and pods are isolated from the public internet, providing an additional layer of protection for your workloads.
321
+
322
+ To create a private cluster, use the following arguments:
323
+
324
+ **`--private`**
325
+
326
+ This flag enables the creation of a private GKE cluster. When this flag is set:
327
+
328
+ * Nodes and pods are isolated from the direct internet access.
329
+ * `master_authorized_networks` is automatically enabled.
330
+ * Access to the cluster's control plane is restricted to your current machine's IP address by default.
331
+
332
+ **`--authorized-networks`**
333
+
334
+ This argument allows you to specify additional IP ranges (in CIDR notation) that are authorized to access the private cluster's control plane and perform `kubectl` commands.
335
+
336
+ * Even if this argument is not set when you have `--private`, your current machine's IP address will always be given access to the control plane.
337
+ * If this argument is used with an existing private cluster, it will replace the existing authorized networks.
338
+
339
+ **Example Usage:**
340
+
341
+ * To create a private cluster and allow access to Control Plane only to your current machine:
342
+
343
+ ```shell
344
+ python3 xpk.py cluster create \
345
+ --cluster=xpk-private-cluster \
346
+ --tpu-type=v4-8 --num-slices=2 \
347
+ --private
348
+ ```
349
+
350
+ * To create a private cluster and allow access to Control Plane only to your current machine and the IP ranges `1.2.3.0/24` and `1.2.4.5/32`:
351
+
352
+ ```shell
353
+ python3 xpk.py cluster create \
354
+ --cluster=xpk-private-cluster \
355
+ --tpu-type=v4-8 --num-slices=2 \
356
+ --authorized-networks 1.2.3.0/24 1.2.4.5/32
357
+
358
+ # --private is optional when you set --authorized-networks
359
+ ```
360
+
361
+ > **Important Notes:**
362
+ > * The argument `--private` is only applicable when creating new clusters. You cannot convert an existing public cluster to a private cluster using these flags.
363
+ > * The argument `--authorized-networks` is applicable when creating new clusters or using an existing _*private*_ cluster. You cannot convert an existing public cluster to a private cluster using these flags.
364
+ > * You need to [set up a Cluster NAT for your VPC network](https://cloud.google.com/nat/docs/set-up-manage-network-address-translation#creating_nat) so that the Nodes and Pods have outbound access to the internet. This is required because XPK installs and configures components such as kueue that need access to external sources like `registry.k8.io`.
365
+
366
+
367
+ ### Create Vertex AI Tensorboard
368
+ *Note: This feature is available in XPK >= 0.4.0. Enable [Vertex AI API](https://cloud.google.com/vertex-ai/docs/start/cloud-environment#enable_vertexai_apis) in your Google Cloud console to use this feature. Make sure you have
369
+ [Vertex AI Administrator](https://cloud.google.com/vertex-ai/docs/general/access-control#aiplatform.admin) role
370
+ assigned to your user account.*
371
+
372
+ Vertex AI Tensorboard is a fully managed version of open-source Tensorboard. To learn more about Vertex AI Tensorboard, visit [this](https://cloud.google.com/vertex-ai/docs/experiments/tensorboard-introduction). Note that Vertex AI Tensorboard is only available in [these](https://cloud.google.com/vertex-ai/docs/general/locations#available-regions) regions.
373
+
374
+ You can create a Vertex AI Tensorboard for your cluster with `Cluster Create` command. XPK will create a single Vertex AI Tensorboard instance per cluster.
375
+
376
+ * Create Vertex AI Tensorboard in default region with default Tensorboard name:
377
+
378
+ ```shell
379
+ python3 xpk.py cluster create \
380
+ --cluster xpk-test --num-slices=1 --tpu-type=v4-8 \
381
+ --create-vertex-tensorboard
382
+ ```
383
+
384
+ will create a Vertex AI Tensorboard with the name `xpk-test-tb-instance` (*<args.cluster>-tb-instance*) in `us-central1` (*default region*).
385
+
386
+ * Create Vertex AI Tensorboard in user-specified region with default Tensorboard name:
387
+
388
+ ```shell
389
+ python3 xpk.py cluster create \
390
+ --cluster xpk-test --num-slices=1 --tpu-type=v4-8 \
391
+ --create-vertex-tensorboard --tensorboard-region=us-west1
392
+ ```
393
+
394
+ will create a Vertex AI Tensorboard with the name `xpk-test-tb-instance` (*<args.cluster>-tb-instance*) in `us-west1`.
395
+
396
+ * Create Vertex AI Tensorboard in default region with user-specified Tensorboard name:
397
+
398
+ ```shell
399
+ python3 xpk.py cluster create \
400
+ --cluster xpk-test --num-slices=1 --tpu-type=v4-8 \
401
+ --create-vertex-tensorboard --tensorboard-name=tb-testing
402
+ ```
403
+
404
+ will create a Vertex AI Tensorboard with the name `tb-testing` in `us-central1`.
405
+
406
+ * Create Vertex AI Tensorboard in user-specified region with user-specified Tensorboard name:
407
+
408
+ ```shell
409
+ python3 xpk.py cluster create \
410
+ --cluster xpk-test --num-slices=1 --tpu-type=v4-8 \
411
+ --create-vertex-tensorboard --tensorboard-region=us-west1 --tensorboard-name=tb-testing
412
+ ```
413
+
414
+ will create a Vertex AI Tensorboard instance with the name `tb-testing` in `us-west1`.
415
+
416
+ * Create Vertex AI Tensorboard in an unsupported region:
417
+
418
+ ```shell
419
+ python3 xpk.py cluster create \
420
+ --cluster xpk-test --num-slices=1 --tpu-type=v4-8 \
421
+ --create-vertex-tensorboard --tensorboard-region=us-central2
422
+ ```
423
+
424
+ will fail the cluster creation process because Vertex AI Tensorboard is not supported in `us-central2`.
425
+
426
+ ## Cluster Delete
427
+ * Cluster Delete (deprovision capacity):
428
+
429
+ ```shell
430
+ python3 xpk.py cluster delete \
431
+ --cluster xpk-test
432
+ ```
433
+ ## Cluster List
434
+ * Cluster List (see provisioned capacity):
435
+
436
+ ```shell
437
+ python3 xpk.py cluster list
438
+ ```
439
+ ## Cluster Describe
440
+ * Cluster Describe (see capacity):
441
+
442
+ ```shell
443
+ python3 xpk.py cluster describe \
444
+ --cluster xpk-test
445
+ ```
446
+
447
+ ## Cluster Cacheimage
448
+ * Cluster Cacheimage (enables faster start times):
449
+
450
+ ```shell
451
+ python3 xpk.py cluster cacheimage \
452
+ --cluster xpk-test --docker-image gcr.io/your_docker_image \
453
+ --tpu-type=v5litepod-16
454
+ ```
455
+
456
+ ## Provisioning A3-Ultra and A3-Mega clusters (GPU machines)
457
+ To create a cluster with A3 machines, run the below command. To create workloads on these clusters see [here](#workloads-for-a3-ultra-and-a3-mega-clusters-gpu-machines).
458
+ * For A3-Ultra: --device-type=h200-141gb-8
459
+ * For A3-Mega: --device-type=h100-mega-80gb-8
460
+
461
+ ```shell
462
+ python3 xpk.py cluster create \
463
+ --cluster CLUSTER_NAME --device-type=h200-141gb-8 \
464
+ --zone=$COMPUTE_ZONE --project=$PROJECT_ID \
465
+ --num-nodes=4 --reservation=$RESERVATION_ID
466
+ ```
467
+ Currently, the below flags/arguments are supported for A3-Mega and A3-Ultra machines:
468
+ * --num-nodes
469
+ * --default-pool-cpu-machine-type
470
+ * --default-pool-cpu-num-nodes
471
+ * --reservation
472
+ * --spot
473
+ * --on-demand (only A3-Mega)
474
+
475
+
476
+ ## Storage
477
+ Currently XPK supports two types of storages: Cloud Storage FUSE and Google Cloud Filestore.
478
+
479
+ ### FUSE
480
+ A FUSE adapter lets you mount and access Cloud Storage buckets as local file systems, so applications can read and write objects in your bucket using standard file system semantics.
481
+
482
+ To use the GCS FUSE with XPK you need to create a [Storage Bucket](https://console.cloud.google.com/storage/).
483
+
484
+ Once it's ready you can use `xpk storage attach` with `--type=gcsfuse` command to attach a FUSE storage instance to your cluster:
485
+
486
+ ```shell
487
+ python3 xpk.py storage attach test-fuse-storage --type=gcsfuse \
488
+ --project=$PROJECT --cluster=$CLUSTER --zone=$ZONE
489
+ --mount-point='/test-mount-point' --readonly=false \
490
+ --bucket=test-bucket --size=1 --auto-mount=false
491
+ ```
492
+
493
+ Parameters:
494
+
495
+ - `--type` - type of the storage, currently xpk supports `gcsfuse` and `gcpfilestore` only.
496
+ - `--auto-mount` - if set to true all workloads will have this storage mounted by default.
497
+ - `--mount-point` - the path on which this storage should be mounted for a workload.
498
+ - `--readonly` - if set to true, workload can only read from storage.
499
+ - `--size` - size of the storage in Gb.
500
+ - `--bucket` - name of the storage bucket. If not set then the name of the storage is used as a bucket name.
501
+
502
+ ### Filestore
503
+
504
+ A Filestore adapter lets you mount and access [Filestore instances](https://cloud.google.com/filestore/) as local file systems, so applications can read and write objects in your volumes using standard file system semantics.
505
+
506
+ To create and attach a GCP Filestore instance to your cluster use `xpk storage create` command with `--type=gcpfilestore`:
507
+
508
+ ```shell
509
+ python3 xpk.py storage create test-fs-storage --type=gcpfilestore \
510
+ --auto-mount=false --mount-point=/data-fs --readonly=false \
511
+ --size=1024 --tier=BASIC_HDD --access_mode=ReadWriteMany --vol=default \
512
+ --project=$PROJECT --cluster=$CLUSTER --zone=$ZONE
513
+ ```
514
+
515
+ You can also attach an existing Filestore instance to your cluster using `xpk storage attach` command:
516
+
517
+ ```shell
518
+ python3 xpk.py storage attach test-fs-storage --type=gcpfilestore \
519
+ --auto-mount=false --mount-point=/data-fs --readonly=false \
520
+ --size=1024 --tier=BASIC_HDD --access_mode=ReadWriteMany --vol=default \
521
+ --project=$PROJECT --cluster=$CLUSTER --zone=$ZONE
522
+ ```
523
+
524
+ The command above is also useful when attaching multiple volumes from the same Filestore instance.
525
+
526
+ Commands `xpk storage create` and `xpk storage attach` with `--type=gcpfilestore` accept following arguments:
527
+ - `--type` - type of the storage.
528
+ - `--auto-mount` - if set to true all workloads will have this storage mounted by default.
529
+ - `--mount-point` - the path on which this storage should be mounted for a workload.
530
+ - `--readonly` - if set to true, workload can only read from storage.
531
+ - `--size` - size of the Filestore instance that will be created in Gb.
532
+ - `--tier` - tier of the Filestore instance that will be created. Possible options are: `[BASIC_HDD, BASIC_SSD, ZONAL, REGIONAL, ENTERPRISE]`
533
+ - `--access-mode` - access mode of the Filestore instance that will be created. Possible values are: `[ReadWriteOnce, ReadOnlyMany, ReadWriteMany]`
534
+ - `--vol` - file share name of the Filestore instance that will be created.
535
+ - `--instance` - the name of the Filestore instance. If not set then the name parameter is used as an instance name. Useful when connecting multiple volumes from the same Filestore instance.
536
+
537
+ ### List attached storages
538
+
539
+ ```shell
540
+ python3 xpk.py storage list \
541
+ --project=$PROJECT --cluster $CLUSTER --zone=$ZONE
542
+ ```
543
+
544
+ ### Running workloads with storage
545
+
546
+ If you specified `--auto-mount=true` when creating or attaching a storage, then all workloads deployed on the cluster will have the volume attached by default. Otherwise, in order to have the storage attached, you have to add `--storage` parameter to `workload create` command:
547
+
548
+ ```shell
549
+ python3 xpk.py workload create \
550
+ --workload xpk-test-workload --command "echo goodbye" \
551
+ --project=$PROJECT --cluster=$CLUSTER --zone=$ZONE \
552
+ --tpu-type=v5litepod-16 --storage=test-storage
553
+ ```
554
+
555
+ ### Detaching storage
556
+
557
+ ```shell
558
+ python3 xpk.py storage detach $STORAGE_NAME \
559
+ --project=$PROJECT --cluster=$CLUSTER --zone=$ZONE
560
+ ```
561
+
562
+ ### Deleting storage
563
+
564
+ XPK allows you to remove Filestore instances easily with `xpk storage delete` command. **Warning:** this deletes all data contained in the Filestore!
565
+
566
+ ```shell
567
+ python3 xpk.py storage delete test-fs-instance \
568
+ --project=$PROJECT --cluster=$CLUSTER --zone=$ZONE
569
+ ```
570
+
571
+ ## Workload Create
572
+ * Workload Create (submit training job):
573
+
574
+ ```shell
575
+ python3 xpk.py workload create \
576
+ --workload xpk-test-workload --command "echo goodbye" \
577
+ --cluster xpk-test \
578
+ --tpu-type=v5litepod-16 --projet=$PROJECT
579
+ ```
580
+
581
+ * Workload Create for Pathways:
582
+ Pathways workload can be submitted using `workload create-pathways` on a Pathways enabled cluster (created with `cluster create-pathways`)
583
+
584
+ Pathways workload example:
585
+ ```shell
586
+ python3 xpk.py workload create-pathways \
587
+ --workload xpk-pw-test \
588
+ --num-slices=1 \
589
+ --tpu-type=v5litepod-16 \
590
+ --cluster xpk-pw-test \
591
+ --docker-name='user-workload' \
592
+ --docker-image=<maxtext docker image> \
593
+ --command='python3 MaxText/train.py MaxText/configs/base.yml base_output_directory=<output directory> dataset_path=<dataset path> per_device_batch_size=1 enable_checkpointing=false enable_profiler=false remat_policy=full global_parameter_scale=4 steps=300 max_target_length=2048 use_iota_embed=true reuse_example_batch=1 dataset_type=synthetic attention=flash gcs_metrics=True run_name=$(USER)-pw-xpk-test-1'
594
+ ```
595
+
596
+ Regular workload can also be submitted on a Pathways enabled cluster (created with `cluster create-pathways`)
597
+
598
+ Pathways workload example:
599
+ ```shell
600
+ python3 xpk.py workload create-pathways \
601
+ --workload xpk-regular-test \
602
+ --num-slices=1 \
603
+ --tpu-type=v5litepod-16 \
604
+ --cluster xpk-pw-test \
605
+ --docker-name='user-workload' \
606
+ --docker-image=<maxtext docker image> \
607
+ --command='python3 MaxText/train.py MaxText/configs/base.yml base_output_directory=<output directory> dataset_path=<dataset path> per_device_batch_size=1 enable_checkpointing=false enable_profiler=false remat_policy=full global_parameter_scale=4 steps=300 max_target_length=2048 use_iota_embed=true reuse_example_batch=1 dataset_type=synthetic attention=flash gcs_metrics=True run_name=$(USER)-pw-xpk-test-1'
608
+ ```
609
+
610
+ Pathways in headless mode - Pathways now offers the capability to run JAX workloads in Vertex AI notebooks or in GCE VMs!
611
+ Specify `--headless` with `workload create-pathways` when the user workload is not provided in a docker container.
612
+ ```shell
613
+ python3 xpk.py workload create-pathways --headless \
614
+ --workload xpk-pw-headless \
615
+ --num-slices=1 \
616
+ --tpu-type=v5litepod-16 \
617
+ --cluster xpk-pw-test
618
+ ```
619
+ Executing the command above would provide the address of the proxy that the user job should connect to.
620
+ ```shell
621
+ kubectl get pods
622
+ kubectl port-forward pod/<proxy-pod-name> 29000:29000
623
+ ```
624
+ ```shell
625
+ JAX_PLATFORMS=proxy JAX_BACKEND_TARGET=grpc://127.0.0.1:29000 python -c 'import pathwaysutils; import jax; print(jax.devices())'
626
+ ```
627
+ Specify `JAX_PLATFORMS=proxy` and `JAX_BACKEND_TARGET=<proxy address from above>` and `import pathwaysutils` to establish this connection between the user's JAX code and the Pathways proxy. Execute Pathways workloads interactively on Vertex AI notebooks!
628
+
629
+ ### Set `max-restarts` for production jobs
630
+
631
+ * `--max-restarts <value>`: By default, this is 0. This will restart the job ""
632
+ times when the job terminates. For production jobs, it is recommended to
633
+ increase this to a large number, say 50. Real jobs can be interrupted due to
634
+ hardware failures and software updates. We assume your job has implemented
635
+ checkpointing so the job restarts near where it was interrupted.
636
+
637
+ ### Workloads for A3-Ultra and A3-Mega clusters (GPU machines)
638
+ To submit jobs on a cluster with A3 machines, run the below command. To create a cluster with A3 machines see [here](#provisioning-a3-ultra-and-a3-mega-clusters-gpu-machines).
639
+ * For A3-Ultra: --device-type=h200-141gb-8
640
+ * For A3-Mega: --device-type=h100-mega-80gb-8
641
+
642
+ ```shell
643
+ python3 xpk.py workload create \
644
+ --workload=$WORKLOAD_NAME --command="echo goodbye" \
645
+ --cluster=$CLUSTER_NAME --device-type=h200-141gb-8 \
646
+ --zone=$COMPUTE_ZONE --project=$PROJECT_ID \
647
+ --num-nodes=$WOKRKLOAD_NUM_NODES
648
+ ```
649
+ > The docker image flags/arguments introduced in [workloads section](#workload-create) can be used with A3 machines as well.
650
+
651
+ In order to run NCCL test on A3 Ultra machines check out [this guide](/examples/nccl/nccl.md).
652
+
653
+ ### Workload Priority and Preemption
654
+ * Set the priority level of your workload with `--priority=LEVEL`
655
+
656
+ We have five priorities defined: [`very-low`, `low`, `medium`, `high`, `very-high`].
657
+ The default priority is `medium`.
658
+
659
+ Priority determines:
660
+
661
+ 1. Order of queued jobs.
662
+
663
+ Queued jobs are ordered by
664
+ `very-low` < `low` < `medium` < `high` < `very-high`
665
+
666
+ 2. Preemption of lower priority workloads.
667
+
668
+ A higher priority job will `evict` lower priority jobs.
669
+ Evicted jobs are brought back to the queue and will re-hydrate appropriately.
670
+
671
+ #### General Example:
672
+ ```shell
673
+ python3 xpk.py workload create \
674
+ --workload xpk-test-medium-workload --command "echo goodbye" --cluster \
675
+ xpk-test --tpu-type=v5litepod-16 --priority=medium
676
+ ```
677
+
678
+ ### Create Vertex AI Experiment to upload data to Vertex AI Tensorboard
679
+ *Note: This feature is available in XPK >= 0.4.0. Enable [Vertex AI API](https://cloud.google.com/vertex-ai/docs/start/cloud-environment#enable_vertexai_apis) in your Google Cloud console to use this feature. Make sure you have
680
+ [Vertex AI Administrator](https://cloud.google.com/vertex-ai/docs/general/access-control#aiplatform.admin) role
681
+ assigned to your user account and to the [Compute Engine Service account](https://cloud.google.com/compute/docs/access/service-accounts#default_service_account) attached to the node pools in the cluster.*
682
+
683
+ Vertex AI Experiment is a tool that helps to track and analyze an experiment run on Vertex AI Tensorboard. To learn more about Vertex AI Experiments, visit [this](https://cloud.google.com/vertex-ai/docs/experiments/intro-vertex-ai-experiments).
684
+
685
+ XPK will create a Vertex AI Experiment in `workload create` command and attach the Vertex AI Tensorboard created for the cluster during `cluster create`. If there is a cluster created before this feature is released, there will be no Vertex AI Tensorboard created for the cluster and `workload create` will fail. Re-run `cluster create` to create a Vertex AI Tensorboard and then run `workload create` again to schedule your workload.
686
+
687
+ * Create Vertex AI Experiment with default Experiment name:
688
+
689
+ ```shell
690
+ python3 xpk.py workload create \
691
+ --cluster xpk-test --workload xpk-workload \
692
+ --use-vertex-tensorboard
693
+ ```
694
+
695
+ will create a Vertex AI Experiment with the name `xpk-test-xpk-workload` (*<args.cluster>-<args.workload>*).
696
+
697
+ * Create Vertex AI Experiment with user-specified Experiment name:
698
+
699
+ ```shell
700
+ python3 xpk.py workload create \
701
+ --cluster xpk-test --workload xpk-workload \
702
+ --use-vertex-tensorboard --experiment-name=test-experiment
703
+ ```
704
+
705
+ will create a Vertex AI Experiment with the name `test-experiment`.
706
+
707
+ Check out [MaxText example](https://github.com/google/maxtext/pull/570) on how to update your workload to automatically upload logs collected in your Tensorboard directory to the Vertex AI Experiment created by `workload create`.
708
+
709
+ ## Workload Delete
710
+ * Workload Delete (delete training job):
711
+
712
+ ```shell
713
+ python3 xpk.py workload delete \
714
+ --workload xpk-test-workload --cluster xpk-test
715
+ ```
716
+
717
+ This will only delete `xpk-test-workload` workload in `xpk-test` cluster.
718
+
719
+ * Workload Delete (delete all training jobs in the cluster):
720
+
721
+ ```shell
722
+ python3 xpk.py workload delete \
723
+ --cluster xpk-test
724
+ ```
725
+
726
+ This will delete all the workloads in `xpk-test` cluster. Deletion will only begin if you type `y` or `yes` at the prompt. Multiple workload deletions are processed in batches for optimized processing.
727
+
728
+ * Workload Delete supports filtering. Delete a portion of jobs that match user criteria. Multiple workload deletions are processed in batches for optimized processing.
729
+ * Filter by Job: `filter-by-job`
730
+
731
+ ```shell
732
+ python3 xpk.py workload delete \
733
+ --cluster xpk-test --filter-by-job=$USER
734
+ ```
735
+
736
+ This will delete all the workloads in `xpk-test` cluster whose names start with `$USER`. Deletion will only begin if you type `y` or `yes` at the prompt.
737
+
738
+ * Filter by Status: `filter-by-status`
739
+
740
+ ```shell
741
+ python3 xpk.py workload delete \
742
+ --cluster xpk-test --filter-by-status=QUEUED
743
+ ```
744
+
745
+ This will delete all the workloads in `xpk-test` cluster that have the status as Admitted or Evicted, and the number of running VMs is 0. Deletion will only begin if you type `y` or `yes` at the prompt. Status can be: `EVERYTHING`,`FINISHED`, `RUNNING`, `QUEUED`, `FAILED`, `SUCCESSFUL`.
746
+
747
+ ## Workload List
748
+ * Workload List (see training jobs):
749
+
750
+ ```shell
751
+ python3 xpk.py workload list \
752
+ --cluster xpk-test
753
+ ```
754
+
755
+ * Example Workload List Output:
756
+
757
+ The below example shows four jobs of different statuses:
758
+
759
+ * `user-first-job-failed`: **filter-status** is `FINISHED` and `FAILED`.
760
+ * `user-second-job-success`: **filter-status** is `FINISHED` and `SUCCESSFUL`.
761
+ * `user-third-job-running`: **filter-status** is `RUNNING`.
762
+ * `user-forth-job-in-queue`: **filter-status** is `QUEUED`.
763
+ * `user-fifth-job-in-queue-preempted`: **filter-status** is `QUEUED`.
764
+
765
+ ```
766
+ Jobset Name Created Time Priority TPU VMs Needed TPU VMs Running/Ran TPU VMs Done Status Status Message Status Time
767
+ user-first-job-failed 2023-1-1T1:00:00Z medium 4 4 <none> Finished JobSet failed 2023-1-1T1:05:00Z
768
+ user-second-job-success 2023-1-1T1:10:00Z medium 4 4 4 Finished JobSet finished successfully 2023-1-1T1:14:00Z
769
+ user-third-job-running 2023-1-1T1:15:00Z medium 4 4 <none> Admitted Admitted by ClusterQueue cluster-queue 2023-1-1T1:16:00Z
770
+ user-forth-job-in-queue 2023-1-1T1:16:05Z medium 4 <none> <none> Admitted couldn't assign flavors to pod set slice-job: insufficient unused quota for google.com/tpu in flavor 2xv4-8, 4 more need 2023-1-1T1:16:10Z
771
+ user-fifth-job-preempted 2023-1-1T1:10:05Z low 4 <none> <none> Evicted Preempted to accommodate a higher priority Workload 2023-1-1T1:10:00Z
772
+ ```
773
+
774
+ * Workload List supports filtering. Observe a portion of jobs that match user criteria.
775
+
776
+ * Filter by Status: `filter-by-status`
777
+
778
+ Filter the workload list by the status of respective jobs.
779
+ Status can be: `EVERYTHING`,`FINISHED`, `RUNNING`, `QUEUED`, `FAILED`, `SUCCESSFUL`
780
+
781
+ * Filter by Job: `filter-by-job`
782
+
783
+ Filter the workload list by the name of a job.
784
+
785
+ ```shell
786
+ python3 xpk.py workload list \
787
+ --cluster xpk-test --filter-by-job=$USER
788
+ ```
789
+
790
+ * Workload List supports waiting for the completion of a specific job. XPK will follow an existing job until it has finished or the `timeout`, if provided, has been reached and then list the job. If no `timeout` is specified, the default value is set to the max value, 1 week. You may also set `timeout=0` to poll the job once.
791
+
792
+ Wait for a job to complete.
793
+
794
+ ```shell
795
+ python3 xpk.py workload list \
796
+ --cluster xpk-test --wait-for-job-completion=xpk-test-workload
797
+ ```
798
+
799
+ Wait for a job to complete with a timeout of 300 seconds.
800
+
801
+ ```shell
802
+ python3 xpk.py workload list \
803
+ --cluster xpk-test --wait-for-job-completion=xpk-test-workload \
804
+ --timeout=300
805
+ ```
806
+
807
+ Return codes
808
+ `0`: Workload finished and completed successfully.
809
+ `124`: Timeout was reached before workload finished.
810
+ `125`: Workload finished but did not complete successfully.
811
+ `1`: Other failure.
812
+
813
+ ## Job List
814
+
815
+ * Job List (see jobs submitted via batch command):
816
+
817
+ ```shell
818
+ python3 xpk.py job ls --cluster xpk-test
819
+ ```
820
+
821
+ * Example Job List Output:
822
+
823
+ ```
824
+ NAME PROFILE LOCAL QUEUE COMPLETIONS DURATION AGE
825
+ xpk-def-app-profile-slurm-74kbv xpk-def-app-profile 1/1 15s 17h
826
+ xpk-def-app-profile-slurm-brcsg xpk-def-app-profile 1/1 9s 3h56m
827
+ xpk-def-app-profile-slurm-kw99l xpk-def-app-profile 1/1 5s 3h54m
828
+ xpk-def-app-profile-slurm-x99nx xpk-def-app-profile 3/3 29s 17h
829
+ ```
830
+
831
+ ## Job Cancel
832
+
833
+ * Job Cancel (delete job submitted via batch command):
834
+
835
+ ```shell
836
+ python3 xpk.py job cancel xpk-def-app-profile-slurm-74kbv --cluster xpk-test
837
+ ```
838
+
839
+ ## Inspector
840
+ * Inspector provides debug info to understand cluster health, and why workloads are not running.
841
+ Inspector output is saved to a file.
842
+
843
+ ```shell
844
+ python3 xpk.py inspector \
845
+ --cluster $CLUSTER_NAME \
846
+ --project $PROJECT_ID \
847
+ --zone $ZONE
848
+ ```
849
+
850
+ * Optional Arguments
851
+ * `--print-to-terminal`:
852
+ Print command output to terminal as well as a file.
853
+ * `--workload $WORKLOAD_NAME`
854
+ Inspector will write debug info related to the workload:`$WORKLOAD_NAME`
855
+
856
+ * Example Output:
857
+
858
+ The output of xpk inspector is in `/tmp/tmp0pd6_k1o` in this example.
859
+ ```shell
860
+ [XPK] Starting xpk
861
+ [XPK] Task: `Set Cluster` succeeded.
862
+ [XPK] Task: `Local Setup: gcloud version` is implemented by `gcloud version`, hiding output unless there is an error.
863
+ [XPK] Task: `Local Setup: Project / Zone / Region` is implemented by `gcloud config get project; gcloud config get compute/zone; gcloud config get compute/region`, hiding output unless there is an error.
864
+ [XPK] Task: `GKE: Cluster Details` is implemented by `gcloud beta container clusters list --project $PROJECT --region $REGION | grep -e NAME -e $CLUSTER_NAME`, hiding output unless there is an error.
865
+ [XPK] Task: `GKE: Node pool Details` is implemented by `gcloud beta container node-pools list --cluster $CLUSTER_NAME --project=$PROJECT --region=$REGION`, hiding output unless there is an error.
866
+ [XPK] Task: `Kubectl: All Nodes` is implemented by `kubectl get node -o custom-columns='NODE_NAME:metadata.name, READY_STATUS:.status.conditions[?(@.type=="Ready")].status, NODEPOOL:metadata.labels.cloud\.google\.com/gke-nodepool'`, hiding output unless there is an error.
867
+ [XPK] Task: `Kubectl: Number of Nodes per Node Pool` is implemented by `kubectl get node -o custom-columns=':metadata.labels.cloud\.google\.com/gke-nodepool' | sort | uniq -c`, hiding output unless there is an error.
868
+ [XPK] Task: `Kubectl: Healthy Node Count Per Node Pool` is implemented by `kubectl get node -o custom-columns='NODE_NAME:metadata.name, READY_STATUS:.status.conditions[?(@.type=="Ready")].status, NODEPOOL:metadata.labels.cloud\.google\.com/gke-nodepool' | grep -w True | awk {'print $3'} | sort | uniq -c`, hiding output unless there is an error.
869
+ [XPK] Task: `Kueue: ClusterQueue Details` is implemented by `kubectl describe ClusterQueue cluster-queue`, hiding output unless there is an error.
870
+ [XPK] Task: `Kueue: LocalQueue Details` is implemented by `kubectl describe LocalQueue multislice-queue`, hiding output unless there is an error.
871
+ [XPK] Task: `Kueue: Kueue Deployment Details` is implemented by `kubectl describe Deployment kueue-controller-manager -n kueue-system`, hiding output unless there is an error.
872
+ [XPK] Task: `Jobset: Deployment Details` is implemented by `kubectl describe Deployment jobset-controller-manager -n jobset-system`, hiding output unless there is an error.
873
+ [XPK] Task: `Kueue Manager Logs` is implemented by `kubectl logs deployment/kueue-controller-manager -n kueue-system --tail=100 --prefix=True`, hiding output unless there is an error.
874
+ [XPK] Task: `Jobset Manager Logs` is implemented by `kubectl logs deployment/jobset-controller-manager -n jobset-system --tail=100 --prefix=True`, hiding output unless there is an error.
875
+ [XPK] Task: `List Jobs with filter-by-status=EVERYTHING with filter-by-jobs=None` is implemented by `kubectl get workloads -o=custom-columns="Jobset Name:.metadata.ownerReferences[0].name,Created Time:.metadata.creationTimestamp,Priority:.spec.priorityClassName,TPU VMs Needed:.spec.podSets[0].count,TPU VMs Running/Ran:.status.admission.podSetAssignments[-1].count,TPU VMs Done:.status.reclaimablePods[0].count,Status:.status.conditions[-1].type,Status Message:.status.conditions[-1].message,Status Time:.status.conditions[-1].lastTransitionTime" `, hiding output unless there is an error.
876
+ [XPK] Task: `List Jobs with filter-by-status=QUEUED with filter-by-jobs=None` is implemented by `kubectl get workloads -o=custom-columns="Jobset Name:.metadata.ownerReferences[0].name,Created Time:.metadata.creationTimestamp,Priority:.spec.priorityClassName,TPU VMs Needed:.spec.podSets[0].count,TPU VMs Running/Ran:.status.admission.podSetAssignments[-1].count,TPU VMs Done:.status.reclaimablePods[0].count,Status:.status.conditions[-1].type,Status Message:.status.conditions[-1].message,Status Time:.status.conditions[-1].lastTransitionTime" | awk -e 'NR == 1 || ($7 ~ "Admitted|Evicted|QuotaReserved" && ($5 ~ "<none>" || $5 == 0)) {print $0}' `, hiding output unless there is an error.
877
+ [XPK] Task: `List Jobs with filter-by-status=RUNNING with filter-by-jobs=None` is implemented by `kubectl get workloads -o=custom-columns="Jobset Name:.metadata.ownerReferences[0].name,Created Time:.metadata.creationTimestamp,Priority:.spec.priorityClassName,TPU VMs Needed:.spec.podSets[0].count,TPU VMs Running/Ran:.status.admission.podSetAssignments[-1].count,TPU VMs Done:.status.reclaimablePods[0].count,Status:.status.conditions[-1].type,Status Message:.status.conditions[-1].message,Status Time:.status.conditions[-1].lastTransitionTime" | awk -e 'NR == 1 || ($7 ~ "Admitted|Evicted" && $5 ~ /^[0-9]+$/ && $5 > 0) {print $0}' `, hiding output unless there is an error.
878
+ [XPK] Find xpk inspector output file: /tmp/tmp0pd6_k1o
879
+ [XPK] Exiting XPK cleanly
880
+ ```
881
+
882
+ ## Run
883
+ * `xpk run` lets you execute scripts on a cluster with ease. It automates task execution, handles interruptions, and streams job output to your console.
884
+
885
+ ```shell
886
+ python xpk.py run --kind-cluster -n 2 -t 0-2 examples/job.sh
887
+ ```
888
+
889
+ * Example Output:
890
+
891
+ ```shell
892
+ [XPK] Starting xpk
893
+ [XPK] Task: `get current-context` is implemented by `kubectl config current-context`, hiding output unless there is an error.
894
+ [XPK] No local cluster name specified. Using current-context `kind-kind`
895
+ [XPK] Task: `run task` is implemented by `kubectl kjob create slurm --profile xpk-def-app-profile --localqueue multislice-queue --wait --rm -- examples/job.sh --partition multislice-queue --ntasks 2 --time 0-2`. Streaming output and input live.
896
+ job.batch/xpk-def-app-profile-slurm-g4vr6 created
897
+ configmap/xpk-def-app-profile-slurm-g4vr6 created
898
+ service/xpk-def-app-profile-slurm-g4vr6 created
899
+ Starting log streaming for pod xpk-def-app-profile-slurm-g4vr6-1-4rmgk...
900
+ Now processing task ID: 3
901
+ Starting log streaming for pod xpk-def-app-profile-slurm-g4vr6-0-bg6dm...
902
+ Now processing task ID: 1
903
+ exit
904
+ exit
905
+ Now processing task ID: 2
906
+ exit
907
+ Job logs streaming finished.[XPK] Task: `run task` terminated with code `0`
908
+ [XPK] XPK Done.
909
+ ```
910
+
911
+ ## GPU usage
912
+
913
+ In order to use XPK for GPU, you can do so by using `device-type` flag.
914
+
915
+ * Cluster Create (provision reserved capacity):
916
+
917
+ ```shell
918
+ # Find your reservations
919
+ gcloud compute reservations list --project=$PROJECT_ID
920
+
921
+ # Run cluster create with reservation.
922
+ python3 xpk.py cluster create \
923
+ --cluster xpk-test --device-type=h100-80gb-8 \
924
+ --num-nodes=2 \
925
+ --reservation=$RESERVATION_ID
926
+ ```
927
+
928
+ * Cluster Delete (deprovision capacity):
929
+
930
+ ```shell
931
+ python3 xpk.py cluster delete \
932
+ --cluster xpk-test
933
+ ```
934
+
935
+ * Cluster List (see provisioned capacity):
936
+
937
+ ```shell
938
+ python3 xpk.py cluster list
939
+ ```
940
+
941
+ * Cluster Describe (see capacity):
942
+
943
+ ```shell
944
+ python3 xpk.py cluster describe \
945
+ --cluster xpk-test
946
+ ```
947
+
948
+
949
+ * Cluster Cacheimage (enables faster start times):
950
+
951
+ ```shell
952
+ python3 xpk.py cluster cacheimage \
953
+ --cluster xpk-test --docker-image gcr.io/your_docker_image \
954
+ --device-type=h100-80gb-8
955
+ ```
956
+
957
+
958
+ * [Install NVIDIA GPU device drivers](https://cloud.google.com/container-optimized-os/docs/how-to/run-gpus#install)
959
+ ```shell
960
+ # List available driver versions
961
+ gcloud compute ssh $NODE_NAME --command "sudo cos-extensions list"
962
+
963
+ # Install the default driver
964
+ gcloud compute ssh $NODE_NAME --command "sudo cos-extensions install gpu"
965
+ # OR install a specific version of the driver
966
+ gcloud compute ssh $NODE_NAME --command "sudo cos-extensions install gpu -- -version=DRIVER_VERSION"
967
+ ```
968
+
969
+ * Run a workload:
970
+
971
+ ```shell
972
+ # Submit a workload
973
+ python3 xpk.py workload create \
974
+ --cluster xpk-test --device-type h100-80gb-8 \
975
+ --workload xpk-test-workload \
976
+ --command="echo hello world"
977
+ ```
978
+
979
+ * Workload Delete (delete training job):
980
+
981
+ ```shell
982
+ python3 xpk.py workload delete \
983
+ --workload xpk-test-workload --cluster xpk-test
984
+ ```
985
+
986
+ This will only delete `xpk-test-workload` workload in `xpk-test` cluster.
987
+
988
+ * Workload Delete (delete all training jobs in the cluster):
989
+
990
+ ```shell
991
+ python3 xpk.py workload delete \
992
+ --cluster xpk-test
993
+ ```
994
+
995
+ This will delete all the workloads in `xpk-test` cluster. Deletion will only begin if you type `y` or `yes` at the prompt.
996
+
997
+ * Workload Delete supports filtering. Delete a portion of jobs that match user criteria.
998
+ * Filter by Job: `filter-by-job`
999
+
1000
+ ```shell
1001
+ python3 xpk.py workload delete \
1002
+ --cluster xpk-test --filter-by-job=$USER
1003
+ ```
1004
+
1005
+ This will delete all the workloads in `xpk-test` cluster whose names start with `$USER`. Deletion will only begin if you type `y` or `yes` at the prompt.
1006
+
1007
+ * Filter by Status: `filter-by-status`
1008
+
1009
+ ```shell
1010
+ python3 xpk.py workload delete \
1011
+ --cluster xpk-test --filter-by-status=QUEUED
1012
+ ```
1013
+
1014
+ This will delete all the workloads in `xpk-test` cluster that have the status as Admitted or Evicted, and the number of running VMs is 0. Deletion will only begin if you type `y` or `yes` at the prompt. Status can be: `EVERYTHING`,`FINISHED`, `RUNNING`, `QUEUED`, `FAILED`, `SUCCESSFUL`.
1015
+
1016
+ ## CPU usage
1017
+
1018
+ In order to use XPK for CPU, you can do so by using `device-type` flag.
1019
+
1020
+ * Cluster Create (provision on-demand capacity):
1021
+
1022
+ ```shell
1023
+ # Run cluster create with on demand capacity.
1024
+ python3 xpk.py cluster create \
1025
+ --cluster xpk-test \
1026
+ --device-type=n2-standard-32-256 \
1027
+ --num-slices=1 \
1028
+ --default-pool-cpu-machine-type=n2-standard-32 \
1029
+ --on-demand
1030
+ ```
1031
+ Note that `device-type` for CPUs is of the format <cpu-machine-type>-<number of VMs>, thus in the above example, user requests for 256 VMs of type n2-standard-32.
1032
+ Currently workloads using < 1000 VMs are supported.
1033
+
1034
+ * Run a workload:
1035
+
1036
+ ```shell
1037
+ # Submit a workload
1038
+ python3 xpk.py workload create \
1039
+ --cluster xpk-test \
1040
+ --num-slices=1 \
1041
+ --device-type=n2-standard-32-256 \
1042
+ --workload xpk-test-workload \
1043
+ --command="echo hello world"
1044
+ ```
1045
+
1046
+ # Autoprovisioning with XPK
1047
+ XPK can dynamically allocate cluster capacity using [Node Auto Provisioning, (NAP)](https://cloud.google.com/kubernetes-engine/docs/how-to/node-auto-provisioning#use_accelerators_for_new_auto-provisioned_node_pools) support.
1048
+
1049
+ Allow several topology sizes to be supported from one XPK cluster, and be dynamically provisioned based on incoming workload requests. XPK users will not need to re-provision the cluster manually.
1050
+
1051
+ Enabling autoprovisioning will take the cluster around initially up to **30 minutes to upgrade**.
1052
+
1053
+ ## Create a cluster with autoprovisioning:
1054
+
1055
+ Autoprovisioning will be enabled on the below cluster with [0, 8] chips of v4 TPU (up to 1xv4-16) to scale
1056
+ between.
1057
+
1058
+ XPK doesn't currently support different generations of accelerators in the same cluster (like v4 and v5p TPUs).
1059
+
1060
+ ```shell
1061
+ CLUSTER_NAME=my_cluster
1062
+ NUM_SLICES=2
1063
+ DEVICE_TYPE=v4-8
1064
+ RESERVATION=reservation_id
1065
+ PROJECT=my_project
1066
+ ZONE=us-east5-b
1067
+
1068
+ python3 xpk.py cluster create \
1069
+ --cluster $CLUSTER_NAME \
1070
+ --num-slices=$NUM_SLICES \
1071
+ --device-type=$DEVICE_TYPE \
1072
+ --zone=$ZONE \
1073
+ --project=$PROJECT \
1074
+ --reservation=$RESERVATION \
1075
+ --enable-autoprovisioning
1076
+ ```
1077
+
1078
+ 1. Define the starting accelerator configuration and capacity type.
1079
+
1080
+ ```shell
1081
+ --device-type=$DEVICE_TYPE \
1082
+ --num-slice=$NUM_SLICES
1083
+ ```
1084
+ 2. Optionally set custom `minimum` / `maximum` chips. NAP will rescale the cluster with `maximum` - `minimum` chips. By default, `maximum` is set to the current cluster configuration size, and `minimum` is set to 0. This allows NAP to rescale with all the resources.
1085
+
1086
+ ```shell
1087
+ --autoprovisioning-min-chips=$MIN_CHIPS \
1088
+ --autoprovisioning-max-chips=$MAX_CHIPS
1089
+ ```
1090
+
1091
+ 3. `FEATURE TO COME SOON:` Set the timeout period for when node pools will automatically be deleted
1092
+ if no incoming workloads are run. This is 10 minutes currently.
1093
+
1094
+ 4. `FEATURE TO COME:` Set the timeout period to infinity. This will keep the idle node pool configuration always running until updated by new workloads.
1095
+
1096
+ ### Update a cluster with autoprovisioning:
1097
+ ```shell
1098
+ CLUSTER_NAME=my_cluster
1099
+ NUM_SLICES=2
1100
+ DEVICE_TYPE=v4-8
1101
+ RESERVATION=reservation_id
1102
+ PROJECT=my_project
1103
+ ZONE=us-east5-b
1104
+
1105
+ python3 xpk.py cluster create \
1106
+ --cluster $CLUSTER_NAME \
1107
+ --num-slices=$NUM_SLICES \
1108
+ --device-type=$DEVICE_TYPE \
1109
+ --zone=$ZONE \
1110
+ --project=$PROJECT \
1111
+ --reservation=$RESERVATION \
1112
+ --enable-autoprovisioning
1113
+ ```
1114
+
1115
+ ### Update a previously autoprovisioned cluster with different amount of chips:
1116
+
1117
+ * Option 1: By creating a new cluster nodepool configuration.
1118
+
1119
+ ```shell
1120
+ CLUSTER_NAME=my_cluster
1121
+ NUM_SLICES=2
1122
+ DEVICE_TYPE=v4-16
1123
+ RESERVATION=reservation_id
1124
+ PROJECT=my_project
1125
+ ZONE=us-east5-b
1126
+
1127
+ # This will create 2x v4-16 node pools and set the max autoprovisioned chips to 16.
1128
+ python3 xpk.py cluster create \
1129
+ --cluster $CLUSTER_NAME \
1130
+ --num-slices=$NUM_SLICES \
1131
+ --device-type=$DEVICE_TYPE \
1132
+ --zone=$ZONE \
1133
+ --project=$PROJECT \
1134
+ --reservation=$RESERVATION \
1135
+ --enable-autoprovisioning
1136
+ ```
1137
+
1138
+ * Option 2: By increasing the `--autoprovisioning-max-chips`.
1139
+ ```shell
1140
+ CLUSTER_NAME=my_cluster
1141
+ NUM_SLICES=0
1142
+ DEVICE_TYPE=v4-16
1143
+ RESERVATION=reservation_id
1144
+ PROJECT=my_project
1145
+ ZONE=us-east5-b
1146
+
1147
+ # This will clear the node pools if they exist in the cluster and set the max autoprovisioned chips to 16
1148
+ python3 xpk.py cluster create \
1149
+ --cluster $CLUSTER_NAME \
1150
+ --num-slices=$NUM_SLICES \
1151
+ --device-type=$DEVICE_TYPE \
1152
+ --zone=$ZONE \
1153
+ --project=$PROJECT \
1154
+ --reservation=$RESERVATION \
1155
+ --enable-autoprovisioning \
1156
+ --autoprovisioning-max-chips 16
1157
+ ```
1158
+
1159
+ ## Run workloads on the cluster with autoprovisioning:
1160
+ Reconfigure the `--device-type` and `--num-slices`
1161
+ ```shell
1162
+ CLUSTER_NAME=my_cluster
1163
+ NUM_SLICES=2
1164
+ DEVICE_TYPE=v4-8
1165
+ NEW_RESERVATION=new_reservation_id
1166
+ PROJECT=my_project
1167
+ ZONE=us-east5-b
1168
+ # Create a 2x v4-8 TPU workload.
1169
+ python3 xpk.py workload create \
1170
+ --cluster $CLUSTER \
1171
+ --workload ${USER}-nap-${NUM_SLICES}x${DEVICE_TYPE}_$(date +%H-%M-%S) \
1172
+ --command "echo hello world from $NUM_SLICES $DEVICE_TYPE" \
1173
+ --device-type=$DEVICE_TYPE \
1174
+ --num-slices=$NUM_SLICES \
1175
+ --zone=$ZONE \
1176
+ --project=$PROJECT
1177
+
1178
+ NUM_SLICES=1
1179
+ DEVICE_TYPE=v4-16
1180
+
1181
+ # Create a 1x v4-16 TPU workload.
1182
+ python3 xpk.py workload create \
1183
+ --cluster $CLUSTER \
1184
+ --workload ${USER}-nap-${NUM_SLICES}x${DEVICE_TYPE}_$(date +%H-%M-%S) \
1185
+ --command "echo hello world from $NUM_SLICES $DEVICE_TYPE" \
1186
+ --device-type=$DEVICE_TYPE \
1187
+ --num-slices=$NUM_SLICES \
1188
+ --zone=$ZONE \
1189
+ --project=$PROJECT
1190
+
1191
+ # Use a different reservation from what the cluster was created with.
1192
+ python3 xpk.py workload create \
1193
+ --cluster $CLUSTER \
1194
+ --workload ${USER}-nap-${NUM_SLICES}x${DEVICE_TYPE}_$(date +%H-%M-%S) \
1195
+ --command "echo hello world from $NUM_SLICES $DEVICE_TYPE" \
1196
+ --device-type=$DEVICE_TYPE \
1197
+ --num-slices=$NUM_SLICES \
1198
+ --zone=$ZONE \
1199
+ --project=$PROJECT \
1200
+ --reservation=$NEW_RESERVATION
1201
+ ```
1202
+
1203
+ 1. (Optional) Define the capacity type. By default, the capacity type will
1204
+ match with what the cluster was created with.
1205
+
1206
+ ```shell
1207
+ --reservation=my-reservation-id | --on-demand | --spot
1208
+ ```
1209
+
1210
+ 2. Set the topology of your workload using --device-type.
1211
+
1212
+ ```shell
1213
+ NUM_SLICES=1
1214
+ DEVICE_TYPE=v4-8
1215
+ --device-type=$DEVICE_TYPE \
1216
+ --num-slices=$NUM_SLICES \
1217
+ ```
1218
+
1219
+
1220
+ # How to add docker images to a xpk workload
1221
+
1222
+ The default behavior is `xpk workload create` will layer the local directory (`--script-dir`) into
1223
+ the base docker image (`--base-docker-image`) and run the workload command.
1224
+ If you don't want this layering behavior, you can directly use `--docker-image`. Do not mix arguments from the two flows in the same command.
1225
+
1226
+ ## Recommended / Default Docker Flow: `--base-docker-image` and `--script-dir`
1227
+ This flow pulls the `--script-dir` into the `--base-docker-image` and runs the new docker image.
1228
+
1229
+ * The below arguments are optional by default. xpk will pull the local
1230
+ directory with a generic base docker image.
1231
+
1232
+ - `--base-docker-image` sets the base image that xpk will start with.
1233
+
1234
+ - `--script-dir` sets which directory to pull into the image. This defaults to the current working directory.
1235
+
1236
+ See `python3 xpk.py workload create --help` for more info.
1237
+
1238
+ * Example with defaults which pulls the local directory into the base image:
1239
+ ```shell
1240
+ echo -e '#!/bin/bash \n echo "Hello world from a test script!"' > test.sh
1241
+ python3 xpk.py workload create --cluster xpk-test \
1242
+ --workload xpk-test-workload-base-image --command "bash test.sh" \
1243
+ --tpu-type=v5litepod-16 --num-slices=1
1244
+ ```
1245
+
1246
+ * Recommended Flow For Normal Sized Jobs (fewer than 10k accelerators):
1247
+ ```shell
1248
+ python3 xpk.py workload create --cluster xpk-test \
1249
+ --workload xpk-test-workload-base-image --command "bash custom_script.sh" \
1250
+ --base-docker-image=gcr.io/your_dependencies_docker_image \
1251
+ --tpu-type=v5litepod-16 --num-slices=1
1252
+ ```
1253
+
1254
+ ## Optional Direct Docker Image Configuration: `--docker-image`
1255
+ If a user wants to directly set the docker image used and not layer in the
1256
+ current working directory, set `--docker-image` to the image to be use in the
1257
+ workload.
1258
+
1259
+ * Running with `--docker-image`:
1260
+ ```shell
1261
+ python3 xpk.py workload create --cluster xpk-test \
1262
+ --workload xpk-test-workload-base-image --command "bash test.sh" \
1263
+ --tpu-type=v5litepod-16 --num-slices=1 --docker-image=gcr.io/your_docker_image
1264
+ ```
1265
+
1266
+ * Recommended Flow For Large Sized Jobs (more than 10k accelerators):
1267
+ ```shell
1268
+ python3 xpk.py cluster cacheimage \
1269
+ --cluster xpk-test --docker-image gcr.io/your_docker_image
1270
+ # Run workload create with the same image.
1271
+ python3 xpk.py workload create --cluster xpk-test \
1272
+ --workload xpk-test-workload-base-image --command "bash test.sh" \
1273
+ --tpu-type=v5litepod-16 --num-slices=1 --docker-image=gcr.io/your_docker_image
1274
+ ```
1275
+
1276
+ # More advanced facts:
1277
+
1278
+ * Workload create has two mutually exclusive ways to override the environment of a workload:
1279
+ * a `--env` flag to specify each environment variable separately. The format is:
1280
+
1281
+ `--env VARIABLE1=value --env VARIABLE2=value`
1282
+
1283
+ * a `--env-file` flag to allow specifying the container's
1284
+ environment from a file. Usage is the same as Docker's
1285
+ [--env-file flag](https://docs.docker.com/engine/reference/commandline/run/#env)
1286
+
1287
+ Example Env File:
1288
+ ```shell
1289
+ LIBTPU_INIT_ARGS=--my-flag=true --performance=high
1290
+ MY_ENV_VAR=hello
1291
+ ```
1292
+
1293
+ * Workload create accepts a --debug-dump-gcs flag which is a path to GCS bucket.
1294
+ Passing this flag sets the XLA_FLAGS='--xla_dump_to=/tmp/xla_dump/' and uploads
1295
+ hlo dumps to the specified GCS bucket for each worker.
1296
+
1297
+ # Integration Test Workflows
1298
+ The repository code is tested through Github Workflows and Actions. Currently three kinds of tests are performed:
1299
+ * A nightly build that runs every 24 hours
1300
+ * A build that runs on push to `main` branch
1301
+ * A build that runs for every PR approval
1302
+
1303
+ More information is documented [here](https://github.com/google/xpk/tree/main/.github/workflows)
1304
+
1305
+ # Troubleshooting
1306
+
1307
+ ## `Invalid machine type` for CPUs.
1308
+ XPK will create a regional GKE cluster. If you see issues like
1309
+
1310
+ ```shell
1311
+ Invalid machine type e2-standard-32 in zone $ZONE_NAME
1312
+ ```
1313
+
1314
+ Please select a CPU type that exists in all zones in the region.
1315
+
1316
+ ```shell
1317
+ # Find CPU Types supported in zones.
1318
+ gcloud compute machine-types list --zones=$ZONE_LIST
1319
+ # Adjust default cpu machine type.
1320
+ python3 xpk.py cluster create --default-pool-cpu-machine-type=CPU_TYPE ...
1321
+ ```
1322
+
1323
+ ## Workload creation fails
1324
+
1325
+ Some XPK cluster configuration might be missing, if workload creation fails with the below error.
1326
+
1327
+ `[XPK] b'error: the server doesn\'t have a resource type "workloads"\n'`
1328
+
1329
+ Mitigate this error by re-running your `xpk.py cluster create ...` command, to refresh the cluster configurations.
1330
+
1331
+ ## Permission Issues: `requires one of ["permission_name"] permission(s)`.
1332
+
1333
+ 1) Determine the role needed based on the permission error:
1334
+
1335
+ ```shell
1336
+ # For example: `requires one of ["container.*"] permission(s)`
1337
+ # Add [Kubernetes Engine Admin](https://cloud.google.com/iam/docs/understanding-roles#kubernetes-engine-roles) to your user.
1338
+ ```
1339
+
1340
+ 2) Add the role to the user in your project.
1341
+
1342
+ Go to [iam-admin](https://console.cloud.google.com/iam-admin/) or use gcloud cli:
1343
+ ```shell
1344
+ PROJECT_ID=my-project-id
1345
+ CURRENT_GKE_USER=$(gcloud config get account)
1346
+ ROLE=roles/container.admin # container.admin is the role needed for Kubernetes Engine Admin
1347
+ gcloud projects add-iam-policy-binding $PROJECT_ID --member user:$CURRENT_GKE_USER --role=$ROLE
1348
+ ```
1349
+
1350
+ 3) Check the permissions are correct for the users.
1351
+
1352
+ Go to [iam-admin](https://console.cloud.google.com/iam-admin/) or use gcloud cli:
1353
+
1354
+ ```shell
1355
+ PROJECT_ID=my-project-id
1356
+ CURRENT_GKE_USER=$(gcloud config get account)
1357
+ gcloud projects get-iam-policy $PROJECT_ID --filter="bindings.members:$CURRENT_GKE_USER" --flatten="bindings[].members"
1358
+ ```
1359
+
1360
+ 4) Confirm you have logged in locally with the correct user.
1361
+
1362
+ ```shell
1363
+ gcloud auth login
1364
+ ```
1365
+
1366
+ ### Roles needed based on permission errors:
1367
+
1368
+ * `requires one of ["container.*"] permission(s)`
1369
+
1370
+ Add [Kubernetes Engine Admin](https://cloud.google.com/iam/docs/understanding-roles#kubernetes-engine-roles) to your user.
1371
+
1372
+ * `ERROR: (gcloud.monitoring.dashboards.list) User does not have permission to access projects instance (or it may not exist)`
1373
+
1374
+ Add [Monitoring Viewer](https://cloud.google.com/iam/docs/understanding-roles#monitoring.viewer) to your user.
1375
+
1376
+
1377
+ ## Reservation Troubleshooting:
1378
+
1379
+ ### How to determine your reservation and its size / utilization:
1380
+
1381
+ ```shell
1382
+ PROJECT_ID=my-project
1383
+ ZONE=us-east5-b
1384
+ RESERVATION=my-reservation-name
1385
+ # Find the reservations in your project
1386
+ gcloud beta compute reservations list --project=$PROJECT_ID
1387
+ # Find the tpu machine type and current utilization of a reservation.
1388
+ gcloud beta compute reservations describe $RESERVATION --project=$PROJECT_ID --zone=$ZONE
1389
+ ```
1390
+
1391
+ ## 403 error on workload create when using `--base-docker-image` flag
1392
+ You need authority to push to the registry from your local machine. Try running `gcloud auth configure-docker`.
1393
+ ## `Kubernetes API exception` - 404 error
1394
+ If error of this kind appeared after updating xpk version it's possible that you need to rerun `cluster create` command in order to update resource definitions.
1395
+
1396
+ # TPU Workload Debugging
1397
+
1398
+ ## Verbose Logging
1399
+ If you are having trouble with your workload, try setting the `--enable-debug-logs` when you schedule it. This will give you more detailed logs to help pinpoint the issue. For example:
1400
+ ```shell
1401
+ python3 xpk.py workload create \
1402
+ --cluster --workload xpk-test-workload \
1403
+ --command="echo hello world" --enable-debug-logs
1404
+ ```
1405
+ Please check [libtpu logging](https://cloud.google.com/tpu/docs/troubleshooting/trouble-tf#debug_logs) and [Tensorflow logging](https://deepreg.readthedocs.io/en/latest/docs/logging.html#tensorflow-logging) for more information about the flags that are enabled to get the logs.
1406
+
1407
+ ## Collect Stack Traces
1408
+ [cloud-tpu-diagnostics](https://pypi.org/project/cloud-tpu-diagnostics/) PyPI package can be used to generate stack traces for workloads running in GKE. This package dumps the Python traces when a fault such as segmentation fault, floating-point exception, or illegal operation exception occurs in the program. Additionally, it will also periodically collect stack traces to help you debug situations when the program is unresponsive. You must make the following changes in the docker image running in a Kubernetes main container to enable periodic stack trace collection.
1409
+ ```shell
1410
+ # main.py
1411
+
1412
+ from cloud_tpu_diagnostics import diagnostic
1413
+ from cloud_tpu_diagnostics.configuration import debug_configuration
1414
+ from cloud_tpu_diagnostics.configuration import diagnostic_configuration
1415
+ from cloud_tpu_diagnostics.configuration import stack_trace_configuration
1416
+
1417
+ stack_trace_config = stack_trace_configuration.StackTraceConfig(
1418
+ collect_stack_trace = True,
1419
+ stack_trace_to_cloud = True)
1420
+ debug_config = debug_configuration.DebugConfig(
1421
+ stack_trace_config = stack_trace_config)
1422
+ diagnostic_config = diagnostic_configuration.DiagnosticConfig(
1423
+ debug_config = debug_config)
1424
+
1425
+ with diagnostic.diagnose(diagnostic_config):
1426
+ main_method() # this is the main method to run
1427
+ ```
1428
+ This configuration will start collecting stack traces inside the `/tmp/debugging` directory on each Kubernetes Pod.
1429
+
1430
+ ### Explore Stack Traces
1431
+ To explore the stack traces collected in a temporary directory in Kubernetes Pod, you can run the following command to configure a sidecar container that will read the traces from `/tmp/debugging` directory.
1432
+ ```shell
1433
+ python3 xpk.py workload create \
1434
+ --workload xpk-test-workload --command "python3 main.py" --cluster \
1435
+ xpk-test --tpu-type=v5litepod-16 --deploy-stacktrace-sidecar
1436
+ ```
1437
+
1438
+ ### Get information about jobs, queues and resources.
1439
+
1440
+ To list available resources and queues use ```xpk info``` command. It allows to see localqueues and clusterqueues and check for available resources.
1441
+
1442
+ To see queues with usage and workload info use:
1443
+ ```shell
1444
+ python3 xpk.py info --cluster my-cluster
1445
+ ```
1446
+
1447
+ You can specify what kind of resources(clusterqueue or localqueue) you want to see using flags --clusterqueue or --localqueue.
1448
+ ```shell
1449
+ python3 xpk.py info --cluster my-cluster --localqueue
1450
+ ```
1451
+
1452
+ # Local testing with Kind
1453
+
1454
+ To facilitate development and testing locally, we have integrated support for testing with `kind`. This enables you to simulate a Kubernetes environment on your local machine.
1455
+
1456
+ ## Prerequisites
1457
+
1458
+ - Install kind on your local machine. Follow the official documentation here: [Kind Installation Guide.](https://kind.sigs.k8s.io/docs/user/quick-start#installation)
1459
+
1460
+ ## Usage
1461
+
1462
+ xpk interfaces seamlessly with kind to manage Kubernetes clusters locally, facilitating the orchestration and management of workloads. Below are the commands for managing clusters:
1463
+
1464
+ ### Cluster Create
1465
+ * Cluster create:
1466
+
1467
+ ```shell
1468
+ python3 xpk.py kind create \
1469
+ --cluster xpk-test
1470
+ ```
1471
+
1472
+ ### Cluster Delete
1473
+ * Cluster Delete:
1474
+
1475
+ ```shell
1476
+ python3 xpk.py kind delete \
1477
+ --cluster xpk-test
1478
+ ```
1479
+
1480
+ ### Cluster List
1481
+ * Cluster List:
1482
+
1483
+ ```shell
1484
+ python3 xpk.py kind list
1485
+ ```
1486
+
1487
+ ## Local Testing Basics
1488
+
1489
+ Local testing is available exclusively through the `batch` and `job` commands of xpk with the `--kind-cluster` flag. This allows you to simulate training jobs locally:
1490
+
1491
+ ```shell
1492
+ python xpk.py batch [other-options] --kind-cluster script
1493
+ ```
1494
+
1495
+ Please note that all other xpk subcommands are intended for use with cloud systems on Google Cloud Engine (GCE) and don't support local testing. This includes commands like cluster, info, inspector, etc.
1496
+
1497
+ # Other advanced usage
1498
+ [Use a Jupyter notebook to interact with a Cloud TPU cluster](xpk-notebooks.md)