特殊的bug:element 0 of tensors does not require grad and does not have a grad_fn

这篇具有很好参考价值的文章主要介绍了特殊的bug:element 0 of tensors does not require grad and does not have a grad_fn。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

很多帖子都说了,设置requires_grad_()就行。
但是我这次遇到的不一样,设置了都不行。

我是这种情况,在前面设置了torch.no_grad():,又在这个的作用域下进行了requires_grad_(),这是不起作用的。

简单版:

with torch.no_grad():
            model.eval()
            pos_embed = model(homo_data.x, homo_data.edge_index)
						....            
            pos_embed.requires_grad_()# 不起作用
            ....

这样子直接看,傻瓜都不会犯错。而我这个就比较隐蔽了。。。
我的:

# file1.py
with torch.no_grad():
    pos_embed = model(homo_data.x, homo_data.edge_index)
    ...
    fun_A(pos_embed)
    ...
# file2.py
def fun_A(x):
    ...
    fun_B(x)
    ...
# file3.py
def fun_B(x):
	...
  x.requires_grad_() # 由于x是在torch.no_grad中传过来的,所以不起作用
  ...

就这样一直会报错element 0 of tensors does not require grad and does not have a grad_fn

太坑了

大家引以为鉴,看看出现这个情况没。文章来源地址https://www.toymoban.com/news/detail-769287.html

到了这里,关于特殊的bug:element 0 of tensors does not require grad and does not have a grad_fn的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • MySQL问题:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

    MySQL问题:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

    当修改mysql密码时,如果密码设置的太简单的话,会提示报错: mysql安装了validate_password密码校验插件,导致要修改的密码不符合密码策略的要求。 策略说明 思路: 1、遵从策略 2、修改策略 3、策略失效 如输入的密码为: Wxq3012@ 修改全局变量,但 重启mysql 后会失效 在设置密

    2024年02月07日
    浏览(15)
  • 端口映射问题:Bad Request This combination of host and port requires TLS.

    错误信息: 遇到上面的错误信息:如果是通过域名访问,则该域名后配置的转发端口映射错误。 如果是通过ip+端口 或者 域名+端口访问,则为你端口填写错误。 我出现过若干次以上问题,所以将其记录,原因为在配置端口时,为服务配置了一个server port 一个http port。但在访

    2024年02月11日
    浏览(9)
  • Win11预览体验计划显示Your PC does not meet the minimum hardware requirements...的解决方案

    Win11预览体验计划显示Your PC does not meet the minimum hardware requirements...的解决方案

    某一天你心血来潮,打算参与Win11 预览体验计划,但体验计划页面却显示“Your PC does not meet the minimum hardware requirements for Windows11…”。 一种解决思路: 去以下网页下载Offline Insider Enroll软件,管理员权限运行后,选择你想参与的体验计划通道。 Offline Insider Enroll https://github.

    2024年02月04日
    浏览(13)
  • 运行错误:view size is not compatible with input tensor‘s size and stride (at least

    运行错误:view size is not compatible with input tensor‘s size and stride (at least

    python运行报错: view size is not compatible with input tensor\\\'s size and stride (at least one dimension spans acros 出现这个原因主要就是因为v iew()需要 Tensor 中的元素地址是连续的,因为可能出现Tensor不连续的情况,修改为: 在.view前加 .contiguous() ,使其变为连续就ok。    

    2024年02月11日
    浏览(9)
  • Error [ERR_REQUIRE_ESM]: require() of ES Module ...not supported.

    Error [ERR_REQUIRE_ESM]: require() of ES Module ...not supported.

     学习使用gulp的del删除任务时出现require() of ES Module 问题 报的错误如下所示: 查看对应代码,是引入del插件位置的错误,const del = require(\\\'del\\\') ,经学习,发现是npm 默认安装的del插件版本为7.0.0,版本太高导致,因此 问题解决 参考:require() of ES Module错误提示怎么解决?_Only

    2024年02月11日
    浏览(8)
  • 解决ES集群启动失败 skipping cluster bootstrapping as local node does not match bootstrap requirements:[xxx]

    异常信息 这个错误信息网上有很多解决方案,但都没说明一点,就是由于账号密码配置而导致的连接失败 正常根据网上资源和官方文档介绍后,我们会进行以下配置 原配置信息 我们目前集群信息是一主一从,没办法白嫖的阿里云机子才 2g 只能这样子配置 集群名称: es-kk

    2024年02月04日
    浏览(23)
  • kubernetes部署应用时从harbor拉取镜像失败:repository does not exist or may require ‘docker login‘

    问题描述: kubernetes部署应用时,pod启动失败,通过kubectl describe pod查看失败原因类似下面的错误: Failed to pull image \\\"xxxx/oneapi-2/authtenantserver:15\\\": rpc error: code = Unknown desc = Error response from daemon: pull access denied for xxxx/oneapi-2/authtenantserver, repository does not exist or may require \\\'docker login\\\'

    2024年02月16日
    浏览(9)
  • postman 请求接口返回 Bad Request This combination of host and port requires TLS.

    postman 请求接口返回 Bad Request This combination of host and port requires TLS.

    接手一个新项目,下载下来之后,启动一切正常但是访问一直报错,于是在网上查找解决方案,开始说是http改为https 结果postman直接报错了(下图),提示:SSL错误:主机名/IP与证书的别名不匹配 当时没有注意,其实只要点击一下这个红字就自动把ssl证书验证关了。 后来又百

    2024年02月11日
    浏览(21)
  • 【BUG历险记】vivado报错:binding vhdl entity ‘ xxxxx ‘does not have port ‘ xxxxx ‘解决方案

    【BUG历险记】vivado报错:binding vhdl entity ‘ xxxxx ‘does not have port ‘ xxxxx ‘解决方案

    🏔【BUG历险记】 vivado报错:binding vhdl entity xxxxx \\\' does not have port \\\' xxxxx \\\'解决方案 我在编写雷达的脉冲压缩仿真时,先例化了FFT和复数乘法器,并仿真验证通过了;再例化IFFT,结果仿真时出现错误,前面仿真通过的复数乘法器报错。说是没有aclk引脚,实际上是有的。 更改代

    2024年02月12日
    浏览(10)
  • 记录:Error [ERR_REQUIRE_ESM]: require() of ES Module not supported.报错

    记录:Error [ERR_REQUIRE_ESM]: require() of ES Module not supported.报错

    记录:在js中导入jsencrypt模块时,出现Error [ERR_REQUIRE_ESM]: require() of ES Module xxxxx from xxxxx not supported.报错 代码: 报错: 解决办法: 将提示语翻译过来: 将jsencrypt.js重命名为以.cjs结尾,将所需代码更改为使用所有CommonJS模块中可用的dynamicimport(),或将D:yj_pjno中的“type”:

    2024年02月11日
    浏览(9)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包