Skip to content

Commit f8dcddc

Browse files
committed
Add MaxText Llama 3.1 70B training with GCS recipe
1 parent af2a7cd commit f8dcddc

File tree

5 files changed

+287
-0
lines changed

5 files changed

+287
-0
lines changed
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# Instructions for training Llama3.1-70B-MaxText on TPU trillium (v6e-256) with Google Cloud Storage (GCS)
2+
3+
## GCS Bucket setup
4+
1. Create a bucket with a dataset for dataloading and a bucket to write checkpoints. To create a regional HNS bucket use the following command:
5+
```
6+
# Set variables
7+
export DATASET_BUCKET="your-dataloading-bucket-name"
8+
export CHECKPOINT_BUCKET="your-checkpoint-bucket-name"
9+
export REGION="us-central1"
10+
11+
# Create dataset bucket
12+
gcloud storage buckets create gs://${DATASET_BUCKET} --location=${REGION} --default-storage-class=Standard --enable-hierarchical-namespace --uniform-bucket-level-access
13+
14+
# Create checkpoint bucket
15+
gcloud storage buckets create gs://${CHECKPOINT_BUCKET} --location=${REGION} --default-storage-class=Standard --enable-hierarchical-namespace --uniform-bucket-level-access
16+
```
17+
Replace the following values:
18+
- `<DATASET_BUCKET>`:the name of your Cloud Storage bucket with training dataset. Do not include the gs:// prefix
19+
- `<CHECKPOINT_BUCKET>`: the name of your Cloud Storage bucket where checkpoints will written. Do not include the gs:// prefix
20+
- `<DATASET_STORAGE_NAME>`: name of the XPK storage for dataset bucket
21+
- `<CHECKPOINT_STORAGE_NAME>`: name of the XPK storage for checkpoint bucket
22+
- `<REGION>`: the region where your cluster is located ([available locations](https://cloud.google.com/storage/docs/locations#location-r))
23+
24+
2. Follow these [instructions](https://github.com/AI-Hypercomputer/maxtext/blob/b93beba652db6b3f4e6c82dc48a83b03229f5d3a/getting_started/Data_Input_Pipeline.md#tfds-pipeline) to download the Allenai c4 dataset which is used in this recipe.
25+
Then follow these [instructions](https://github.com/google/array_record/tree/main/beam) to convert the dataset into ArrayRecord.
26+
27+
## XPK setup
28+
1. Please follow this [link](https://github.com/AI-Hypercomputer/tpu-recipes/blob/main/training/trillium/XPK_README.md) to create your GKE cluster with XPK.
29+
2. GCSFuse 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. It adds pv and pvc to the cluster
30+
https://github.com/AI-Hypercomputer/xpk?tab=readme-ov-file#storage. You'll need to use the below commands to create XPK storage resources for both the dataset and checkpoint buckets in order to mount them to the MaxText workload using GCSFuse.
31+
```
32+
33+
export PROJECT="your-gcp-project" # Update
34+
export CLUSTER="your-xpk-cluster" # Update
35+
export ZONE="your-cluster-zone" # Update
36+
export OUTPUT_DIR="checkpointing-mount-point" # Update
37+
export RECIPE_REPO="path-to-this-recipe-repo" # Update
38+
39+
cd ~/xpk
40+
41+
python3 xpk.py storage attach $DATASET_STORAGE_NAME type=gcsfuse project=$PROJECT cluster=$CLUSTER zone=$ZONE mountpoint=/tmp/dataset readonly=false bucket=$DATASET_BUCKET size=64 automount=false manifest=$RECIPE_REPO/tpu-recipes/training/trillium/Llama3.1-70B-MaxText-with-Storage/dataset_pvc.yaml
42+
43+
python3 xpk.py storage attach $CHECKPOINT_STORAGE_NAME type=gcsfuse project=$PROJECT cluster=$CLUSTER zone=$ZONE mountpoint=/tmp/ckpt readonly=false bucket=$CHECKPOINT_BUCKET size=64 automount=false manifest=$RECIPE_REPO/tpu-recipes/training/trillium/Llama3.1-70B-MaxText-with-Storage/checkpoint_pvc.yaml
44+
```
45+
For the dataset bucket and checkpoint bucket use separate manifest files `checkpoint_pvc.yaml` and `dataset_pvc.yaml` from this repo.
46+
Creating a bucket and xpk storage is a one time setup.
47+
48+
## Prep for MaxText
49+
50+
### Install MaxText and Build Docker Image
51+
Please follow this [link](https://github.com/AI-Hypercomputer/tpu-recipes/blob/main/training/trillium/MAXTEXT_README.md) to install maxtext and build the docker image.
52+
53+
In step 2, use the jax-stable-stack image containing JAX 0.5.2:
54+
```
55+
BASE_IMAGE=us-docker.pkg.dev/cloud-tpu-images/jax-stable-stack/tpu:jax0.5.2-rev1
56+
bash docker_build_dependency_image.sh DEVICE=tpu MODE=stable_stack BASEIMAGE=${BASE_IMAGE}
57+
```
58+
59+
## Run MaxText Llama3.1-70B workloads on GKE
60+
61+
### Starting workload
62+
63+
From the MaxText root directory, start your Llama3.1-70B workload.
64+
65+
Run MaxText Llama 3.1 70B with synthetic data and no checkpointing:
66+
```
67+
python3 benchmarks/benchmark_runner.py xpk \
68+
project=$PROJECT \
69+
zone=$ZONE \
70+
device_type=v6e-256 \
71+
num_slices=1 \
72+
cluster_name=$CLUSTER \
73+
base_output_directory=$OUTPUT_DIR \
74+
model_name="llama3_1_70b_8192_synthetic" \
75+
num_steps=100 \
76+
base_docker_image=maxtext_base_image
77+
```
78+
79+
Run MaxText Llama 3.1 70B with checkpointing and loading real data from GCS:
80+
```
81+
python3 benchmarks/benchmark_runner.py xpk \
82+
project=$PROJECT \
83+
zone=$ZONE \
84+
device_type=v6e-256 \
85+
num_slices=1 \
86+
cluster_name=${CLUSTER} \
87+
base_output_directory=/tmp/ckpt \
88+
model_name="llama3_1_70b_8192_rd_ckpt_grain" \
89+
num_steps=100 \
90+
base_docker_image=maxtext_base_image \
91+
xpk_storage=$DATASET_STORAGE_NAME xpk_storage=$CHECKPOINT_STORAGE_NAME
92+
```
93+
94+
If you would like to run on multiple slices of v6e-256, you may modify the `--num_slices` flag.
95+
96+
### Workload Details
97+
98+
For reference, here are the `llama3_1_70b_8192_synthetic` and `llama3_1_70b_8192_rd_ckpt_grain` workload details:
99+
100+
```
101+
MaxTextModel(
102+
model_name="llama3_1-70b-8192",
103+
model_type="llama3.1-70b",
104+
tuning_params={
105+
"per_device_batch_size": 4,
106+
"ici_fsdp_parallelism": -1,
107+
"remat_policy": "custom",
108+
"decoder_layer_input": "offload",
109+
"query_proj": "offload",
110+
"key_proj": "offload",
111+
"value_proj": "offload",
112+
"max_target_length": 8192,
113+
"attention": "flash",
114+
"use_iota_embed": True,
115+
"dataset_path": "gs://max-datasets-rogue",
116+
"dataset_type": "synthetic",
117+
"enable_checkpointing": False,
118+
"sa_block_q": 2048,
119+
"sa_block_kv": 2048,
120+
"sa_block_kv_compute": 2048,
121+
"sa_block_q_dkv": 2048,
122+
"sa_block_kv_dkv": 2048,
123+
"sa_block_kv_dkv_compute": 2048,
124+
"sa_block_q_dq": 2048,
125+
"sa_block_kv_dq": 2048,
126+
"sa_use_fused_bwd_kernel": True,
127+
"profiler": "xplane",
128+
"skip_first_n_steps_for_profiler": 10,
129+
"profiler_steps": 5,
130+
},
131+
xla_flags=(
132+
xla_flags_library.DENSE_VMEM_LIMIT_FLAG
133+
+ xla_flags_library.LAYOUT_FOR_ALL_REDUCE_SCATTER
134+
+ xla_flags_library.DATA_PARALLEL_OVERLAP
135+
+ xla_flags_library.CF_FOR_ALL_GATHER
136+
+ xla_flags_library.HOST_OFFLOAD_FLAGS
137+
),
138+
)
139+
140+
141+
MaxTextModel(
142+
model_name="llama3_1_70b_8192_rd_ckpt_grain",
143+
model_type="llama3.1-70b",
144+
tuning_params={
145+
"per_device_batch_size": 2,
146+
"ici_fsdp_parallelism": -1,
147+
"remat_policy": "custom",
148+
"decoder_layer_input": "offload",
149+
"query_proj": "offload",
150+
"key_proj": "offload",
151+
"value_proj": "offload",
152+
"max_target_length": 8192,
153+
"attention": "flash",
154+
"use_iota_embed": True,
155+
"dataset_path": "/tmp/dataset",
156+
"dataset_type": "grain",
157+
"grain_train_files": "/tmp/dataset/array-record/c4/en/3.0.1/c4-train.array_record*",
158+
"grain_worker_count": 24,
159+
"enable_checkpointing": True,
160+
"async_checkpointing": True,
161+
"checkpoint_period": 20,
162+
"sa_block_q": 2048,
163+
"sa_block_kv": 2048,
164+
"sa_block_kv_compute": 2048,
165+
"sa_block_q_dkv": 2048,
166+
"sa_block_kv_dkv": 2048,
167+
"sa_block_kv_dkv_compute": 2048,
168+
"sa_block_q_dq": 2048,
169+
"sa_block_kv_dq": 2048,
170+
"sa_use_fused_bwd_kernel": True,
171+
},
172+
xla_flags=(
173+
xla_flags_library.DENSE_VMEM_LIMIT_FLAG
174+
+ xla_flags_library.LAYOUT_FOR_ALL_REDUCE_SCATTER
175+
+ xla_flags_library.DATA_PARALLEL_OVERLAP
176+
+ xla_flags_library.CF_FOR_ALL_GATHER
177+
+ xla_flags_library.HOST_OFFLOAD_FLAGS
178+
+ xla_flags_library.ENABLE_SPARSECORE_OFFLOADING_FOR_ALL_REDUCE
179+
+ " --xla_tpu_iova_dma_chunk_size_bytes=104857"
180+
),
181+
)
182+
```
183+
184+
This equivalent workload code can be found in the [maxtext_trillium_model_configs.py](https://github.com/AI-Hypercomputer/maxtext/blob/1e4d513ad70dd4074d975a9f7936295008d4b900/benchmarks/maxtext_trillium_model_configs.py#L1103-L1146) file within the MaxText repository.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apiVersion: v1
2+
kind: PersistentVolume
3+
metadata:
4+
name: checkpoint-bucket-pv
5+
spec:
6+
accessModes:
7+
- ReadWriteMany
8+
capacity:
9+
storage: 64Gi
10+
persistentVolumeReclaimPolicy: Retain
11+
storageClassName: gcsfuse-sc # dummy storage class
12+
claimRef:
13+
namespace: default
14+
name: checkpoint-bucket-pvc
15+
mountOptions:
16+
- metadata-cache:ttl-secs:-1
17+
- metadata-cache:negative-ttl-secs:0
18+
- metadata-cache:stat-cache-max-size-mb:-1
19+
- metadata-cache:type-cache-max-size-mb:-1
20+
- file-cache:enable-parallel-downloads:false
21+
- file-system:kernel-list-cache-ttl-secs:0
22+
- write:enable-streaming-writes:true
23+
- file-system:precondition-errors:false
24+
csi:
25+
driver: gcsfuse.csi.storage.gke.io
26+
volumeHandle: your-trillium-chkpt # unique bucket name
27+
volumeAttributes:
28+
gcsfuseMetadataPrefetchOnMount: "true"
29+
---
30+
apiVersion: v1
31+
kind: PersistentVolumeClaim
32+
metadata:
33+
name: checkpoint-bucket-pvc
34+
namespace: defaultls
35+
spec:
36+
accessModes:
37+
- ReadWriteMany
38+
resources:
39+
requests:
40+
storage: 64Gi
41+
volumeName: checkpoint-bucket-pv
42+
storageClassName: gcsfuse-sc # dummy storage class
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: v1
2+
kind: PersistentVolume
3+
metadata:
4+
name: dataset-bucket-pv
5+
spec:
6+
accessModes:
7+
- ReadWriteMany
8+
capacity:
9+
storage: 64Gi
10+
persistentVolumeReclaimPolicy: Retain
11+
storageClassName: gcsfuse-sc # dummy storage class
12+
claimRef:
13+
namespace: default
14+
name: dataset-bucket-pvc
15+
mountOptions:
16+
- metadata-cache:ttl-secs:-1
17+
- metadata-cache:stat-cache-max-size-mb:-1
18+
- metadata-cache:type-cache-max-size-mb:-1
19+
- file-cache:enable-parallel-downloads:false
20+
- file-system:kernel-list-cache-ttl-secs:-1
21+
- write:enable-streaming-writes:true
22+
csi:
23+
driver: gcsfuse.csi.storage.gke.io
24+
volumeHandle: your-trillium-dataloading # unique bucket name
25+
volumeAttributes:
26+
gcsfuseMetadataPrefetchOnMount: "true"
27+
---
28+
apiVersion: v1
29+
kind: PersistentVolumeClaim
30+
metadata:
31+
name: dataset-bucket-pvc
32+
namespace: default
33+
spec:
34+
accessModes:
35+
- ReadWriteMany
36+
resources:
37+
requests:
38+
storage: 64Gi
39+
volumeName: dataset-bucket-pv
40+
storageClassName: gcsfuse-sc # dummy storage class
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
python3 benchmarks/benchmark_runner.py xpk \
2+
project=$PROJECT \
3+
zone=$ZONE \
4+
device_type=v6e-256 \
5+
num_slices=1 \
6+
cluster_name=${CLUSTER} \
7+
base_output_directory=/tmp/ckpt \
8+
model_name="llama3_1_70b_8192_rd_ckpt_grain" \
9+
num_steps=100 \
10+
base_docker_image=maxtext_base_image \
11+
xpk_storage="yourdatasetbucket" xpk_storage="yourckptbucket"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
python3 benchmarks/benchmark_runner.py xpk \
2+
project=$PROJECT \
3+
zone=$ZONE \
4+
device_type=v6e-256 \
5+
num_slices=1 \
6+
cluster_name=$CLUSTER \
7+
base_output_directory=$OUTPUT_DIR \
8+
model_name="llama3_1_70b_8192_synthetic" \
9+
num_steps=100 \
10+
base_docker_image=maxtext_base_image

0 commit comments

Comments
 (0)