Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Avoid future warning #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions torchqrnn/forget_mult.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ def forward(self, f, x, hidden_init=None, use_cuda=True):
loss = resulta.pow(2).sum()
loss.backward()

print('Result =', loss.data[0])
print('X grad =', a.grad.mean().data[0])
print('Forget grad =', forget.grad.mean().data[0])
print('Last H grad =', last_h.grad.mean().data[0])
print('Result =', loss.item())
print('X grad =', a.grad.mean().item())
print('Forget grad =', forget.grad.mean().item())
print('Last H grad =', last_h.grad.mean().item())

x_grad_copy = a.grad.clone()

Expand All @@ -222,20 +222,20 @@ def forward(self, f, x, hidden_init=None, use_cuda=True):
loss = resultb.pow(2).sum()
loss.backward()

print('Result =', loss.data[0])
print('X grad =', a.grad.mean().data[0])
print('Forget grad =', forget.grad.mean().data[0])
print('Last H grad =', last_h.grad.mean().data[0])
print('Result =', loss.item())
print('X grad =', a.grad.mean().item())
print('Forget grad =', forget.grad.mean().item())
print('Last H grad =', last_h.grad.mean().item())

###

print()
print('=-=-' * 5)
print('(Xgrad - Xgrad).sum() =', (x_grad_copy - a.grad).sum().data[0])
print('(Xgrad - Xgrad).sum() =', (x_grad_copy - a.grad).sum().item())
print('Residual error for result')
print('=-=-' * 5)
residual = (resulta - resultb)
print(residual.abs().sum().data[0])
print(residual.abs().sum().item())

# Had to loosen gradient checking, potentially due to general floating point badness?
from torch.autograd import gradcheck
Expand Down
2 changes: 1 addition & 1 deletion torchqrnn/qrnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def forward(self, input, hidden=None):
qrnn.use_cuda = False
Z, _ = qrnn(X)

diff = (Y - Z).sum().data[0]
diff = (Y - Z).sum().item()
print('Total difference between QRNN(use_cuda=True) and QRNN(use_cuda=False) results:', diff)
assert diff < 1e-5, 'CUDA and non-CUDA QRNN layers return different results'

Expand Down