-
Notifications
You must be signed in to change notification settings - Fork 905
[megatron] update megatron kto #6036
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
Merged
Jintao-Huang
merged 23 commits into
modelscope:main
from
Jintao-Huang:update_megatron_kto
Oct 8, 2025
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e7ab82c
update
Jintao-Huang 0c89bee
update
Jintao-Huang 01c9dfe
update
Jintao-Huang 8127dc0
Merge branch 'main' into update_megatron_kto
Jintao-Huang f622656
update
Jintao-Huang a0a866f
update
Jintao-Huang 3176ede
update
Jintao-Huang bdfc939
update
Jintao-Huang 849972c
update
Jintao-Huang b087499
updae
Jintao-Huang cb1d0fb
update
Jintao-Huang a76e6af
update
Jintao-Huang b493fcf
update
Jintao-Huang 973cd6d
update
Jintao-Huang 255aece
update
Jintao-Huang 12aee79
Merge branch 'main' into update_megatron_kto
Jintao-Huang 38023e9
update
Jintao-Huang caeaae2
fix
Jintao-Huang a438ff7
fix
Jintao-Huang b7cb9b2
update
Jintao-Huang 2062ecb
update
Jintao-Huang 3a87e2a
update
Jintao-Huang 65f17ff
update
Jintao-Huang 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
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
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,36 @@ | ||
# 4 * 43GiB | ||
PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \ | ||
NPROC_PER_NODE=4 \ | ||
CUDA_VISIBLE_DEVICES=0,1,2,3 \ | ||
megatron rlhf \ | ||
--rlhf_type kto \ | ||
--load Qwen2.5-7B-Instruct-mcore \ | ||
--dataset 'AI-ModelScope/ultrafeedback-binarized-preferences-cleaned-kto#20000' \ | ||
--load_from_cache_file true \ | ||
--split_dataset_ratio 0.01 \ | ||
--tensor_model_parallel_size 4 \ | ||
--packing true \ | ||
--micro_batch_size 1 \ | ||
--global_batch_size 4 \ | ||
--recompute_granularity full \ | ||
--recompute_method uniform \ | ||
--recompute_num_layers 1 \ | ||
--max_epochs 1 \ | ||
--finetune true \ | ||
--cross_entropy_loss_fusion true \ | ||
--lr 1e-5 \ | ||
--lr_warmup_fraction 0.05 \ | ||
--min_lr 1e-6 \ | ||
--save megatron_output/Qwen2.5-7B-Instruct \ | ||
--eval_interval 200 \ | ||
--save_interval 200 \ | ||
--max_length 8192 \ | ||
--num_workers 8 \ | ||
--dataset_num_proc 8 \ | ||
--no_save_optim true \ | ||
--no_save_rng true \ | ||
--sequence_parallel true \ | ||
--attention_backend flash \ | ||
--beta 0.1 \ | ||
--desirable_weight 1 \ | ||
--undesirable_weight 1 |
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,44 @@ | ||
# 2 * 48GiB | ||
PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \ | ||
NPROC_PER_NODE=2 \ | ||
CUDA_VISIBLE_DEVICES=0,1 \ | ||
megatron rlhf \ | ||
--rlhf_type kto \ | ||
--load Qwen3-30B-A3B-Instruct-2507-mcore \ | ||
--dataset 'AI-ModelScope/ultrafeedback-binarized-preferences-cleaned-kto#20000' \ | ||
--load_from_cache_file true \ | ||
--packing true \ | ||
--train_type lora \ | ||
--lora_rank 8 \ | ||
--lora_alpha 32 \ | ||
--target_modules all-linear \ | ||
--split_dataset_ratio 0.01 \ | ||
--expert_model_parallel_size 2 \ | ||
--moe_permute_fusion true \ | ||
--moe_grouped_gemm true \ | ||
--moe_shared_expert_overlap true \ | ||
--moe_aux_loss_coeff 1e-3 \ | ||
--micro_batch_size 1 \ | ||
--global_batch_size 4 \ | ||
--recompute_granularity full \ | ||
--recompute_method uniform \ | ||
--recompute_num_layers 1 \ | ||
--max_epochs 1 \ | ||
--finetune true \ | ||
--cross_entropy_loss_fusion true \ | ||
--lr 1e-4 \ | ||
--lr_warmup_fraction 0.05 \ | ||
--min_lr 1e-5 \ | ||
--save megatron_output/Qwen3-30B-A3B-Instruct-2507 \ | ||
--eval_interval 100 \ | ||
--save_interval 100 \ | ||
--max_length 8192 \ | ||
--num_workers 8 \ | ||
--dataset_num_proc 8 \ | ||
--no_save_optim true \ | ||
--no_save_rng true \ | ||
--sequence_parallel true \ | ||
--attention_backend flash \ | ||
--beta 0.1 \ | ||
--desirable_weight 1 \ | ||
--undesirable_weight 1 |
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
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.
The
calculate_KL
parameter seems to have been removed from the KTO parameters documentation. However, it's still a configurable parameter in the code (swift/megatron/argument/megatron_args.py
). It's now optional and can be inferred, but users can still set it. It would be beneficial to document this parameter for clarity.For example, you could add: