SEE-GEO / ccic

Chalmers Cloud Ice Climatology
MIT License
1 stars 2 forks source link

Prune network heads to increase inference efficiency #85

Closed adriaat closed 2 months ago

adriaat commented 7 months ago

In the current setup, when running any prediction all targets are predicted and then discarded based on the ccic process's --targets flag. Since the network heads are independent of each other, this means that many computations are wasted.

An improvement would be to prune the network and keep only those heads relevant for the --targets arguments, both reducing the memory footprint and execution time.

adriaat commented 2 months ago

What I considered:

In any case, this is not straightforward since ccic is calling quantnn.mrnn.MRNN.predict to run inference, which does not support new (keyword) arguments. That is, the quantnn library should be adapted accordingly.

Consequently, I added a script that creates a copy of the network model but with retaining only heads specified as an argument. This has the advantage that both the model and inference are lighter, since unused heads are not loaded to memory, and that this only needed a small modification in ccic.models.CCICModel. The disadvantage with this approach is that there can be multiple network files, and the user should pick the correct file according to their needs.

Also, this is only probably relevant when doing a large (full) processing of CCIC data or in a setting with limited computational resources to spare.

Addressed with 386c6295f70430b84a9a77d113bc8fda4367a1ce