Skip to content

Commit 5ee6a23

Browse files
authored
fix: Support multi-slice training and add experiment name (GoogleCloudPlatform#1161)
This change introduces enhanced multi-slice support for RL and SFT training workflows, improves experiment tracking with Vertex AI Tensorboard integration, and updates core utility functions and configuration defaults. The changes primarily focus on enabling more flexible distributed training, improving experiment reproducibility, and ensuring compatibility with the latest `xpk` tooling which fixed the version comparison issue.
1 parent ab51f36 commit 5ee6a23

5 files changed

Lines changed: 52 additions & 23 deletions

File tree

dags/post_training/maxtext_rl.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
training_config = test_config_util.RLTestConfig(
6767
cluster=XpkClusters.TPU_V5P_128_CLUSTER,
6868
accelerator="v5p-128",
69-
slices=[1], # Single slice for RL training
69+
slices=[1, 2], # Multi-slice support
7070
model_name="llama3.1-70b",
7171
base_dir=(
7272
f"{test_config_util.DEFAULT_BUCKET}/llama3.1-70b-Instruct/outputs"
@@ -99,6 +99,7 @@
9999
loss_algo=loss_algo,
100100
run_name=run_name,
101101
hf_token=HF_TOKEN_LLAMA3_1,
102+
num_slices=slice_num,
102103
)
103104

104105
with TaskGroup(
@@ -122,6 +123,8 @@
122123
test_owner=test_owner.JACKY_F,
123124
).run_model(
124125
use_pathways=True,
126+
use_vertex_tensorboard=True,
127+
experiment_name=loss_algo.value,
125128
xpk_branch=MAIN_BRANCH,
126129
)
127130

dags/post_training/maxtext_sft.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def run_training(
4949
test_owner=test_owner.JACKY_F,
5050
).run_model(
5151
use_pathways=True,
52+
use_vertex_tensorboard=True,
53+
experiment_name="sft",
5254
xpk_branch=MAIN_BRANCH,
5355
)
5456

@@ -128,7 +130,7 @@ def validate_training(
128130
training_config = test_config_util.SFTTestConfig(
129131
cluster=XpkClusters.TPU_V5P_128_CLUSTER,
130132
accelerator="v5p-128",
131-
slices=[1], # Single slice for SFT training
133+
slices=[2],
132134
model_name="llama3.1-70b",
133135
steps=training_steps,
134136
short_id="msft",

dags/post_training/util/test_config_util.py

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,40 +107,56 @@ def __init__(
107107
self.rl_config_path = rl_config_path
108108

109109
def generate_rl_training_command(
110-
self, loss_algo: LossAlgo, run_name: str, hf_token: str
110+
self,
111+
loss_algo: LossAlgo,
112+
run_name: str,
113+
hf_token: str,
114+
num_slices: int = 1,
111115
) -> tuple[str]:
112-
"""Generates the RL training command as a tuple for GKE compatibility.
116+
"""Generates the RL training command as a tuple for GKE compatibility."""
117+
command_params = [
118+
f"run_name={run_name}",
119+
f"model_name={self.model_name}",
120+
f"tokenizer_path={self.tokenizer_path}",
121+
f"load_parameters_path={self.load_parameters_path}",
122+
f"base_output_directory={self.base_dir}",
123+
f"rl.loss_algo={loss_algo.loss_name}",
124+
]
113125

114-
Args:
115-
loss_algo: The loss algorithm to use (e.g., LossAlgo.GRPO).
116-
run_name: The run name for the training job.
117-
hf_token: The HuggingFace token for authentication.
126+
num_trainer = 1
127+
num_samplers = max(1, num_slices - num_trainer)
128+
129+
if num_slices > 1:
130+
command_params.extend([
131+
f"num_trainer_slices={num_trainer}",
132+
f"num_samplers_slices={num_samplers}",
133+
f"rollout_data_parallelism={num_samplers * 2}",
134+
])
118135

119-
Returns:
120-
A tuple containing the RL training command string.
121-
"""
122136
rl_command = (
123137
"python -m src.MaxText.rl.train_rl "
124-
f"{self.rl_config_path} run_name={run_name} "
125-
f"model_name={self.model_name} "
126-
f"tokenizer_path={self.tokenizer_path} "
127-
f"load_parameters_path={self.load_parameters_path} "
128-
f"base_output_directory={self.base_dir} "
129-
f"rl.loss_algo={loss_algo.loss_name}"
138+
f"{self.rl_config_path} " + " ".join(command_params)
130139
)
131-
command = " && ".join([
140+
141+
environment_variables = [
132142
f"export HF_TOKEN={hf_token}",
133143
"export TPU_MIN_LOG_LEVEL=0",
134144
"export TF_CPP_MIN_LOG_LEVEL=0",
135145
"export TPU_STDERR_LOG_LEVEL=0",
136146
"export JAX_PLATFORMS=proxy,cpu",
137147
"export JAX_BACKEND_TARGET=grpc://127.0.0.1:29000",
138148
"export ENABLE_PATHWAYS_PERSISTENCE='1'",
139-
rl_command,
140-
])
149+
]
141150

142-
# Return as tuple for k8s yaml compatibility.
143-
return (command,)
151+
if num_slices > 1:
152+
environment_variables.extend([
153+
f"export NUM_SLICES={num_samplers}",
154+
"export JAX_RANDOM_WEIGHTS=true",
155+
"export VLLM_ENABLE_V1_MULTIPROCESSING=0",
156+
])
157+
158+
full_command = " && ".join(environment_variables + [rl_command])
159+
return (full_command,)
144160

145161

146162
@dataclass

xlml/apis/task.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ def run_model(
699699
self,
700700
gcs_location: Optional[airflow.XComArg] = None,
701701
use_vertex_tensorboard: bool = False,
702+
experiment_name: str = "",
702703
use_pathways: bool = False,
703704
ramdisk_directory: str = "",
704705
mtc_enabled: bool = False,
@@ -711,6 +712,7 @@ def run_model(
711712
gcs_location: GCS path for all artifacts of the test.
712713
use_vertex_tensorboard: Set to True to view workload data on
713714
Vertex AI Tensorboard.
715+
experiment_name: The name of the experiment for Vertex AI Tensorboard.
714716
715717
Returns:
716718
A DAG node that executes the model test.
@@ -728,6 +730,7 @@ def run_model(
728730
workload_id,
729731
gcs_path,
730732
use_vertex_tensorboard,
733+
experiment_name,
731734
use_pathways,
732735
ramdisk_directory,
733736
mtc_enabled,
@@ -764,6 +767,7 @@ def launch_workload(
764767
workload_id: str,
765768
gcs_path: str,
766769
use_vertex_tensorboard: bool,
770+
experiment_name: str = "",
767771
use_pathways: bool = False,
768772
ramdisk_directory: str = "",
769773
mtc_enabled: bool = False,
@@ -787,6 +791,7 @@ def launch_workload(
787791
run_cmds=self.task_test_config.test_script,
788792
num_slices=self.task_test_config.num_slices,
789793
use_vertex_tensorboard=use_vertex_tensorboard,
794+
experiment_name=experiment_name,
790795
use_pathways=use_pathways,
791796
ramdisk_directory=ramdisk_directory,
792797
mtc_enabled=mtc_enabled,

xlml/utils/xpk.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
# NOTE: This version needs to be pinned to ensure compatibility when using
3535
# xpk.py for workload creation.
36-
MAIN_BRANCH = "v0.17.3"
36+
MAIN_BRANCH = "v1.1.2"
3737

3838
# Duration = past 7 days
3939
LOGGING_URL_FORMAT = (
@@ -105,6 +105,7 @@ def run_workload(
105105
run_cmds: str,
106106
num_slices: int = 1,
107107
use_vertex_tensorboard: bool = False,
108+
experiment_name: str = "",
108109
use_pathways: bool = False,
109110
# Directory for enabling emergency checkpointing
110111
ramdisk_directory: str = "",
@@ -179,6 +180,8 @@ def run_workload(
179180
workload_create_cmd += " --scheduler=gke.io/topology-aware-auto"
180181
if use_vertex_tensorboard:
181182
workload_create_cmd += " --use-vertex-tensorboard"
183+
if experiment_name:
184+
workload_create_cmd += f" --experiment-name={experiment_name}"
182185
vertex_ai_dependency = (
183186
"pip install -U google-cloud-aiplatform cloud-accelerator-diagnostics"
184187
)

0 commit comments

Comments
 (0)