-
Notifications
You must be signed in to change notification settings - Fork 124
patch for megatron core part 2 #896
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @koutianzhengwen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly extends the Megatron-LM framework by integrating support for Huawei Atlas800TA3 NPUs and introducing robust mechanisms for heterogeneous training. It updates model configurations for Qwen2.5-VL, enhances checkpointing capabilities, and refines argument and feature management, paving the way for more diverse and efficient large language model training environments. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a large set of patches for Megatron-LM, primarily aimed at enabling and optimizing training on Huawei Atlas800TA3 hardware. The changes span configuration files, model adaptation layers, custom optimizers, and hardware-specific communication logic. While the patch adds significant new functionality, there are several critical issues that need to be addressed, including hardcoded device types that will cause crashes on non-CUDA platforms, potential NameError and IndexError exceptions, and a security vulnerability related to torch.load. Additionally, there are maintainability concerns like hardcoded paths in configuration files and the inclusion of backup files in the repository. A number of unit tests have also been disabled, which is a significant concern for code quality and should be rectified.
| + mode = 1 if rotary_interleaved else 0 | ||
| + t = npu_rotary_position_embedding(t.contiguous(), cos_, sin_, mode).to(t.dtype) | ||
| + else: | ||
| + t = (t * cos_) + (_rotate_half(t, rotary_interleaved) * sin_) |
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.
| + if group['step'].is_cpu: | ||
| + group['step'] = group['step'].cuda() | ||
| + else: | ||
| + group['step'] = torch.tensor(1, dtype=torch.int64, device=torch.cuda.current_device()) |
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 device for the optimizer's step tensor is hardcoded to cuda. This will cause a crash on non-CUDA hardware like the target NPU platform. The device should be dynamically inferred from the model parameters to ensure portability.
if group['step'].device != group['params'][0].device:
group['step'] = group['step'].to(group['params'][0].device)
else:
group['step'] = torch.tensor(1, dtype=torch.int64, device=group['params'][0].device)
| + seq_len = actual_seq_len[0] | ||
| + actual_seq_len = [elem + i * seq_len for i, elem in enumerate(actual_seq_len)] | ||
| + batch['actual_seq_len'] = torch.tensor(actual_seq_len, dtype=torch.long) |
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.
Accessing actual_seq_len[0] without checking if the list is empty will raise an IndexError if the input samples list is empty. This can crash the data loading process. It's important to add a guard clause to handle this edge case gracefully.
if not actual_seq_len:
return batch
seq_len = actual_seq_len[0]
actual_seq_len = [elem + i * seq_len for i, elem in enumerate(actual_seq_len)]
batch['actual_seq_len'] = torch.tensor(actual_seq_len, dtype=torch.long)
| + #data_path: [40,/mnt/share/hetero_data/datasets/fineweb-edu-CC-3_5_text_document,28,/mnt/share/hetero_data/datasets/dclm-baseline-1.0-top_pct5_text_document,3,/mnt/share/hetero_data/datasets/k73_edu_qwen_text_document,5,/mnt/share/hetero_data/datasets/wxb_edu_qwen_text_document,20,/mnt/share/hetero_data/datasets/cosmopedia-v2-full_text_document,4,/mnt/share/hetero_data/datasets/infinst-kg-0712_text_document] | ||
| + # exp02 | ||
| + # data_path: [4.08,/mnt/share/hetero_data/datasets/k73_edu_qwen_text_document,6.52,/mnt/share/hetero_data/datasets/wxb_edu_qwen_text_document,14.4,/mnt/share/hetero_data/datasets/opencsg-chinese-fineweb-edu-v2_20241104_text_document,4.81,/mnt/share/hetero_data/datasets/fineweb-code-corpus_20241112_text_document,0.32,/mnt/share/hetero_data/datasets/smollm-corpus-python-edu_text_document,0.4,/mnt/share/hetero_data/datasets/opc-annealing-corpus-algorithmic_corpus_text_document,0.11,/mnt/share/hetero_data/datasets/opc-annealing-corpus-synthetic_code_snippet_text_document,0.09,/mnt/share/hetero_data/datasets/opc-annealing-corpus-synthetic_qa_text_document,1.7,/mnt/share/hetero_data/datasets/K76/code_filter_qwen05_loss3/c_text_document,1.37,/mnt/share/hetero_data/datasets/K76/code_filter_qwen05_loss3/cpp_text_document,0.7,/mnt/share/hetero_data/datasets/K76/code_filter_qwen05_loss3/go_text_document,1.89,/mnt/share/hetero_data/datasets/K76/code_filter_qwen05_loss3/java_text_document,1.61,/mnt/share/hetero_data/datasets/K76/code_filter_qwen05_loss3/javascript_text_document,0.16,/mnt/share/hetero_data/datasets/K76/code_filter_qwen05_loss3/json_text_document,0.2,/mnt/share/hetero_data/datasets/K76/code_filter_qwen05_loss3/jupyter-scripts-dedup-filtered_text_document,0.16,/mnt/share/hetero_data/datasets/K76/code_filter_qwen05_loss3/jupyter-structured-clean-dedup_text_document,1.93,/mnt/share/hetero_data/datasets/K76/code_filter_qwen05_loss3/markdown_text_document,1.45,/mnt/share/hetero_data/datasets/K76/code_filter_qwen05_loss3/python_text_document,0.09,/mnt/share/hetero_data/datasets/K76/code_filter_qwen05_loss3/shell_text_document,26.11,/mnt/share/hetero_data/datasets/Nemotron-CC-HQ/Nemotron-CC-high-synthetic-diverse_qa_pairs_text_document,28.89,/mnt/share/hetero_data/datasets/Nemotron-CC-HQ/Nemotron-CC-high-actual-actual_text_document,0.18,/mnt/share/hetero_data/datasets/EleutherAI-proof-pile-2/EleutherAI-proof-pile-2-open-web-math_text_document,0.3,/mnt/share/hetero_data/datasets/finemath/infiwebmath-3plus_text_document,0.52,/mnt/share/hetero_data/datasets/finemath/finemath-3plus_text_document,1.0,/mnt/share/hetero_data/datasets/dolma_arxiv_text_document,1.0,/mnt/share/hetero_data/datasets/dolma_pes2o_v2_text_document] | ||
| + data_path: /share/project/lizhiyu/data/pile_wikipedia_demo |
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 data_path is hardcoded to /share/project/lizhiyu/data/pile_wikipedia_demo. Hardcoding paths makes the configuration less portable and harder to use in different environments. Consider using a placeholder or an environment variable, like ${data_path:??} which is used in other configuration files in this repository.
| diff --git a/examples/aquila/conf/train/7b.yaml.bak b/examples/aquila/conf/train/7b.yaml.bak | ||
| new file mode 100644 | ||
| index 00000000..a534b9e1 | ||
| --- /dev/null | ||
| +++ b/examples/aquila/conf/train/7b.yaml.bak | ||
| @@ -0,0 +1,64 @@ | ||
| +system: | ||
| + tensor_model_parallel_size: 1 | ||
| + pipeline_model_parallel_size: 1 | ||
| + disable_bias_linear: True | ||
| + use_flash_attn: True | ||
| + use_distributed_optimizer: True | ||
| + precision: | ||
| + fp16: True | ||
| + initial_loss_scale: 522893 | ||
| + min_loss_scale: 1.0 | ||
| + attention_softmax_in_fp32: True | ||
| + accumulate_allreduce_grads_in_fp32: True | ||
| + logging: | ||
| + log_interval: 1 | ||
| + tensorboard_log_interval: 1 | ||
| + wandb_project: "train-aquila-7B" | ||
| + wandb_exp_name: "train-test-7B" | ||
| + checkpoint: | ||
| + save_interval: 2000 | ||
| + | ||
| +model: | ||
| + num_layers: 32 | ||
| + hidden_size: 4096 | ||
| + num_attention_heads: 32 | ||
| + seq_length: 2048 | ||
| + max_position_embeddings: 2048 | ||
| + norm_epsilon: 1e-5 | ||
| + use_rotary_position_embeddings: true | ||
| + no_position_embedding: true | ||
| + swiglu: true | ||
| + multiple_of: 256 | ||
| + normalization: RMSNorm | ||
| + # rotary_interleaved_patch: true | ||
| + untie_embeddings_and_output_weights: true | ||
| + init_method_std: 0.02 | ||
| + attention_dropout: 0.0 | ||
| + hidden_dropout: 0.0 | ||
| + weight_decay: 0.1 | ||
| + clip_grad: 1.0 | ||
| + train_samples: 1002539063 | ||
| + eval_iters: 0 | ||
| + micro_batch_size: 2 | ||
| + global_batch_size: 1728 | ||
| + seed: 1234 | ||
| + | ||
| + optimizer: | ||
| + weight_decay: 0.1 | ||
| + adam_beta1: 0.9 | ||
| + adam_beta2: 0.95 | ||
| + lr_scheduler: | ||
| + lr: 2.0e-5 | ||
| + min_lr: 2.0e-6 | ||
| + lr_warmup_samples: 3076172 | ||
| + lr_decay_style: cosine | ||
| + | ||
| +data: | ||
| + data_path: ${data_path:??} | ||
| + split: 1 | ||
| + tokenizer: | ||
| + tokenizer_type: AquilaTokenizerFS | ||
| + vocab_file: ./examples/aquila/tokenizer/vocab.json | ||
| + merge_file: ./examples/aquila/tokenizer/merges.txt | ||
| + special_tokens_file: ./examples/aquila/tokenizer/special_tokens.txt | ||
| + vocab_size: 100008 | ||
|
|
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.
|
|
||
| data: | ||
| - data_path: ${data_path:??} | ||
| + data_path: /home/dataset/pile_wikipedia_demo |
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.
|
zhaoxuncheng seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
patch for megatron core part 2