配置新的c++/python联合编程环境

在这里插入图片描述

因此我们需要重新配置一下环境。。

克隆环境

在这里插入图片描述

conda create -n pt17two --clone pt17

在这里插入图片描述

export failure: Exporting the operator silu to ONNX opset version 12 is not supported. Please open a bug to request ONNX export support for the missing operator.

如果有需要转onnx,遇到过一个bug,export failure: Exporting the operator silu to ONNX opset version 12 is not supported. Please open a bug to request ONNX export support for the missing operator. 这是因为onnx与pytorch一些方法不兼容导致的,onnx不支持silu,把**函数换一种写法即可。解决方式如下:

C:\ProgramData\Anaconda3\envs\pt17two\Lib\site-packages\torch\nn\modules

(这里路径因人而异,我是建的虚拟环境)找到该路径下的 activation.py 脚本,然后按照下面的方式进行修改即可。

class SiLU(Module):
    r"""Applies the silu function, element-wise.

    .. math::
        \text{silu}(x) = x * \sigma(x), \text{where } \sigma(x) \text{ is the logistic sigmoid.}

    .. note::
        See `Gaussian Error Linear Units (GELUs) <https://arxiv.org/abs/1606.08415>`_ 
        where the SiLU (Sigmoid Linear Unit) was originally coined, and see 
        `Sigmoid-Weighted Linear Units for Neural Network Function Approximation 
        in Reinforcement Learning <https://arxiv.org/abs/1702.03118>`_ and `Swish: 
        a Self-Gated Activation Function <https://arxiv.org/abs/1710.05941v1>`_ 
        where the SiLU was experimented with later.

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

    Examples::

        >>> m = nn.SiLU()
        >>> input = torch.randn(2)
        >>> output = m(input)
    """
    __constants__ = ['inplace']
    inplace: bool

    def __init__(self, inplace: bool = False):
        super(SiLU, self).__init__()
        self.inplace = inplace

    def forward(self, input: Tensor) -> Tensor:
         # ------------------------------------- #
        # 把F.silu替换掉,修改后如下
        return input * torch.sigmoid(input)
        #原来的代码
        return F.silu(input, inplace=self.inplace)

在这里插入图片描述
在这里插入图片描述
成功。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值