... # your code here
with autocast():
    out_first = model(images)
    loss = your_loss_func(inputs, out_first) # use this loss for calculations
scaler.scale(loss).backward()
optimizer.first_step(zero_grad=True)

with autocast():
    out_second = model(images)
    loss_second = your_loss_func(inputs, out_second)
scaler.scale(loss_second).backward()
optimizer.second_step(zero_grad=True)
scaler.update()
... # your code here

can you try this?