caffe icon indicating copy to clipboard operation
caffe copied to clipboard

cuDNN v1 and other factors on CaffeNet convergence

Open yulingzhou opened this issue 12 years ago • 7 comments

I trained the bvlc_reference_caffenet after executing create_imagenet.sh and compute_image_mean.cpp , and there is no error happened. But after 70000 iterations, the accuracy is still 0.001 and the loss keeps around 6.9. Why the training does not work?

yulingzhou avatar Nov 13 '14 12:11 yulingzhou

I've been trying to track down something similar as well, but I'm still collecting evidence. I've been finding that running the validation set at the beginning https://github.com/BVLC/caffe/commit/2bdf516440139ce59f9a45f3cd6c84540e2cb040 has been affecting the convergence of the network during later training. I've also been finding that I get different convergence behavior depending on whether or not I have cuDNN enabled. I'm still trying to track down why those two things might make such a difference.

This is with Amazon EC2 g2.2xlarge instances (GRID 520) with the nvidia 340.29 driver and cuDNN 6.5.18.

kmatzen avatar Nov 13 '14 20:11 kmatzen

The validation set is only used to report the accuracy. After 70000 iterations, the loss keeps around 6.9. Is it possible that there is something wrong with the input data? How can I check it out?

yulingzhou avatar Nov 14 '14 02:11 yulingzhou

@kmatzen I've experimented with and without cuDNN and I made similar observations over the past few weeks. In some cases cuDNN would not converge at all, while deactivating it would yield 'normal' behavior. I haven't been able to find the time to track the problem down. However, I should be able to more or less pinpoint the range of commits that may cause the problem as it was not happening prior a certain date (for me).

beniz avatar Nov 14 '14 10:11 beniz

@beniz I tried a few more things last night with cuDNN. None of these are necessarily incorrect behavior, but it's behavior that's different from the reference implementation which could explain the discrepancy.

(1) Max pooling gives a slightly different gradient. Passes the gradient check. Could just be that they implemented the gradient accumulation in a different order. (2) Convolution is non-deterministic. If you use the reference implementation and print the loss with high precision, then the execution is more or less deterministic (at least for hundreds of iterations), which is great for reproducing experiments. cudnnConvolutionBackwardData is not and the divergence between re-executions is immediate. What's suspicious is that if you execute something such as several iterations of the validation set before training, then the gradient from the cuDNN convolution is affected.

Also, you should set a random_seed in your solver.prototxt if you want to make any comparisons. Finally, you'll need this if you want deterministic re-execution since the validation set is incorrectly using the shared PRNG right now. https://github.com/BVLC/caffe/issues/1430

@yulingzhou I know the validation set is for accuracy. I'm saying that I've been seeing some weird interaction between the validation step and the training step. To check if your dataset is correct, you could download one of the reference models, run the testing procedure, and make sure the accuracy is close to the accuracy reported.

kmatzen avatar Nov 14 '14 15:11 kmatzen

@kmatzen thanks for detailed report. I can corroborate that prediction runs over the same data are non deterministic, this has been on my todolist for a few days already to try to locate the issue. If I were less civilized I would rant against proprietary software just now ;)

beniz avatar Nov 14 '14 15:11 beniz

Thanks for your investigations @kmatzen and @beniz. We are following up with NVIDIA about the reproducibility of cuDNN results.

shelhamer avatar Nov 29 '14 19:11 shelhamer

This should be resolved, but when in doubt for reproducibility one might use the standard CAFFE engine to check a few iterations.

shelhamer avatar Apr 27 '15 08:04 shelhamer