forked from microsoft/Megatron-DeepSpeed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable Sequence Parallelism (microsoft#429)
- Loading branch information
1 parent
1280f59
commit 0d6e379
Showing
7 changed files
with
50 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -1,16 +1,29 @@ | ||
# Copyright (C) 2024 Habana Labs, Ltd. an Intel Company. | ||
|
||
from deepspeed.accelerator import get_accelerator | ||
from megatron import get_args | ||
|
||
import torch | ||
from torch.nn import init | ||
from torch.nn.parameter import Parameter | ||
|
||
# Taken from facebookresearch/llama | ||
class RMSNorm(torch.nn.Module): | ||
def __init__(self, dim: int, eps: float = 1e-6): | ||
super().__init__() | ||
self.eps = eps | ||
self.weight = Parameter(torch.ones(dim)) | ||
init_device = None | ||
if get_accelerator().device_name() == 'hpu': | ||
init_device = get_accelerator().current_device_name() | ||
self.weight = Parameter(torch.empty(dim, | ||
device=init_device, | ||
dtype=get_args().params_dtype)) | ||
init.ones_(self.weight) | ||
setattr(self.weight, 'sequence_parallel', sequence_parallel) | ||
|
||
def _norm(self, x): | ||
return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps) | ||
|
||
def forward(self, x): | ||
output = self._norm(x.float()).type_as(x) | ||
return output * self.weight | ||
return output * self.weight |
This file contains 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