AttributeError: ‘GELU‘ object has no attribute ‘approximate‘

不用更换环境:
找到GELU的位置,我的是在activation.py文件,将其修改为不使用 approximate 属性即可。

把原始的文件注释如下:

# class GELU(Module):
#     r"""Applies the Gaussian Error Linear Units function:

#     .. math:: \text{GELU}(x) = x * \Phi(x)

#     where :math:`\Phi(x)` is the Cumulative Distribution Function for Gaussian Distribution.

#     When the approximate argument is 'tanh', Gelu is estimated with:

#     .. math:: \text{GELU}(x) = 0.5 * x * (1 + \text{Tanh}(\sqrt(2 / \pi) * (x + 0.044715 * x^3)))

#     Args:
#         approximate (str, optional): the gelu approximation algorithm to use:
#             ``'none'`` | ``'tanh'``. Default: ``'none'``

#     Shape:
#         - Input: :math:`(*)`, where :math:`*` means any number of dimensions.
#         - Output: :math:`(*)`, same shape as the input.

#     .. image:: ../scripts/activation_images/GELU.png

#     Examples::

#         >>> m = nn.GELU()
#         >>> input = torch.randn(2)
#         >>> output = m(input)
#     """
#     __constants__ = ['approximate']
#     approximate: str

#     def __init__(self, approximate: str = 'none') -> None:
#         super(GELU, self).__init__()
#         self.approximate = approximate

#     def forward(self, input: Tensor) -> Tensor:
#         return F.gelu(input, approximate=self.approximate)

#     def extra_repr(self) -> str:
#         return 'approximate={}'.format(repr(self.approximate))

替换为:

class GELU(Module):
    r"""Applies the Gaussian Error Linear Units function:

    .. math:: \text{GELU}(x) = x * \Phi(x)

    where :math:`\Phi(x)` is the Cumulative Distribution Function for Gaussian Distribution.

    Shape:
        - Input: :math:`(*)`, where :math:`*` means any number of dimensions.
        - Output: :math:`(*)`, same shape as the input.

    .. image:: ../scripts/activation_images/GELU.png

    Examples::

        >>> m = nn.GELU()
        >>> input = torch.randn(2)
        >>> output = m(input)
    """
    def __init__(self) -> None:
        super(GELU, self).__init__()

    def forward(self, input: Tensor) -> Tensor:
        return F.gelu(input)

    def extra_repr(self) -> str:
        return 'GELU()'

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值