Hi,
I think optimizer should be defined before the forward function.
optimizer = optim.Adam(model.parameters(), lr=opt.lr)
optimizer.zero_grad()

out = model(data)
loss = criterion_b(out, label) 
loss.backward()
optimizer.step()

Hope this helps.