LHD: Early Detection of Silent Training Failures in Neural Networks

TL;DR

Training takes the majority of the compute spent on a large model. As models advance, the compute needed for training increases exponentially, because each generation has more parameters and learns from more data, which creates a compounding effect. Most runs are also experimental, so a team often trains many times before shipping a viable model. Together, these facts make one kind of bug expensive to deal with, namely the silent failure. For instance, a layer in a convolutional neural network may stop learning while the outputs look normal. The failure of such a run shows only after the time and compute are used up. Layer Health Diagnostics, or LHD, checks each layer during training and stops a run when a layer breaks. Across 885 training runs on three networks, we detected 97.7% of the 470 planted faults with LHD, between 95.3% and 100% on each network, including all 105 with a loss of 2 points or more in accuracy, and we flagged 6 of the 150 healthy runs.

I began this work after one such silent failure in a project of my own, which I describe here. I obtained 76% accuracy with SignNet, a small convolutional network for the GTSRB dataset of German traffic signs, and spent weeks on tuning before identifying the cause. A single convolutional layer was omitted from the optimizer, so the weights of that layer were never updated. After the omission was corrected, the accuracy of the same network was 87%, and because there was no error in either run, the only indicator of the bug was an accuracy 11 points below the corrected result.

Layer Health Diagnostics

The four stages of LHD are recording, calibration, detection, and diagnosis. During a run, the five signals in the table below are recorded for each layer after every epoch. The output of a dead unit is zero for every input of a fixed probe batch of 256 examples, and an always-dead unit is a unit that was dead before training and at every epoch since.

Signal Definition Fault indicated by the signal
Weight change Movement of the weights of a layer relative to their size A layer whose weights are never updated
Gradient norm Size of the gradient of a layer for one batch A layer with a gradient close to zero
Weight norm Overall size of the weights of a layer Weights far larger than in healthy runs
Dead-unit fraction Share of units with an output of zero for every probe input Units with zero output that were active earlier
Always-dead fraction Share of units that were dead at every measurement Units with zero output since before training

During calibration, a healthy range is measured for every signal, layer, and epoch on 20 healthy runs of the same network. The range is bounded by the lowest and the highest value across those runs and is then widened, so that a detection is not raised by ordinary noise. The lower bound is multiplied by 0.5, and the upper bound is multiplied by 1.5 and raised by 0.05. A lower bound above zero is therefore still above zero after widening, so a weight change of exactly zero is always outside the healthy range. Because calibration is performed on healthy runs only, no faulty run is needed for the setup.

A detection is raised when a signal is outside the healthy range for three consecutive epochs. The run is then terminated, and the layer is reported together with a probable cause. The cause is determined from the pattern of the signals at the detection, and the patterns are checked in the order of the table below.

Signal pattern at the detection Reported cause
Any signal is not a finite number Diverged training
Dead-unit fraction or always-dead fraction above the healthy range Dead units
Weight change below the range, gradient norm inside or above the range Frozen layer
Weight change and gradient norm both below the range Vanishing gradient
Weight norm above the range Weight runaway
Any other pattern Unrecognized cause

One run with a frozen-layer fault in the second convolutional layer of the CNN is shown in Figure 1. The weight change of that layer is exactly 0 from the first epoch, which is below the healthy range, while validation accuracy is inside the healthy range for the entire run. A detection was raised at epoch 3, and a frozen layer was reported as the cause, whereas no detection was recorded for the accuracy baseline in 15 epochs.

CNN on GTSRB with conv2 frozen

Weight change of conv2

00.861.62 151015 Epoch Detection

Validation accuracy

26%56%83% 151015 Epoch Detection
LHD
Detection at epoch 3 in conv2, a frozen-layer fault
Accuracy baseline
No detection in 15 epochs
  • Weight change below the healthy range
  • Weight norm within the healthy range
  • Gradient norm above the healthy range
  • Dead-unit fraction within the healthy range
  • Always-dead fraction within the healthy range
Figure 1. Five saved runs from the evaluation, each replayed through LHD, with the healthy range drawn as a band and the detection epoch drawn as a dashed line.

Experimental setup

The evaluation was conducted on the three networks in the table below. Two networks are image classifiers with dense and convolutional layers, and the third is a next character predictor with attention layers. I trained 885 runs in total and calibrated the healthy ranges of each network on 20 healthy runs. A fault was then injected into 470 runs, 50 held-out healthy runs per network were reserved to measure false positives, and the remaining runs were used to test other kinds of faults.

Network Dataset Parameters Watched layers Epochs per run
Fully connected network Fashion-MNIST 242,762 4 20
CNN GTSRB traffic signs 41,659 5 15
Character transformer Tiny Shakespeare 112,577 11 15

Exactly one fault was injected into each faulty run, either a frozen-layer fault or a dead-unit fault. In a frozen-layer fault, the weights of one layer are never updated, as in the SignNet bug. In a dead-unit fault, 10%, 25%, or 50% of the units in one layer are forced to an output of zero. For the accuracy baseline, the validation accuracy curve of every run is tracked, and a detection is recorded when validation accuracy is below the lowest healthy value for three consecutive epochs.

I first conducted the entire evaluation with a four-signal variant without the always-dead fraction. After examining the false negatives of that variant, I added the always-dead fraction as the fifth signal. I set the rule for that signal on runs that were never scored, and I then scored every run once more. Both variants are therefore shown side by side with the accuracy baseline in the first results table.

Results

LHD Four-signal variant Accuracy baseline
Detected faulty runs, out of 470 459 411 166
Detected, out of the 105 runs with an accuracy loss of 2 points or more 105 94 60
False positives, out of 150 healthy runs 6 3 7

According to the table, 459 of the 470 faulty runs, or 98%, were detected with LHD, against 166 with the accuracy baseline. The median detection epoch was 3 on every network, which is one fifth of a 15 epoch run and less than one sixth of a 20 epoch run. On the 165 runs that were detected by both methods, the detection from LHD was 4.9 epochs earlier on average than the detection from the accuracy baseline.

Of the 166 faulty runs detected with the accuracy baseline, 165 were also detected with LHD. A total of 294 faulty runs were therefore detected with LHD alone, and 1 run was detected with the accuracy baseline alone. The difference is clearest on the character transformer, where the accuracy loss was under 2 points in all 170 faulty runs and all 170 were still detected with LHD.

Network Detected faulty runs Reports with the correct layer False positives
Fully connected network 127 of 130 127 of 127 1 of 50
CNN 162 of 170 155 of 162 5 of 50
Character transformer 170 of 170 170 of 170 0 of 50

The detection rate was similar across all three networks, with 97.7% on the fully connected network, 95.3% on the CNN, and 100% on the character transformer. In 452 of the 459 detections, or 98%, the reported layer was the layer with the injected fault. All 7 detections with a different reported layer were frozen-layer faults in the CNN.

Injected fault Runs Detected by LHD
Frozen-layer fault 200 200
Dead-unit fault on 50% of the units 90 90
Dead-unit fault on 25% of the units 90 90
Dead-unit fault on 10% of the units 90 79

Every frozen-layer fault and every dead-unit fault on 25% or 50% of the units in a layer was detected with LHD. For dead-unit faults overall, 259 of 270 runs, or 96%, were detected with LHD, with 6 false positives. With the default rule of SageMaker Debugger, 40% of the same faults were detected, with 22 false positives. Dead units are also present in healthy networks at rates that are very different between layers, so no single threshold is correct for every layer.

The second row of the first table is restricted to the faults with the largest effect on the final model. In 223 of the 470 faulty runs, the accuracy loss was under half a point, which is too small to observe in the accuracy curve. In 105 runs the accuracy loss was 2 points or more, and all 105 of those runs were detected with LHD, against 94 with the four-signal variant and 60 with the accuracy baseline. Of those 105 runs, 95 were CNN runs and 10 were runs of the fully connected network.

The difference between the two variants is due to the fifth signal, with 48 additional detections at the cost of 3 additional false positives. The time spent on recording the four original signals was 2.2% of the run time on the CNN, 5.9% on the character transformer, and 11.6% on the fully connected network.

Limitations

The results of this study are subject to the five limitations listed below. First, the full method is not needed for frozen-layer faults, including the original SignNet bug. With a zero-change test, in which each layer is checked only for a weight change of exactly zero, all 200 frozen layers were identified at epoch 1 with no false positives, two epochs ahead of LHD. The same 200 faults were also detected with LHD, so the zero-change test is simply the faster option for this one fault type, while the calibrated healthy ranges are still necessary for dead-unit faults.

Second, the smallest dead-unit fault is below the sensitivity of LHD. All 11 false negatives were runs with a dead-unit fault on 10% of the units in a layer, and the accuracy loss was under 2 points in every one of those runs. Eight of the 11 were in the dense layer of the CNN, because between 5% and 19% of the units in that layer were always dead even in healthy runs, and only 2 of the 10 runs with that fault there were detected.

Third, there were 6 false positives with LHD on the 150 healthy runs, one fewer than with the accuracy baseline. Three are due to the first four signals and three are due to the always-dead fraction. Two of the six were in a CNN layer with only 16 filters, where a single dead filter is already outside the healthy range. Two more were flagged because fewer units were always dead than in any of the 20 calibration runs, which is not a fault.

Fourth, every fault in this study was injected and made visible in the recorded signals, so an evaluation on naturally occurring bugs is the next step. I added the always-dead fraction after examining the false negatives of the four-signal variant, and every unit in a dead-unit fault was disabled before training, which is the case that this signal was designed for. The gain from the fifth signal may therefore be smaller on other bugs. For example, none of the 5 runs in which half of the units in the dense layer of the CNN were disabled at epoch 6 was detected with either variant.

Fifth, no fault was injected into the training data, so label errors and similar data faults are still untested.

Related work

Comparable signals are already used in AutoTrainer, DeepDiagnosis, and SageMaker Debugger, and the same signals are displayed on the dashboard of wandb during training. In the first three systems the thresholds are preset, whereas in LHD the healthy range of each layer is calibrated on healthy runs of the same network.

Code and data

The code, every saved run, and every table of this study are available in the repo.

Who did what

I came up with the idea for LHD and designed all of the experiments. I wrote the four original signals, the detector, and the diagnosis by hand from function outlines and docstrings by Claude, an AI model from Anthropic. The experiment, analysis, and figure code was written by the same model, which was also used to run the training runs, to extend my four signals with a fifth, and to draft this post. I directed the project, decided what to test and change, and I'm responsible for all of its content.