Skip to content

Commit c88f116

Browse files
committed
fix: require a shared run ID for multi-node launch
- add torchrun-style --rdzv_id support - use the shared ID to isolate CCL unique-ID files - preserve automatic run ID generation for single-node runs - document rdzv_id in the multi-node example
1 parent ec68923 commit c88f116

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ The following examples demonstrate **LLaMA 3 supervised fine-tuning (SFT)** usin
123123
--nproc_per_node=1 \
124124
--node_rank=[rank_id] \
125125
--rdzv_endpoint=[master_addr]:29500 \
126+
--rdzv_id=[job_id] \
126127
./llama3 \
127128
--device cuda \
128129
--input_bin [training_data_path] \

tools/infini_run/infini_run.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ DEFINE_int32(nproc_per_node, 1, "Number of processes per node");
1919
DEFINE_int32(node_rank, 0, "Rank of this node");
2020
DEFINE_string(rdzv_endpoint, "127.0.0.1:29500", "Rendezvous endpoint (host:port)");
2121

22+
DEFINE_string(rdzv_id, "", "Unique job ID shared by all nodes");
23+
2224
namespace {
2325

2426
bool IsLauncherFlag(const std::string &flag) {
25-
return flag == "--nnodes" || flag == "--nproc_per_node" || flag == "--node_rank" || flag == "--rdzv_endpoint";
27+
return flag == "--nnodes" || flag == "--nproc_per_node" || flag == "--node_rank" || flag == "--rdzv_endpoint"
28+
|| flag == "--rdzv_id";
2629
}
2730

2831
int FindTrainProgramIndex(int argc, char **argv) {
@@ -106,6 +109,8 @@ int main(int argc, char **argv) {
106109
CHECK_GT(FLAGS_nnodes, 0) << "nnodes must be positive";
107110
CHECK_GT(FLAGS_nproc_per_node, 0) << "nproc_per_node must be positive";
108111
CHECK_NE(FLAGS_rdzv_endpoint.find(':'), std::string::npos) << "rdzv_endpoint must be host:port";
112+
CHECK(FLAGS_nnodes == 1 || !FLAGS_rdzv_id.empty())
113+
<< "rdzv_id must be set to the same unique job ID on every node for multi-node training";
109114

110115
CHECK_LT(train_program_index, argc) << "No training program specified!";
111116

@@ -119,7 +124,7 @@ int main(int argc, char **argv) {
119124
int proc_world_size = FLAGS_nnodes * FLAGS_nproc_per_node;
120125
std::string master_addr = FLAGS_rdzv_endpoint.substr(0, FLAGS_rdzv_endpoint.find(':'));
121126
std::string master_port = FLAGS_rdzv_endpoint.substr(FLAGS_rdzv_endpoint.find(':') + 1);
122-
const std::string run_id = FLAGS_nnodes == 1 ? GenerateLocalRunId() : "";
127+
const std::string run_id = FLAGS_rdzv_id.empty() ? GenerateLocalRunId() : FLAGS_rdzv_id;
123128

124129
std::unordered_set<pid_t> running_children;
125130
int exit_code = 0;
@@ -138,9 +143,7 @@ int main(int argc, char **argv) {
138143

139144
setenv("MASTER_ADDR", master_addr.c_str(), 1);
140145
setenv("MASTER_PORT", master_port.c_str(), 1);
141-
if (!run_id.empty()) {
142-
setenv("INFINI_RUN_ID", run_id.c_str(), 1);
143-
}
146+
setenv("INFINI_RUN_ID", run_id.c_str(), 1);
144147

145148
SetEnvInt("RANK", global_proc_rank);
146149
SetEnvInt("LOCAL_RANK", local_proc_rank);
@@ -177,7 +180,7 @@ int main(int argc, char **argv) {
177180
}
178181
}
179182

180-
if (!run_id.empty()) {
183+
if (FLAGS_nnodes == 1) {
181184
CleanupRunUniqueIdFiles(run_id);
182185
}
183186
return exit_code;

0 commit comments

Comments
 (0)