Plugin embedding
@jcury and I discussed today (and this has also come up in the past) that if users develop their own network (or transforms, or anything else pluggable) and use it to train a model, it would be useful if the .pth file itself embedded all plugins used for training the model.
The users who are handed the .pth file can run predict on it without having to pass around any additional plugin modules.
There is a slight security concern here, that we would be passing around files that contain arbitrary code run on the user's machine. Of course, researchers share code with each other all the time and run them on their own machines (probably more often than not without looking at it). So we can generally assume that researchers who want to share their models with each other will not have malicious intent. Though arbitrary code can be dangerous even unintentionally, if it is poorly coded, but this problem is not made worse if the code is embedded in the .pth file as opposed to distributed as a separate file.
It might be a good idea to run plugins with some degree of sandboxing, e.g. to prevent access to the full filesystem of the host computer. It is not possible in Python to do this totally securely, but in this case the purpose would be to mitigate coding mistakes, not mitigate deliberate attacks.
If nothing else, it would be a good idea when loading a .pth file with embedded plugins to warn the user about it, list the plugins that will be loaded, and prompt them to continue loading, or give them the option to view the plugin files.