-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add NPU FusedAdam support #4343
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
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
e37215d
add npu support dtypes
CurryRice233 8614f40
Merge remote-tracking branch 'origin/master'
CurryRice233 ac78f3a
add npu fused_adam support
CurryRice233 fd64619
Merge branch 'master' into master
CurryRice233 a43fcf8
Merge branch 'master' into master
CurryRice233 0617206
Merge branch 'master' into master
CurryRice233 c87ef32
add license
CurryRice233 5eaeee0
Merge remote-tracking branch 'origin/master'
CurryRice233 510166e
Merge branch 'master' into master
CurryRice233 efe4c12
Merge branch 'master' into master
tjruwase 51ddc02
Merge branch 'master' into master
CurryRice233 b472ecf
Merge branch 'master' into master
tjruwase 258eac1
Update accelerator/npu_accelerator.py
CurryRice233 620b85e
Update op_builder/npu/fused_adam.py
CurryRice233 dd94fcc
Update op_builder/npu/fused_adam.py
CurryRice233 b41f20c
Update op_builder/npu/fused_adam.py
CurryRice233 0487035
Update op_builder/npu/fused_adam.py
CurryRice233 52a2a8c
Update op_builder/npu/fused_adam.py
CurryRice233 d808f86
Update op_builder/npu/fused_adam.py
CurryRice233 fb77cd0
Update op_builder/npu/fused_adam.py
CurryRice233 38bc926
Merge branch 'master' into master
CurryRice233 7b26ce4
Update accelerator/npu_accelerator.py
CurryRice233 da7edd6
Update accelerator/npu_accelerator.py
CurryRice233 4b6197f
Merge branch 'master' into master
CurryRice233 20bd85e
Merge branch 'master' into master
CurryRice233 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # DeepSpeed Team | ||
|
|
||
| from .builder import NPUOpBuilder | ||
|
|
||
| try: | ||
| import torch_npu | ||
| except ImportError as e: | ||
| pass | ||
|
|
||
|
|
||
| class NPUFusedAdam: | ||
|
|
||
| @staticmethod | ||
CurryRice233 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def multi_tensor_adam(chunk_size, noop_flag_buffer, tensor_lists, lr, beta1, beta2, epsilon, step, adam_w_mode, | ||
| bias_correction, weight_decay, *args): | ||
| bias_correction1 = beta1**step | ||
| bias_correction2 = beta2**step | ||
|
|
||
| # iteration group['params'] | ||
| for i in range(len(tensor_lists[0])): | ||
| grad_flat = tensor_lists[0][i] | ||
| param_flat = tensor_lists[1][i] | ||
| m_flat = tensor_lists[2][i] | ||
| v_flat = tensor_lists[3][i] | ||
|
|
||
| if adam_w_mode: | ||
| param_flat.data, m_flat, v_flat = torch_npu.npu_apply_adam_w( | ||
| bias_correction1, | ||
| bias_correction2, | ||
| lr, | ||
| weight_decay, | ||
| beta1, | ||
| beta2, | ||
| epsilon, | ||
| grad_flat, | ||
| None, # max_grad_norm | ||
| False, # amsgrad | ||
| False, # maximize | ||
| out=(param_flat.data, m_flat, v_flat)) | ||
| else: | ||
| param_flat.data, m_flat, v_flat = torch_npu.npu_apply_adam( | ||
| bias_correction1, | ||
| bias_correction2, | ||
| lr, | ||
| beta1, | ||
| beta2, | ||
| epsilon, | ||
| grad_flat, | ||
| False, # use_locking | ||
| False, # use_nesterov | ||
| out=(param_flat.data, m_flat, v_flat)) | ||
|
|
||
|
|
||
| class FusedAdamBuilder(NPUOpBuilder): | ||
| BUILD_VAR = "DS_BUILD_FUSED_ADAM" | ||
| NAME = "fused_adam" | ||
|
|
||
| def __init__(self): | ||
| super().__init__(name=self.NAME) | ||
|
|
||
| def absolute_name(self): | ||
| return f'deepspeed.ops.adam.{self.NAME}_op' | ||
|
|
||
| def sources(self): | ||
| return [] | ||
|
|
||
| def include_paths(self): | ||
| return [] | ||
|
|
||
| def load(self, verbose=True): | ||
| return NPUFusedAdam | ||
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.