Skip to content

Commit

Permalink
nn.Identity is not required to be compatible with PyTorch < 1.1.0 as …
Browse files Browse the repository at this point in the history
…the minimum PyTorch version we currently support is 1.10.0 (huggingface#25974)

nn.Identity is not required to be compatible with PyTorch < 1.1.0 as the
minimum PyTorch version we currently support is 1.10.0
  • Loading branch information
ji-huazhong authored and EduardoPach committed Nov 18, 2023
1 parent 8269474 commit b8636f6
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions src/transformers/modeling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import torch
from packaging import version
from torch import Tensor, nn
from torch.nn import CrossEntropyLoss
from torch.nn import CrossEntropyLoss, Identity

from .activations import get_activation
from .configuration_utils import PretrainedConfig
Expand Down Expand Up @@ -151,20 +151,6 @@ def no_init_weights(_enable=True):
_init_weights = old_init_weights


try:
from torch.nn import Identity
except ImportError:
# Older PyTorch compatibility
class Identity(nn.Module):
r"""A placeholder identity operator that is argument-insensitive."""

def __init__(self, *args, **kwargs):
super().__init__()

def forward(self, input):
return input


def get_parameter_device(parameter: Union[nn.Module, GenerationMixin, "ModuleUtilsMixin"]):
try:
return next(parameter.parameters()).device
Expand Down

0 comments on commit b8636f6

Please sign in to comment.