The common way is to start your code with:

Yup, I’ve noted this (this code is based on pytorch examples).
However, there may be different possible situations to handle and I want the model code to be quite isolated from the environment (e.g. place it in a separate python module), and this doesn’t look like a general solution.