Skip to content
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

Enable compatibility of sparse MOE training under DeepSpeed ZeRO3 #312

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/sft/ds_config_zero3.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"contiguous_gradients": true,
"sub_group_size": 1e9,
"reduce_bucket_size": "auto",
"stage3_prefetch_bucket_size": "auto",
"stage3_prefetch_bucket_size": "0",
"stage3_param_persistence_threshold": "auto",
"stage3_max_live_parameters": 1e9,
"stage3_max_reuse_distance": 1e9,
Expand Down
7 changes: 7 additions & 0 deletions examples/sft/finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from transformers.trainer_pt_utils import LabelSmoother
from peft import LoraConfig, get_peft_model, prepare_model_for_kbit_training
from accelerate.utils import DistributedType
from deepspeed.utils import set_z3_leaf_modules
from transformers.models.qwen2_moe.modeling_qwen2_moe import Qwen2MoeSparseMoeBlock


IGNORE_TOKEN_ID = LabelSmoother.ignore_index
Expand Down Expand Up @@ -317,6 +319,11 @@ def train():
else None,
**model_load_kwargs,
)

# Set z3 flag to make sparse MoE layer compatible with Zero3,
# following https://github.com/microsoft/DeepSpeed/pull/5008
set_z3_leaf_modules(model, [Qwen2MoeSparseMoeBlock])

tokenizer = AutoTokenizer.from_pretrained(
model_args.model_name_or_path,
cache_dir=training_args.cache_dir,
Expand Down