Paddle paddle.autograd.grad not working

gajydyqb  于 2021-11-30  发布在  Java
关注(0)|答案(1)|浏览(367)

Hey, I am working to convert a torch work to paddle. I need to use paddle.autograd.grad to update gradients against some variables. However, it is not working while it is working for another group of vectors.

The code snippet is as following,

for i in range(option['g_l_steps']):
                gen_res = model(images, z, depths)
                g_log_lkhd = 1.0 / (2.0 * option['g_llhd_sigma'] * option['g_llhd_sigma']) * mse_loss(
                    F.sigmoid(gen_res[0]), gts)
                en = ebm_model(z)
                #z_grad_g = g_log_lkhd.grad[0]
                z_grad_g = g_log_lkhd.grad(z)
                z_grad_g = paddle.autograd.grad(g_log_lkhd, z)[0]
                z_grad_e = paddle.autograd.grad(en.sum(), z)[0]

                z.data = z.data - 0.5 * option['g_l_step_size'] * option['g_l_step_size'] * (
                            z_grad_g + z_grad_e + 1.0 / (option['e_prior_sig'] * option['e_prior_sig']) * z.data)
                z.data += option['g_l_step_size'] * fluid.layers.gaussian_random_batch_size_like(z, z.shape).data

May you help?
Thanks,

91zkwejq

91zkwejq1#

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网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!

相关问题