-
Notifications
You must be signed in to change notification settings - Fork 51
Support torchrun-style InfiniTrain multi-process launch #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chen2021673
wants to merge
6
commits into
master
Choose a base branch
from
8_proc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
de24af9
Support torchrun-style InfiniTrain multi-process launch
chen2021673 08d684d
test: add basic 8-process config group
chen2021673 b29714f
fix: stabilize distributed training resume flow
chen2021673 ec68923
fix: correct distributed rank and unique ID handling
chen2021673 c88f116
fix: require a shared run ID for multi-node launch
chen2021673 2463ca5
fix: separate launcher args from model test args
chen2021673 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,7 @@ inline int GetNprocPerNode() { return GlobalEnv::Instance().nproc_per_node(); } | |
| inline int GetNthreadPerProc() { return GlobalEnv::Instance().nthread_per_process(); } | ||
| inline int GetGlobalProcRank() { return GlobalEnv::Instance().global_proc_rank(); } | ||
| inline int GetLocalProcRank() { return GlobalEnv::Instance().local_proc_rank(); } | ||
| inline int GetLocalDeviceIndex(int thread_rank = 0) { return GetLocalProcRank() * GetNthreadPerProc() + thread_rank; } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. device index 本身就特指节点内的设备编号,是不是没必要强调 local 了; |
||
|
|
||
| inline int GetTensorParallelSize() { return GlobalEnv::Instance().tensor_parallel_size(); } | ||
| inline int GetSequenceParallelSize() { return GlobalEnv::Instance().sequence_parallel_size(); } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| #include <chrono> | ||
| #include <cstdio> | ||
| #include <cstdlib> | ||
| #include <filesystem> | ||
| #include <fstream> | ||
| #include <iterator> | ||
|
|
@@ -11,26 +12,36 @@ | |
|
|
||
| namespace infini_train::core { | ||
| namespace { | ||
| std::string UniqueIdFileName(const std::string &name, bool tmp = false) { | ||
| return "cclUniqueId_" + name + (tmp ? ".tmp" : ".bin"); | ||
| std::string UniqueIdPath(const std::string &pg_name) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里生成的确实是 file name 而不是 path 吧,应该不需要修改函数名,下面 tmp 函数同理。 |
||
| const char *run_id = std::getenv("INFINI_RUN_ID"); | ||
| const std::string prefix = run_id == nullptr ? "" : std::string(run_id) + "_"; | ||
| return "cclUniqueId_" + prefix + pg_name + ".bin"; | ||
| } | ||
|
|
||
| std::string UniqueIdTmpPath(const std::string &pg_name) { | ||
| const char *run_id = std::getenv("INFINI_RUN_ID"); | ||
| const std::string prefix = run_id == nullptr ? "" : std::string(run_id) + "_"; | ||
| return "cclUniqueId_" + prefix + pg_name + ".tmp"; | ||
| } | ||
| } // namespace | ||
|
|
||
| void WriteUniqueIdFile(const CclUniqueId &unique_id, const std::string &pg_name) { | ||
| const std::string tmp_path = UniqueIdFileName(pg_name, true); | ||
| const std::string tmp_path = UniqueIdTmpPath(pg_name); | ||
|
|
||
| std::ofstream ofs(tmp_path, std::ios::binary); | ||
| CHECK(ofs.good()) << "Failed to open unique_id tmp file for write: " << tmp_path; | ||
| const size_t size = unique_id.Size(); | ||
| ofs.write(reinterpret_cast<const char *>(unique_id.Data()), static_cast<std::streamsize>(size)); | ||
| ofs.close(); | ||
|
|
||
| std::rename(tmp_path.c_str(), UniqueIdFileName(pg_name).c_str()); | ||
| const std::string file_path = UniqueIdPath(pg_name); | ||
| CHECK_EQ(std::rename(tmp_path.c_str(), file_path.c_str()), 0) | ||
| << "Failed to rename unique_id file from " << tmp_path << " to " << file_path; | ||
| } | ||
|
|
||
| void ReadUniqueIdFile(CclUniqueId *unique_id, const std::string &pg_name) { | ||
| CHECK_NOTNULL(unique_id); | ||
| const std::string file_path = UniqueIdFileName(pg_name); | ||
| const std::string file_path = UniqueIdPath(pg_name); | ||
|
|
||
| while (!std::filesystem::exists(file_path)) { std::this_thread::sleep_for(std::chrono::microseconds(1000)); } | ||
|
|
||
|
|
@@ -46,10 +57,15 @@ void ReadUniqueIdFile(CclUniqueId *unique_id, const std::string &pg_name) { | |
| } | ||
|
|
||
| void CleanupUniqueIdFile(const std::string &pg_name) { | ||
| const std::string file_path = UniqueIdFileName(pg_name); | ||
| const std::string file_path = UniqueIdPath(pg_name); | ||
| if (std::filesystem::exists(file_path)) { | ||
| std::filesystem::remove(file_path); | ||
| } | ||
|
|
||
| const std::string tmp_path = UniqueIdTmpPath(pg_name); | ||
| if (std::filesystem::exists(tmp_path)) { | ||
| std::filesystem::remove(tmp_path); | ||
| } | ||
| } | ||
|
|
||
| } // namespace infini_train::core | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要确认下目前的使用行为,README 里删除了 -- 作为启动/训练参数的分隔符?但我看 pr description 里写的是 "support -- as the launcher/training-args separator",原始版本也是通过 -- 作为分隔符的。
顺便指出 pr description 的另一处小问题:

这里似乎需要更新一下,目前应该是多进程/多线程测例同时保留了,vpp case 的说明似乎也和实际代码不一致。