For non-core dependencies (e.g., specific models or algorithms), follow these steps to keep the base installation minimal:
- Specify in
setup.py: Add the dependency to the extra_deps dictionary. Users can then install it via pip install 'megablocks[extra_name]'. - Conditional Imports: Use a
try/except block with MissingConditionalImportError to provide clear error messages if the dependency is missing.
from composer import Callback
from composer.utils import MissingConditionalImportError
class SystemMetricsMonitor(Callback):
try:
import pynvml
except ImportError as e:
raise MissingConditionalImportError(
extra_deps_group="system_metrics_monitor",
conda_package="pynvml",
conda_channel="conda-forge",
) from e
If the dependency is core to MegaBlocks, add it to install_requires in setup.py and requirements.run in meta.yaml.