mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

R-package lr_scheduler: different performance between R-package and python for kaggle ndsb1 image classification

Open Lopezurrutia opened this issue 10 years ago • 3 comments

I am "translating" the python code for kaggle-ndsb1 example in mxnet/example/kaggle-ndsb1/ to R. Everything works fine except regarding speed. R is much slower and doesn't seem to be doing as much intensive use of my GPU as python. My gpu is a Tesla K40m . The code I 'm testing for python is the same as in the current example in the master branch. For simplicity in the comparsion I've put two files in my forked repository: run_local.py and run_local.R that contain the same code in python and R and can be executed directly in the kaggle_ndsb1 folder. https://github.com/Gelu74/mxnet/blob/diff_R_python/example/kaggle-ndsb1/run_local.py https://github.com/Gelu74/mxnet/blob/diff_R_python/example/kaggle-ndsb1/run_local.R

I am a bit puzzled and wondering if I am missing something or doing something wrong..

For the R code I get this log: Start training with 1 devices Batch [50] Train-accuracy=0.08625 Batch [100] Train-accuracy=0.0965625 Batch [150] Train-accuracy=0.101041666666667 Batch [200] Train-accuracy=0.105078125 Batch [250] Train-accuracy=0.1086875 Batch [300] Train-accuracy=0.113229166666667 [1] Train-accuracy=0.114681603773585 [1] Validation-accuracy=0.182904411764706 Model checkpoint saved to ./models/sample_net-0001.params Batch [50] Train-accuracy=0.1671875 Batch [100] Train-accuracy=0.17203125 Batch [150] Train-accuracy=0.176145833333333 Batch [200] Train-accuracy=0.18515625 Batch [250] Train-accuracy=0.1890625 Batch [300] Train-accuracy=0.189895833333333 Batch [350] Train-accuracy=0.195848214285714 [2] Train-accuracy=0.196742957746479 [2] Validation-accuracy=0.276880296610169 Model checkpoint saved to ./models/sample_net-0002.params Batch [50] Train-accuracy=0.2715625 Batch [100] Train-accuracy=0.2621875 Batch [150] Train-accuracy=0.260520833333333 Batch [200] Train-accuracy=0.26640625 Batch [250] Train-accuracy=0.2701875 Batch [300] Train-accuracy=0.273020833333333 Batch [350] Train-accuracy=0.277678571428571 [3] Train-accuracy=0.278177668539326 [3] Validation-accuracy=0.347295168067227 Model checkpoint saved to ./models/sample_net-0003.params Batch [50] Train-accuracy=0.3175 Batch [100] Train-accuracy=0.31640625 Batch [150] Train-accuracy=0.315520833333333 Batch [200] Train-accuracy=0.32265625 Batch [250] Train-accuracy=0.3240625 Batch [300] Train-accuracy=0.327916666666667 Batch [350] Train-accuracy=0.3321875 [4] Train-accuracy=0.332746478873239 [4] Validation-accuracy=0.401085805084746 Model checkpoint saved to ./models/sample_net-0004.params

For the python code I get this log which shows similar accuracies:

[23:51:01] src/io/iter_image_recordio.cc:212: ImageRecordIOParser: data48/tr.rec, use 4 threads for decoding.. [23:51:01] src/io/iter_image_recordio.cc:212: ImageRecordIOParser: data48/va.rec, use 4 threads for decoding.. INFO:root:Start training with [gpu(0)] INFO:root:Epoch[0] Batch [50] Speed: 821.90 samples/sec Train-accuracy=0.094687 INFO:root:Epoch[0] Batch [100] Speed: 806.76 samples/sec Train-accuracy=0.100937 INFO:root:Epoch[0] Batch [150] Speed: 805.98 samples/sec Train-accuracy=0.101354 INFO:root:Epoch[0] Batch [200] Speed: 805.48 samples/sec Train-accuracy=0.109609 INFO:root:Epoch[0] Batch [250] Speed: 804.93 samples/sec Train-accuracy=0.117875 INFO:root:Epoch[0] Batch [300] Speed: 806.31 samples/sec Train-accuracy=0.127344 INFO:root:Epoch[0] Batch [350] Speed: 806.03 samples/sec Train-accuracy=0.134509 INFO:root:Epoch[0] Resetting Data Iterator INFO:root:Epoch[0] Train-accuracy=0.135885 INFO:root:Epoch[0] Time cost=28.633 INFO:root:Saved checkpoint to "./models/sample_net-0001.params" INFO:root:Epoch[0] Validation-accuracy=0.215599 INFO:root:Epoch[1] Batch [50] Speed: 821.92 samples/sec Train-accuracy=0.207813 INFO:root:Epoch[1] Batch [100] Speed: 804.75 samples/sec Train-accuracy=0.208594 INFO:root:Epoch[1] Batch [150] Speed: 805.94 samples/sec Train-accuracy=0.216354 INFO:root:Epoch[1] Batch [200] Speed: 806.32 samples/sec Train-accuracy=0.221953 INFO:root:Epoch[1] Batch [250] Speed: 806.65 samples/sec Train-accuracy=0.228437 INFO:root:Epoch[1] Batch [300] Speed: 806.23 samples/sec Train-accuracy=0.235260 INFO:root:Epoch[1] Batch [350] Speed: 804.87 samples/sec Train-accuracy=0.243393 INFO:root:Epoch[1] Resetting Data Iterator INFO:root:Epoch[1] Train-accuracy=0.243442 INFO:root:Epoch[1] Time cost=28.145 INFO:root:Saved checkpoint to "./models/sample_net-0002.params" INFO:root:Epoch[1] Validation-accuracy=0.295551 INFO:root:Epoch[2] Batch [50] Speed: 821.24 samples/sec Train-accuracy=0.288438 INFO:root:Epoch[2] Batch [100] Speed: 805.81 samples/sec Train-accuracy=0.287813 INFO:root:Epoch[2] Batch [150] Speed: 805.84 samples/sec Train-accuracy=0.293333 INFO:root:Epoch[2] Batch [200] Speed: 806.17 samples/sec Train-accuracy=0.298203 INFO:root:Epoch[2] Batch [250] Speed: 805.14 samples/sec Train-accuracy=0.297063 INFO:root:Epoch[2] Batch [300] Speed: 807.21 samples/sec Train-accuracy=0.300833 INFO:root:Epoch[2] Batch [350] Speed: 803.34 samples/sec Train-accuracy=0.306250 INFO:root:Epoch[2] Resetting Data Iterator INFO:root:Epoch[2] Train-accuracy=0.306575 INFO:root:Epoch[2] Time cost=28.234 INFO:root:Saved checkpoint to "./models/sample_net-0003.params" INFO:root:Epoch[2] Validation-accuracy=0.377232 INFO:root:Epoch[3] Batch [50] Speed: 822.06 samples/sec Train-accuracy=0.343750 INFO:root:Epoch[3] Batch [100] Speed: 804.60 samples/sec Train-accuracy=0.344375 INFO:root:Epoch[3] Batch [150] Speed: 805.83 samples/sec Train-accuracy=0.343125 INFO:root:Epoch[3] Batch [200] Speed: 805.49 samples/sec Train-accuracy=0.348906 INFO:root:Epoch[3] Batch [250] Speed: 804.18 samples/sec Train-accuracy=0.349562 INFO:root:Epoch[3] Batch [300] Speed: 805.09 samples/sec Train-accuracy=0.354427 INFO:root:Epoch[3] Batch [350] Speed: 805.44 samples/sec Train-accuracy=0.360312 INFO:root:Epoch[3] Resetting Data Iterator INFO:root:Epoch[3] Train-accuracy=0.361312 INFO:root:Epoch[3] Time cost=28.164 INFO:root:Saved checkpoint to "./models/sample_net-0004.params" INFO:root:Epoch[3] Validation-accuracy=0.406647

But on the other hand , the time taken to train 4 epochs is in python: real 2m7.715s user 3m3.892s sys 0m29.736s

While in R it takes much longer: user system elapsed 342.332 23.260 328.798

With python code I am get this gpu usage: ==============NVSMI LOG==============

Timestamp : Mon Mar 7 22:49:09 2016 Driver Version : 352.39

Attached GPUs : 1 GPU 0000:02:00.0 Utilization Gpu : 98 % Memory : 42 % Encoder : 0 % Decoder : 0 % GPU Utilization Samples Duration : 16.52 sec Number of Samples : 99 Max : 98 % Min : 92 % Avg : 97 % Memory Utilization Samples Duration : 16.52 sec Number of Samples : 99 Max : 42 % Min : 35 % Avg : 40 % ENC Utilization Samples Duration : 16.52 sec Number of Samples : 99 Max : 0 % Min : 0 % Avg : 0 % DEC Utilization Samples Duration : 16.52 sec Number of Samples : 99 Max : 0 % Min : 0 % Avg : 0 %

While with R code I get a lower GPU utilization:

==============NVSMI LOG==============

Timestamp : Mon Mar 7 23:26:54 2016 Driver Version : 352.39

Attached GPUs : 1 GPU 0000:02:00.0 Utilization Gpu : 48 % Memory : 19 % Encoder : 0 % Decoder : 0 % GPU Utilization Samples Duration : 16.51 sec Number of Samples : 99 Max : 94 % Min : 1 % Avg : 45 % Memory Utilization Samples Duration : 16.51 sec Number of Samples : 99 Max : 36 % Min : 0 % Avg : 17 % ENC Utilization Samples Duration : 16.51 sec Number of Samples : 99 Max : 0 % Min : 0 % Avg : 0 % DEC Utilization Samples Duration : 16.51 sec Number of Samples : 99 Max : 0 % Min : 0 % Avg : 0 %

Lopezurrutia avatar Mar 07 '16 21:03 Lopezurrutia

My PR is proof-of-concept of lr_scheduler. It works, but not perfect. There is one parameter I am still digging into, i.e. epoch_size. In mxnet image-classification example (see context) , python implementation has supported specific epoch_size parameter (See context) while my PR did not.

Puriney avatar Mar 07 '16 22:03 Puriney

OK, you are right, if I do not use the lr_scheduler I get similar performance. I reference here your pull request for the records. https://github.com/dmlc/mxnet/issues/1323 https://github.com/dmlc/mxnet/commit/19959849e8793b20c4642d290c798c27f516140c Thanks!

Lopezurrutia avatar Mar 08 '16 09:03 Lopezurrutia

Close this now. Feel free to reopen.

thirdwing avatar Jul 05 '16 17:07 thirdwing