train_on_batch vs fit which is faster?

3,046 views
Skip to first unread message

Jinwon An

unread,
Sep 3, 2015, 8:28:05 AM9/3/15
to Keras-users
Hi, I previously asked about the batch training mode so that I can work with data that can't fit into the main memory of the GPU. Now I'm curious about which training mode is faster, model.train_on_batch or model.fit if the data can go into the main memory. 

I first thought model.fit would be faster due to optimization in the code(that I expected) but it seems that model.train_on_batch is much faster.

for about 1million number of data, model.train_on_batch took about 5 minutes(I made about 100 batches) while the model.fit took 20 minutes.

Is this a problem that is specific to what datasets I use and what models I implement?

Or is there a general answer to this question?(That a certain training mode is faster than the other)

François Chollet

unread,
Sep 3, 2015, 11:58:52 AM9/3/15
to Jinwon An, Keras-users
At equal batch sizes, they will take the same time exactly (they do the same thing).

With different batch sizes, whichever is using the more appropriate batch size will be faster. Batch size is critical to performance on GPU, because data is loaded on the GPU one batch at a time.

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/83f769c4-6b15-419f-adb8-842741cf0be0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages