-
Notifications
You must be signed in to change notification settings - Fork 43
Feat: add checkpoint loading mechanism #146
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
JYMiracle305
wants to merge
5
commits into
master
Choose a base branch
from
feature/add_checkpoint
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
5 commits
Select commit
Hold shift + click to select a range
69a0729
feat: checkpoint save & load
ArcaLunar ade0893
format: format files in examples and infini_train
ArcaLunar 39e89bf
feat: extract resuming to utils
ArcaLunar b363779
feat: extract similar logic in ckpt_save
ArcaLunar 0a3deb2
feat(checkpoint): reorganize checkpoint code and improve robustness
JYMiracle305 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #pragma once | ||
|
|
||
| #include "infini_train/include/checkpoint.h" | ||
| #include "infini_train/include/dataloader.h" | ||
| #include "infini_train/include/nn/modules/module.h" | ||
| #include "infini_train/include/nn/parallel/rank.h" | ||
| #include "infini_train/include/optimizer.h" | ||
|
|
||
| #include "gflags/gflags.h" | ||
|
|
||
| #include <cstdint> | ||
| #include <cstring> | ||
| #include <filesystem> | ||
|
|
||
| #include <functional> | ||
| #include <limits> | ||
| #include <string> | ||
|
|
||
| namespace infini_train { | ||
| namespace nn { | ||
| class TransformerModel; | ||
| } | ||
|
|
||
| namespace gpt2 { | ||
| std::shared_ptr<nn::TransformerModel> LoadFromLLMC(const std::string &filepath); | ||
| void SaveAsLLMC(const std::shared_ptr<nn::TransformerModel> &model, const std::string &filepath); | ||
| } // namespace gpt2 | ||
| namespace llama3 { | ||
| std::shared_ptr<nn::TransformerModel> LoadFromLLMC(const std::string &filepath); | ||
| void SaveAsLLMC(const std::shared_ptr<nn::TransformerModel> &model, const std::string &filepath); | ||
| } // namespace llama3 | ||
|
|
||
| struct ResumeFromCheckpointArgs { | ||
| fLS::clstring resume_root; | ||
| const nn::parallel::Rank &rank; | ||
| std::shared_ptr<nn::Module> model; | ||
| std::shared_ptr<Optimizer> optimizer; | ||
| DistributedDataLoader &train_loader; | ||
| TrainerState &state; | ||
| DataLoaderIterator &train_iter; | ||
| CheckpointLoadOptions load_options; | ||
| }; | ||
|
|
||
| struct ResumeFromCheckpointResult { | ||
| int global_step = 0; | ||
| float best_loss = std::numeric_limits<float>::infinity(); | ||
| size_t data_batch_idx = 0; | ||
| }; | ||
|
|
||
| struct SaveCheckpointArgs { | ||
| std::filesystem::path save_dir; | ||
| int64_t global_step = 0; | ||
| size_t data_batch_idx = 0; | ||
| float best_loss = std::numeric_limits<float>::infinity(); | ||
| double last_lr = 0.0; | ||
| std::string optimizer_type; | ||
| std::string checkpoint_format = "bin"; | ||
| int ddp_size = 1; | ||
| int tp_size = 1; | ||
| int sp_size = 1; | ||
| int pp_size = 1; | ||
| bool save_optimizer_state = true; | ||
| bool prune_step_checkpoints = false; | ||
| std::filesystem::path checkpoint_root_dir; | ||
| size_t max_checkpoint_keep = 0; | ||
| const nn::parallel::Rank &rank; | ||
| const nn::Module &model; | ||
| const Optimizer &optimizer; | ||
| std::function<void(const nn::Module &, const std::filesystem::path &)> model_bin_writer; | ||
| }; | ||
|
|
||
| ResumeFromCheckpointResult ResumeFromCheckpoint(const ResumeFromCheckpointArgs &args); | ||
|
|
||
| void SaveCheckpoint(const SaveCheckpointArgs &args); | ||
|
|
||
| } // namespace infini_train |
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
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.
这几个 include 还需要吗,是不是可以删掉