Debugging ML Code
Some ML coding rounds hand you code instead of a blank file. The code runs, or nearly runs, but tests fail, the
loss won't fall or a NaN appears, and your job is to find the root causes and fix them in the time left.
ML code is a good place to plant bugs because most of them don't crash: a wrong axis gives a number, just not the
right one.
Anthropic's Fellows program used a 60-minute CodeSignal round of Python debugging on an existing NumPy codebase
with failing unit tests, where the candidate listed the root causes as state, call order, caching, randomness and
mutation (the question); an Anthropic research engineer round
had candidates debug GRPO training code that produced NaNs
(the question); and a Waymo ML systems onsite had a debugging round
on NumPy tensor helpers with an aliasing bug, a missing axis=1 and a truncated remainder
(the question).
How to Work the Round
Treat it as an investigation, not a reading exercise. Read the tests first, because they are the specification: they tell you what each function is supposed to return. Then run them, pick one failure, and reproduce it on the smallest input you can. Only then read the code it exercises, line by line, writing down the shape of every array.
Three rules keep you from wasting the hour. First, fix root causes, not symptoms: one wrong axis can fail five tests, and patching each test's case separately leaves the bug in place; the Anthropic candidate's advice was the same, not to over-patch for a single test. Second, change one thing at a time and rerun, so you know which change fixed what. Third, say each hypothesis out loud before you test it ("I think the mask hides the diagonal"), since the interviewer is grading your process as much as the fixes. The sections below are the bug families that come up most, each with a planted bug and its fix.