I can confirm that with current nightly build it does not double in size anymore.
But I wonder a little bit because the release notes state:
“Major improvements in on-device binary size with Mobile Interpreter” but neither model exports are smaller nor library binaries on Android, which is still around 30-40MB (haven’t checked iOS yet). What exactly do you mean with binary size?
Do you have any concrete numbers that show the improvement?
Hi Erik, the binary size optimization is for pytorch library (runtime), not model file. You need to use custom build to only include ops that are needed by your model. Please check this tutorial:
I found out that the problem lies in the “Conv packed params hoisting” and “INSERT_FOLD_PREPACK_OPS” steps, whatever that means…
The following code optimizes the model for mobile without doubling the model’s size by blacklisting those optimization steps, this works without the nightly build:
import torch
from torch.utils.mobile_optimizer import optimize_for_mobile
from torch._C import MobileOptimizerType
torchscript_model = torch.jit.script(model)
torchscript_model = optimize_for_mobile(
torchscript_model,
optimization_blocklist={
MobileOptimizerType.HOIST_CONV_PACKED_PARAMS,
MobileOptimizerType.INSERT_FOLD_PREPACK_OPS
},
)
if use_lite:
torchscript_model._save_for_lite_interpreter("model.ptl")
else:
torch.jit.save(torchscript_model, "model.pt")