Skip to content

Commit

Permalink
Fix detach again
Browse files Browse the repository at this point in the history
  • Loading branch information
carlo- committed May 14, 2018
1 parent 9714cdb commit 3c669ab
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/main.py
Expand Up @@ -42,17 +42,16 @@

print('===> Building model...')
model = Net().to(device)
model_params = model.parameters()
l1_loss = nn.L1Loss()
optimizer = optim.Adamax(model_params, lr=0.001)
optimizer = optim.Adamax(model.parameters(), lr=0.001)


# ----------------------------------------------------------------------

def detach_all(arg):
"""Wraps hidden states in new Variables, to detach them from their history."""
if type(arg) == torch.Tensor:
arg.detach_() # Variable(arg.data)
if type(arg) == nn.Parameter:
arg.data.detach_() # Variable(arg.data)
else:
for v in arg:
detach_all(v)
Expand Down

0 comments on commit 3c669ab

Please sign in to comment.