-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
模型参数无法更新 #44426
Comments
您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档、常见问题、历史Issue、AI社区来寻求解答。祝您生活愉快~ 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 API,FAQ,Github Issue and AI community to get the answer.Have a nice day! |
@aixuxian 您好,我已经收到你的信息反馈,请整理一下排版?模型训练那里排版出问题了,我无法直接复制进行复现。 |
@GuoxiaWang 抱歉,刚才没找到方法,把导入的库也贴进来
|
如果可以是否能贴一个完整可以跑的代码?数据可以用random 数据。 另外是否也可以提供一份 torch 代码?好排查。 我直观上看这份代码写的是没有问题的,但是实际跑出来确实有问题,所以需要我运行起来才能排查。 |
@GuoxiaWang
|
x1 = paddle.to_tensor(pywt.dwt(inputs1.numpy(), 'haar'), dtype='float32', stop_gradient=False) x1 的 shape 是什么? |
都是[2, 512, 64, 500] |
llb 的 shape 是什么? 里面的值是什么?是否可以提供一下?我需要跑起来代码 |
Tensor(shape=[512], dtype=int64, place=Place(gpu_pinned), stop_gradient=True, |
有没有什么方法我可以把我在Paddle AIStudio里的notebook发给您? |
应该是跟优化器相关,adam 走一个 opt.step 后梯度就为 0 了。这可能跟 adam 有关,我们再找到具体问题。
|
@GuoxiaWang 是的,我改用SGD之后,参数确实更新了。感谢感谢!!! |
请提出你的问题 Please ask your question
使用V100 [16G的环境,模型构建和运行代码如下:
模型构建
`class Representation_Net(nn.Layer):
模型训练:
model = Representation_Net() llr = 0.1 optim = paddle.optimizer.Adam(learning_rate=llr, parameters=model.parameters()) model.train() loss_fun = paddle.nn.CrossEntropyLoss() t1 = time.time() for epoch in range(2): for num, (edt1, edt2, llb) in enumerate(train_loader): # print(llb) # t1 = time.time() # print(llb) x0 = model(edt1, edt2) # paddle.Model(model). loss = loss_fun(x0, llb) loss.backward() for para in model.linear1.parameters(): print(para.name, ":", para.grad.numpy()[0][:5]) print(para.name, ":", para.numpy()[0][:5]) break if num % 10 == 0: # acc, f1, pre, rec = metrics_print(x0, llb) print("{}---epoch: {}, batch_id: {}, loss is: {}".format(time.time()-t1, epoch, num, loss.numpy())) optim.step() optim.clear_grad()
下面是运行了几个step之后的打印信息:
linear_0.w_0 : [ 1.4867793e-05 -1.0415246e-05 1.3343290e-04 2.0477468e-04
-1.7027040e-04]
linear_0.w_0 : [ 0.01032601 -0.00485409 0.00241758 0.00228845 -0.0067165 ]
3.926401138305664---epoch: 0, batch_id: 0, loss is: [0.6963549]
linear_0.w_0 : [-2.3965185e-06 3.9633629e-05 9.2653732e-05 -6.8230751e-05
9.3980285e-05]
linear_0.w_0 : [ 0.01032601 -0.00485409 0.00241758 0.00228845 -0.0067165 ]
linear_0.w_0 : [ 1.3629116e-05 -6.8708534e-05 -1.8428715e-05 5.0045915e-06
-1.5834516e-05]
linear_0.w_0 : [ 0.01032601 -0.00485409 0.00241758 0.00228845 -0.0067165 ]
linear_0.w_0 : [-8.1593771e-06 7.6985467e-05 2.8302988e-05 -7.5435062e-05
-9.5136711e-05]
linear_0.w_0 : [ 0.01032601 -0.00485409 0.00241758 0.00228845 -0.0067165 ]
linear_0.w_0 : [ 1.1492494e-06 -1.5806514e-04 5.4077671e-05 1.1575944e-04
-8.0573343e-05]
linear_0.w_0 : [ 0.01032601 -0.00485409 0.00241758 0.00228845 -0.0067165 ]
linear_0.w_0 : [-1.4700053e-05 -1.4874062e-05 -1.4286905e-05 -1.0297184e-04
1.1741554e-04]
linear_0.w_0 : [ 0.01032601 -0.00485409 0.00241758 0.00228845 -0.0067165 ]
linear_0.w_0 : [-3.0369796e-05 5.5571427e-06 1.2763042e-05 4.1698524e-05
-5.2746847e-05]
linear_0.w_0 : [ 0.01032601 -0.00485409 0.00241758 0.00228845 -0.0067165 ]
linear_0.w_0 : [ 2.5099731e-05 -8.0320642e-05 1.3445060e-05 9.5332878e-05
-2.4350986e-04]
linear_0.w_0 : [ 0.01032601 -0.00485409 0.00241758 0.00228845 -0.0067165 ]
linear_0.w_0 : [-3.3261884e-05 -1.2341246e-04 -4.1538180e-05 -8.0625352e-05
这个问题我搜索了没找到什么好的解决办法,然后就使用Pytorch实现了,在自己电脑上运行,发现参数参数是可以正常更新的!!
希望大佬们给指个方向!!
The text was updated successfully, but these errors were encountered: