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 10 / 10 · Domain 4: Data Handling

A dataset has 10 samples and a DataLoader uses batch_size=3 with drop_last=True. How many batches does one epoch yield, and what happens to the last sample?

  1. 4 batches; the last batch is smaller and holds one sample
  2. 4 batches; the last sample is repeated to fill the batch
  3. 3 batches; the incomplete last batch is dropped
  4. 3 batches; the last sample is moved to the start of the next epoch
Show the answer and explanation

Answer: C

Why this is correct
drop_last controls what happens when the dataset size is not divisible by the batch size. The page says that, when set to True, the last incomplete batch is dropped; if False, the last batch will be smaller. Ten samples with batch_size=3 form three full batches and one leftover sample. The BatchSampler example on the page shows the same data both ways: with drop_last=False it yields [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]], and with drop_last=True it yields [[0, 1, 2], [3, 4, 5], [6, 7, 8]].

Why the other options are wrong
"4 batches; the last batch is smaller and holds one sample" … That is the result with drop_last=False. The page says that if drop_last is False and the dataset size is not divisible by the batch size, the last batch will be smaller.
"4 batches; the last sample is repeated to fill the batch" … The page describes two outcomes only: the incomplete last batch is dropped, or it stays smaller. It does not describe repeating samples to fill a batch.
"3 batches; the last sample is moved to the start of the next epoch" … The page says drop_last=True drops the last incomplete batch. The BatchSampler example with drop_last=True yields three batches of three indices and leaves index 9 out.

Key points
drop_last=True makes every batch the same size, at the price of skipping the leftover samples of the epoch.

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

See the full practice set