首页 > 其他分享 >pytorch 使用多GPU训练模型测试出现:TypeError: forward() missing 1 required positional argument: ‘x‘可能解决方法

pytorch 使用多GPU训练模型测试出现:TypeError: forward() missing 1 required positional argument: ‘x‘可能解决方法

时间:2023-06-20 09:02:57浏览次数:35  
标签:TypeError missing 2522% required argument positional forward

转载:https://blog.csdn.net/lingyunxianhe/article/details/119454778?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168718901716800227455818%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=168718901716800227455818&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-1-119454778-null-null.268^v1^koosearch&utm_term=TypeError&spm=1018.2226.3001.4450

使用多GPU训练时总是报错:

    TypeError: Caught TypeError in replica 1 on device 1.
    TypeError: forward() missing 1 required positional argument: 'x'

百度了一下发现是因为我使用了多个显卡,导致在inference阶段,模型和数据不在同一个显卡上,所以后面同时报了:

TypeError: forward() missing 1 required positional argument: 'x'

详情参考这篇文章:https://www.cnblogs.com/YouXiangLiThon/p/13361448.html

 

但百度上面没有查询到解决办法,于是去github上试试有没有相同的问题。结果发现真的有人出现了同样问题,大佬的回答是因为自己的数据集数量不是 batch-size 的整数倍,因此会报错。

标签:TypeError,missing,2522%,required,argument,positional,forward
From: https://www.cnblogs.com/chamie/p/17492696.html

相关文章

  • QA||TypeError: ‘module‘ object is not callable报错怎么debugIHRM接口自动化测试
    unittest.py生成测试报告时执行报错:TypeError:‘module‘objectisnotcallable 代码如下 原因:结合pycharm自动标注和报错信息,分析出应该是HTMLTestRunner使用问题,结合网上查阅说是因为import的问题,所以基本问题定位到了HTMLTestRunner应该导入HTMLTestRunner.py中的HTML......
  • SprintBoot JavaWeb访问提示 Full authentication is required to access this resour
    SprintBoot部署好网站之后访问没有异常,但是配置域名地址至Nginx上时登录请求报错了,经查询是因为项目是前后端分离,请求的路由会加上工程的主路径,所以需要在Nginx多配置一个地址,如Location/{http://localhost:8080/project}location/project/{http://loc......
  • 执行存储过程报错:User does not have access to metadata required to determine stor
    在执行存储过程中,报错详细信息如下:java.sql.SQLException:Userdoesnothaveaccesstometadatarequiredtodeterminestoredprocedureparametertypes.Ifrightscannotbegranted,configureconnectionwith"noAccessToProcedureBodies=true"tohavedrivergener......
  • Vue进阶(幺贰陆):表格复用 TypeError: _self.$scopedSlots.default is not a function解
    (文章目录)一、前言在使用elementUI的el-table组件时,表头应用v-if判断来动态显示,正常来说这样的操作是没有问题的,但是如果在这基础上使用<templateslot-scope="scope">操作的话,表头一旦切换就会报错,错误信息如下:_self.$scopedSlots.defaultisnotafunction二、解决方......
  • Custom directive is missing corresponding SSR transform and will be ignored
    背景最近在给业务组件库集成指令库,将各个项目中常用的指令如一键复制、元素和弹窗拖拽等封装到一起,进行统一发版维护。业务组件库项目架构采用的是pnpm+vite+vue3+vitepress,其中vitepress主要做组件库文档站点同时展示可交互的组件。问题开发运行时指令库demo没有问题,构建编译......
  • @MapKey is required
    @MapKeyisrequired 这就是mybatis的annotation的一个提醒,可以直接忽略,不影响代码编译;为啥出现这种情况,因为我们很烂,sql中返回的对象不愿意定义一个 resultMap,select默认就是返回list,不指定resultMap或者resultType,默认就是组装为map对象返回;注意:一定要指定 resultType="......
  • 关于xfs文件系统-在操作系统中遇到两个uuid一样的-挂载报错-wrong fs type, bad optio
    当操作系统中,出现了两个uuid一样的文件系统(笔者这里是xfs),那么默认就只能挂载成功一个[root@qq-5201351~]#blkid|grepxfs|grep1ea9e784-0692-403c-bed1-bf34a5a86a57/dev/nvme1n1:UUID="1ea9e784-0692-403c-bed1-bf34a5a86a57"BLOCK_SIZE="512"TYPE="xfs"/dev/nvme2......
  • 【pyqt】报错TypeError: decorated slot has no signature compatible with RecorderP
    一、场景  运行pyqt报错TypeError:decoratedslothasnosignaturecompatiblewithRecorderPlayerProxy.sig_mode_update[object] 二、代码@Slot(int)defupdate_mode(self,mode):...... 三、解决方法  将int去除即可  参考链接:p......
  • Solve “missing iconv.dll” issue on Win7 X64
    AfterinstalledthemobilemecontrolpanelonmyWin7X64,themobilemecontrolpanelcannotbelaunchedwitherrormessage"Missingiconv.dll".Evengettingthismessagewhensystembootup.Triedtocopyiconv.dllinto......
  • 报错:[Vue warn]: Error in render: "TypeError: Cannot read properties of undefined
    1.错误详情2.错误分析百度此错误发现,很多人可能忘记在main.js中引入store.js并挂载在vue实例上,或者state单词写错了我审查了很多遍代码,依然报错,读取不到state中的数据,后来想到可能是版本的问题此项目是vue2,要使用vuex3才能正常运行,我安装的时候没有指定版本,直接装的是最新的v......