How to get the df_do as we used in torch7
<SCODE>     optimizer.zero_grad()
     output = model(data)
     loss = criterion(output, target)
     loss.backward()
     optimizer.step()
<ECODE> So all the network is back-propagated when I call loss.backward() ?
dafang_He
fmassa
Thanks!
dafang_He
Thanks!
dafang_He
You need to make the hook a closure - just redefine it at every step, and use the data in its body: <SCODE>optimizer.zero_grad()

output = model(data)
def hook(d_output):
    return d_output * data.mean() # you can use the data here
output.register_hook(hook)

loss = criterion(output, target)
loss.backward()
optimizer.step()
<ECODE>
apaszke