Skip to content

[Bug]Add sequence_parallel in layernorm init to enable 3D parallelism with DeepSpeed for non CUDA device. #468

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 1 commit into from
Jul 16, 2025
Merged
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 megatron/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .fused_rmsnorm import RMSNorm
else:
from .rmsnorm import RMSNorm
from torch.nn import LayerNorm
from .layernorm import SPLayerNorm as LayerNorm

from .distributed import DistributedDataParallel
from .bert_model import BertModel
Expand Down
10 changes: 10 additions & 0 deletions megatron/model/layernorm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import torch

class SPLayerNorm(torch.nn.LayerNorm):
def __init__(self, normalized_shape, eps: float = 1e-5, sequence_parallel=False):
super(SPLayerNorm, self).__init__(normalized_shape, eps)
self.sequence_parallel = sequence_parallel
setattr(self.weight, 'sequence_parallel', self.sequence_parallel)

def forward(self, x):
return super(SPLayerNorm, self).forward(x)