candle icon indicating copy to clipboard operation
candle copied to clipboard

Low time effiency when run cnn on mnist-traning only with CPU

Open Viewer-HX opened this issue 1 year ago • 3 comments

I try to use the following command to train the CNN model with mnist-training example. It works well when training linear and mlp model, but when I config it to train the CNN model, it needs approximately 1hr30mins per epoch. I think it may be abnormal.

cargo run --example mnist-training --features="candle-datasets" cnn --epochs=5 --save=cnn.safetensors

Can you please try it?

Viewer-HX avatar Apr 29 '24 19:04 Viewer-HX

You may want to compile with --release to enable optimizations?

LaurentMazare avatar Apr 29 '24 19:04 LaurentMazare

@LaurentMazare Thanks for the suggestion. It works. With --release, now the training speed reaches around 8min per epoch. Improve a lot. But I'm still confused, (1) why the release mode is so fast? Is the optimization very aggressive? (2)It still is slower than pytorch without GPU (around 50s per epoch.) What is the reason? Here the training only uses CPU, is the algorithm too time-consuming?

Execution command cargo run --example mnist-training --release --features="candle-datasets" cnn --epochs=5 --save=cnn.safetensors

Viewer-HX avatar Apr 29 '24 20:04 Viewer-HX

Hi, I noticed an even weirder scenario, when I scale up the training epochs to 100 epochs, the training significantly decreases the accuracy. training with GPU Commands: cargo run --example mnist-training --release --features="candle-datasets" --features="cuda" cnn --epochs=100 --save=../../Saved_Models/rust_cnn.safetensors

Results: Screenshot 2024-04-29 at 5 54 01 PM Screenshot 2024-04-29 at 5 54 35 PM

Viewer-HX avatar Apr 29 '24 21:04 Viewer-HX