How to pass multiple inputs into the forward function in Pytorch

本文介绍了在PyTorch中遇到错误时如何处理多输入模型的forward函数。提到了使用'*'来解决'需要一个必需的输入或参数'的问题,以及检查输入一致性以解决'给出两个但提供了三个'的错误。还强调了注意迭代结构中输入和返回维度的一致性,并提供了一种将常量输入保存到文件以控制变量为常量的妥协解决方案。
摘要由CSDN通过智能技术生成

when pass the several input into a model, you need to add something.

when run into the error that ' you need a required input or parameter' : you could use * in front of C,     but I don't know why, I just try it out for thousands of times to make it work.

when run into the error that ' expect two, but three were given':  please check the coherence of the input, make sure the input is the same and they have been passed coherently. 

be careful about the iterative structure, they could be more complex, and make sure the input and return are the same dimension. 

If still error, you could save the constant input to a file, and load it at the right time. Control the variable into a constant. It's a compromise solution. 

 

 

def forward(self, A, *C):

        if self.outermost:
            #print(

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值