Skip to content
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
11 changes: 5 additions & 6 deletions src/transformers/models/bart/modeling_bart.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,12 @@ def _expand_mask(mask: torch.Tensor, dtype: torch.dtype, tgt_len: Optional[int]


def BartLayerNorm(normalized_shape: torch.Size, eps: float = 1e-5, elementwise_affine: bool = True):
if torch.cuda.is_available():
try:
from apex.normalization import FusedLayerNorm
try:
from apex.normalization import FusedLayerNorm

return FusedLayerNorm(normalized_shape, eps, elementwise_affine)
except ImportError:
pass
return FusedLayerNorm(normalized_shape, eps, elementwise_affine)
except ImportError:
pass
return torch.nn.LayerNorm(normalized_shape, eps, elementwise_affine)


Expand Down
12 changes: 5 additions & 7 deletions src/transformers/models/fsmt/modeling_fsmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,12 @@


have_fused_layer_norm = False
if torch.cuda.is_available():
try:
from apex.normalization import FusedLayerNorm

have_fused_layer_norm = True
except ImportError:
pass
try:
from apex.normalization import FusedLayerNorm

have_fused_layer_norm = True
except ImportError:
pass
LayerNorm = FusedLayerNorm if have_fused_layer_norm else torch.nn.LayerNorm


Expand Down
11 changes: 5 additions & 6 deletions src/transformers/models/prophetnet/modeling_prophetnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,12 @@ class ProphetNetDecoderLMOutput(ModelOutput):


def ProphetNetLayerNorm(normalized_shape, eps=1e-5, elementwise_affine=True):
if torch.cuda.is_available():
try:
from apex.normalization import FusedLayerNorm
try:
from apex.normalization import FusedLayerNorm

return FusedLayerNorm(normalized_shape, eps, elementwise_affine)
except ImportError:
pass
return FusedLayerNorm(normalized_shape, eps, elementwise_affine)
except ImportError:
pass
return torch.nn.LayerNorm(normalized_shape, eps, elementwise_affine)


Expand Down