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