returnn.__old_mod_loader__#

This provides lazy module wrappers such that old-style RETURNN-as-a-framework imports are still working. E.g. like:

import returnn.TFUtil
import returnn.TFNativeOp

Some old RETURNN configs also might directly have imports like:

import TFUtil
import TFHorovod

This is supported as well.

returnn.__old_mod_loader__.setup(package_name='returnn', modules=None)[source]#

This does the setup, such that all the modules become available in the returnn package. It does not import all the modules now, but instead provides them lazily.

Parameters:
  • package_name (str) – “returnn” by default

  • modules (dict[str,types.ModuleType]|None) – if set, will do modules[old_mod_name] = mod

returnn.__old_mod_loader__.disable_lazy_mod_loads()[source]#

Disable any future module loads.

E.g. pickle.whichmodule() or pickle.Pickler.dump() has some logic to iterate through all sys.modules, and do a getattr(mod, name) to check whether some object is found there. This triggers that all lazy loaders will actually load the modules, which can cause all kinds of strange side effects.