-
Notifications
You must be signed in to change notification settings - Fork 279
feat: Add npu megatron support #380
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
UsernameFull
wants to merge
8
commits into
alibaba:main
Choose a base branch
from
UsernameFull:npu_megatron
base: main
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
8 commits
Select commit
Hold shift + click to select a range
c6dcb98
fix: add sft support on npu
UsernameFull 26ca43a
adapt mindspeed
jiaqiw09 0af5e74
fix: add base worker npu support, add npu example yaml
UsernameFull 2326d75
fix: add base worker npu support
UsernameFull d80fef2
feat: Add npu megatron support
UsernameFull 23299b0
Merge branch 'main' of https://github.com/alibaba/ROLL into npu_megatron
UsernameFull 98064e2
feat: Add npu megatron support
UsernameFull dcdd8f8
feat: Add npu megatron support
UsernameFull 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| defaults: | ||
| - ../config/deepspeed_zero@_here_ | ||
| - ../config/deepspeed_zero2@_here_ | ||
| - ../config/deepspeed_zero3@_here_ | ||
| - ../config/deepspeed_zero3_cpuoffload@_here_ | ||
|
|
||
| hydra: | ||
| run: | ||
| dir: . | ||
| output_subdir: null | ||
|
|
||
| exp_name: "qwen3-4B-dpo-config" | ||
| seed: 42 | ||
| logging_dir: ./output/logs | ||
| output_dir: ./output | ||
| system_envs: | ||
| USE_MODELSCOPE: '1' | ||
|
|
||
| checkpoint_config: | ||
| type: file_system | ||
| output_dir: ./ckpt | ||
|
|
||
|
|
||
| track_name: None | ||
|
|
||
|
|
||
| max_steps: 500 | ||
| save_steps: 500 | ||
| logging_steps: 1 | ||
| eval_steps: 100 | ||
| resume_from_checkpoint: false | ||
|
|
||
| sequence_length: 512 | ||
| train_batch_size: 64 | ||
| val_batch_size: 64 | ||
|
|
||
| # local_rank: -1 | ||
| num_nodes: 1 | ||
| num_gpus_per_node: 4 | ||
|
|
||
| pretrain: Qwen/Qwen3-4B | ||
|
|
||
| ipo: false | ||
| beta: 0.1 | ||
| label_smoothing: 0.0 | ||
|
|
||
| chosen_key: chosen | ||
| rejected_key: rejected | ||
|
|
||
| validation: | ||
| data_args: | ||
| template: qwen3 | ||
| file_name: data/comparison_gpt4_data_zh.json | ||
|
|
||
| actor_train: | ||
| model_args: | ||
| disable_gradient_checkpointing: false | ||
| dtype: bf16 | ||
| model_type: ~ | ||
| training_args: | ||
| lr_scheduler_type: constant | ||
| learning_rate: 1.0e-6 | ||
| weight_decay: 0 | ||
| per_device_train_batch_size: 16 | ||
| gradient_accumulation_steps: 1 | ||
| warmup_steps: 20 | ||
| num_train_epochs: 10 | ||
| data_args: | ||
| template: qwen3 | ||
| file_name: | ||
| - data/comparison_gpt4_data_zh.json | ||
| dataset_dir: data | ||
| preprocessing_num_workers: 1 | ||
| strategy_args: | ||
| strategy_name: megatron_train | ||
| strategy_config: | ||
| tensor_model_parallel_size: 1 | ||
| pipeline_model_parallel_size: 1 | ||
| expert_model_parallel_size: 1 | ||
| use_distributed_optimizer: true | ||
| recompute_granularity: full | ||
| device_mapping: list(range(0,2)) | ||
| infer_batch_size: 16 | ||
|
|
||
|
|
||
| reference: | ||
| model_args: | ||
| disable_gradient_checkpointing: true | ||
| dtype: bf16 | ||
| model_type: ~ | ||
| data_args: | ||
| template: qwen3 | ||
| strategy_args: | ||
| strategy_name: megatron_infer | ||
| strategy_config: | ||
| tensor_model_parallel_size: 1 | ||
| pipeline_model_parallel_size: 1 | ||
| expert_model_parallel_size: 1 | ||
| device_mapping: list(range(2,4)) | ||
| infer_batch_size: 16 |
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,5 @@ | ||
| #!/bin/bash | ||
| set +x | ||
|
|
||
| CONFIG_PATH=$(basename $(dirname $0)) | ||
| python examples/start_dpo_pipeline.py --config_path $CONFIG_PATH --config_name qwen3_4B_dpo_megatron |
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 |
|---|---|---|
|
|
@@ -25,26 +25,31 @@ def _init_platform() -> Platform: | |
| Returns: | ||
| An instance of a subclass of Platform corresponding to the detected hardware. | ||
| """ | ||
| try: | ||
| import torch_npu # noqa: F401 | ||
|
|
||
| if hasattr(torch, "npu") and torch.npu.is_available(): | ||
| logger.debug("Detected NPU (torch_npu). Initializing NPU platform.") | ||
|
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. plz change log_level to info |
||
| return NpuPlatform() | ||
| except ImportError: | ||
| pass | ||
|
|
||
| if torch.cuda.is_available(): | ||
| device_name = torch.cuda.get_device_name().upper() | ||
| logger.debug(f"Detected CUDA device: {device_name}") | ||
|
|
||
| if "NVIDIA" in device_name: | ||
| logger.debug("Initializing CUDA platform (NVIDIA).") | ||
| return CudaPlatform() | ||
| elif "AMD" in device_name: | ||
| logger.debug("Initializing ROCm platform (AMD).") | ||
| return RocmPlatform() | ||
|
|
||
| logger.warning("Unrecognized CUDA device. Falling back to UnknownPlatform.") | ||
| return UnknownPlatform() | ||
| else: | ||
| try: | ||
| import torch_npu # noqa: F401 | ||
|
|
||
| logger.debug("Detected torch_npu. Initializing NPU platform.") | ||
| return NpuPlatform() | ||
| except ImportError: | ||
| logger.debug("No supported accelerator detected. Initializing CPU platform.") | ||
| return CpuPlatform() | ||
| logger.debug("No supported accelerator detected. Initializing CPU platform.") | ||
| return CpuPlatform() | ||
|
|
||
|
|
||
| # Global singleton representing the current platform in use. | ||
|
|
||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.