import_helpers#

Dynamically import a Python object (e.g. module, class, function, โ€ฆ).

Functions

import_object

Dynamically import a Python object (e.g.

Exceptions

MissingConditionalImportError

Handles errors for external packages that might not be installed.

exception composer.utils.import_helpers.MissingConditionalImportError(extra_deps_group, conda_package, conda_channel='conda-forge')[source]#

Bases: ImportError

Handles errors for external packages that might not be installed.

Parameters
  • extra_deps_group (str) โ€“ the pip package group, found in setup.py. For example, nlp for mosaicml[nlp].

  • conda_package (str, optional) โ€“ The package(s) to install if using conda.

  • conda_channel (str, optional) โ€“ The conda channel to install packages from. Set to None if the package is not published on conda and must be installed via pip.

composer.utils.import_helpers.import_object(name)[source]#

Dynamically import a Python object (e.g. class, function, โ€ฆ).

Note

To dynamically import a module, use importlib.import_module().

Parameters

name (str) โ€“

The path to the Python object to import.

Separate the module name and class name with a ':' (e.g. 'path.to.module:function_name').

Example

>>> from composer.utils import import_object
>>> import_object('functools:partial')
<class 'functools.partial'>

Note

The module name must be discoverale with the Python path, as determined by sys.path.

Returns

Any โ€“ The imported object.