Skip to content
DeepForgeby svx
All problems
EasyDeep Learningdl-066

Gradient Accumulation Steps

Problem

Compute the number of optimizer steps per epoch with gradient accumulation: first micro_batches = ceil(total_samples / batch_size), then optimizer_steps = ceil(micro_batches / accum_steps).

The signature is grad_accum_steps(total_samples, batch_size, accum_steps). Return an integer.

Hint

Round up twice: once for micro-batches and once for accumulation groups.

Test cases

case 1
in: [1000,10,4]
expected: 25
case 2
in: [1001,10,4]
expected: 26
case 3
in: [8,4,2]
expected: 1
case 4
in: [0,10,4]
expected: 0
case 5
in: [7,3,2]
expected: 2
Starter codePython
def grad_accum_steps(total_samples, batch_size, accum_steps):
    # Your code here
    pass

5 test cases · run your code against them in the editor