TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
←

60. Debug: BatchNorm at Inference

Easy

The function below applies batch normalization, but has a bug when called in evaluation mode (training=False).

Signature: def buggy_batchnorm(x, gamma, beta, running_mean, running_var, training=False, eps=1e-5)

The contract: running_mean and running_var are the statistics accumulated during training and passed in by the caller. The output of a single sample at eval time must not depend on which other samples happen to share its batch.

Find and fix the bug.

Math

x^=σ2+ϵ​x−μ​,y=γx^+β

Asked at

NumPy

import numpy as np

 

def buggy_batchnorm(...):

    pass

🔒

Premium problem

Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.

Upgrade to PremiumBack to problems

Already premium?