PaddlePaddle / Paddle

PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice (『飞桨』核心框架,深度学习&机器学习高性能单机、分布式训练和跨平台部署)
http://www.paddlepaddle.org/
Apache License 2.0
22.19k stars 5.57k forks source link

非SGD优化器在回传时(optimizer.minimize(loss))报错:InvalidArgumentError: Tensor holds the wrong type, it holds float, but desires to be double. #34920

Closed gongchenting closed 2 years ago

gongchenting commented 3 years ago

使用Adam或者Momentum等优化器时,在optimizer.minimize(loss)这一步会报如下错误: InvalidArgumentError: Tensor holds the wrong type, it holds float, but desires to be double. [Hint: Expected valid == true, but received valid:0 != true:1.] at (/paddle/paddle/fluid/framework/tensor_impl.h:33) [operator < adam > error] 我把loss转换成float64后,它又报错: InvalidArgumentError: Tensor holds the wrong type, it holds double, but desires to be float.

但是,当我把优化器换成SGD后就没问题了,请问这是为什么呢?

环境:paddlepaddle1.7.1,k40

paddle-bot-old[bot] commented 3 years ago

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

wangxicoding commented 3 years ago

网络中有使用到double的地方吗? 可以开一下环境变量 export GLOG_v=3, 看看是执行到具体哪个adam op出的问题 另外再把program打印出来,对照一下

        with open("main_prog.txt", "w") as fout:
            try:
                # compatible with paddle version <= 1.8
                from paddle.fluid.transpiler.details import program_to_code
                program_to_code(fluid.default_main_program(), fout=fout)
            except ImportError:
                fout.write(str(fluid.default_main_program()))