originrose / cortex

Machine learning in Clojure
Eclipse Public License 1.0
1.27k stars 111 forks source link

Resnet retrain #218

Closed cnuernber closed 7 years ago

cnuernber commented 7 years ago

Landing a lot of hard work to make this a both more possible and pleasant.

  1. Small optimizations to the tensor cpu layer to make processing images with tensors a lot faster. This means our image processing code can match more closely what people find if they are working with numpy or matlab.

  2. Elide split entirely if the system is doing inference in the section of the graph. Force the traverse system to remap buffers.

  3. Build a system to allow the compute binding to allocate buffers from pools meaning several buffers can share the same base physical address (!!). The rational behind this is during inference and to some extent even if you need gradient buffers (during training) you can reuse a some small subset of the buffers. This is a very very important optimization; running resnet50 and trying to fine-tune it to another problem we were seeing that a batch size of 4 took almost a gig of ram to run. With this optimization we are seeing that a batch-size of 16 takes less than 400MB. So a factor of at least 8 if not more reduction in memory use when doing fine tuning and probably considerably more when doing inference.

The last optimization opens the door to using any existing architecture (ImageNet, ResNet, Inception) on normal desktop cards or even on laptop cards (if you are patient).

Special thanks to @joycex99 for setting up this example and fighting through the initial set of painful (and time consuming) errors.