oasjd7
(oasjd7)
1
# input x -> modelA -> modelB -> modelC
optimizer_c = optim.SGD(modelC, ...)
modelA = nn.Linear(10, 10)
modelB = nn.Linear(10, 10)
modelC = nn.Linear(10, 10)
# First phase: Train only modelC.
x = torch.randn(1, 10)
out = modelC(modelB(modelA(x)))
loss_c = ce(out, target)
optimizer_c.zero_grad()
loss_c.backward()
optimizer_c.step()
If I only want to train modelC
, is this the correct code ?
No detach()
or torch.no_grad()
is required ?
sio277
(shoh)
2
This post might help you.