PyTorch Certified Associate (PTCA) Practice Questions

PyTorch Certified Associate exam preparation

PyTorch Certified Associate (PTCA) practice questions in English: 180 questions with explanations. The mock exam has 60 questions and 120 minutes.

PyTorch Certified Associate (PTCA) free question 7 / 10 · Domain 3: Performance & Optimization

A training loop uses torch.autocast on a CUDA device. Which part of one iteration does the torch.amp page say the autocast region should cover?

  1. The model forward pass alone, with the loss computed in a separate region after it
  2. The whole iteration, including optimizer.step() and zero_grad()
  3. The forward pass, including the loss computation, and the region ends before backward()
  4. The forward pass and the call to backward() together, to give the gradients the chosen dtypes
Show the answer and explanation

Answer: C

Why this is correct
The torch.autocast entry says autocast should wrap only the forward pass(es) of your network, including the loss computation(s). Backward passes under autocast are not recommended. The CUDA example on the page follows this: the with torch.autocast(device_type="cuda") block holds output = model(input) and loss = loss_fn(output, target), the context manager is exited before backward(), and loss.backward() and optimizer.step() run outside it.

Why the other options are wrong
"The forward pass and the call to backward() together, to give the gradients the chosen dtypes" … The page says backward passes under autocast are not recommended, so the region should end before backward() is called.
"The whole iteration, including optimizer.step() and zero_grad()" … The page limits the region to the forward pass and the loss. Optimizer work on the parameters is not part of what autocast should wrap.
"The model forward pass alone, with the loss computed in a separate region after it" … The page includes the loss computation in the wrapped part. Its example computes the output and the loss inside the same with-block.

Where people trip
Put the forward pass and the loss inside the autocast block, then leave the block before calling backward().

Go to the PyTorch Certified Associate (PTCA) practice app (10 free questions; purchase unlocks all questions)

See the full practice set