Skip to content
ml-recall

#effective-batch-size

1 question from Deep Learning Frameworks

Timed test

1 question · 1 min · score and explanations at the end

Take a test
Q 1 / 1Score 0 / 0

Question 1: Short answer

mediumAI-checkedDeep Learning Frameworks

A training loop emulates a batch of 4 examples with two micro-batches of 2, calling backward() on each before a single optimizer step:

import torch

w = torch.tensor(1.0, requires_grad=True)
x = torch.tensor([1.0, 2.0, 3.0, 4.0])

for chunk in x.split(2):              # two micro-batches of 2 examples
    loss = ((w * chunk) ** 2).mean()
    loss.backward()
print(w.grad)

What number does the last line print?

a number