Explore Library
Code QuizAdvanced

AMP Mixed-Precision Backward

Spot the mistake in this automatic mixed-precision training step.

Codepython
scaler = torch.cuda.amp.GradScaler()
optimizer.zero_grad()
with torch.cuda.amp.autocast():
    output = model(x)
    loss = criterion(output, y)
loss.backward()
scaler.step(optimizer)
scaler.update()

What is the bug in this mixed-precision training step?