Skip to content

Commit

Permalink
generalize api (NVIDIA#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
YizhouZ committed Jul 20, 2023
1 parent 69e3c6a commit 0e9b765
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 5 additions & 1 deletion megatron/model/gpt_model.py
Expand Up @@ -19,7 +19,11 @@
from .transformer import ParallelTransformerLayerPipe, LMHeadPipe
from deepspeed.pipe import PipelineModule, LayerSpec, TiedLayerSpec

from apex.normalization import MixedFusedRMSNorm
try:
from apex.normalization import MixedFusedRMSNorm
except ImportError:
MixedFusedRMSNorm = None


def post_language_model_processing(lm_output, labels, logit_weights,
parallel_output,
Expand Down
16 changes: 11 additions & 5 deletions megatron/model/transformer.py
Expand Up @@ -45,7 +45,12 @@
flash_attn_builder = FlashAttentionBuilder().load()
except TypeError:
flash_attn_builder = None
from apex.normalization import MixedFusedRMSNorm

try:
from apex.normalization import MixedFusedRMSNorm
except ImportError:
MixedFusedRMSNorm = None



""" We use the following notation throughout this file:
Expand Down Expand Up @@ -383,10 +388,11 @@ def forward(self, q, k, v):
"""

assert all((i.dtype in [torch.float16, torch.bfloat16] for i in (q,k,v)))
if get_accelerator().device_name() == 'cuda':
assert all((i.is_cuda for i in (q,k,v)))
else:
assert all((i.is_xpu for i in (q,k,v)))
assert all((get_accelerator().on_accelerator(i) for i in (q, k, v)))
# if get_accelerator().device_name() == 'cuda':
# assert all((i.is_cuda for i in (q,k,v)))
# else:
# assert all((i.is_xpu for i in (q,k,v)))

batch_size, seqlen_q = q.shape[0], q.shape[1]
seqlen_k = k.shape[1]
Expand Down

0 comments on commit 0e9b765

Please sign in to comment.