Fix ModuleNotFoundError: entry scripts import lightning.pytorch but environment.yml ships pytorch-lightning#1
Open
alex-crlhmmr wants to merge 1 commit into
Conversation
pretrain.py, classification.py, and segmentation.py import seed_everything from lightning.pytorch, but environment.yml installs pytorch-lightning (not the separate `lightning` distribution), so `conda env create -f environment.yml` followed by a training run fails with `ModuleNotFoundError: No module named 'lightning'`. pytorch_lightning re-exports seed_everything and the rest of the codebase already uses it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pretrain.py,classification.py, andsegmentation.pyimportseed_everythingfromlightning.pytorch, butenvironment.ymlonly installspytorch-lightning(a different PyPI distribution, notlightning). As a result, the documented setup path fails at import time: afterconda env create -f environment.yml, any training run raisesModuleNotFoundError: No module named 'lightning'.This unifies the three imports onto
pytorch_lightning, which the rest of the codebase andenvironment.ymlalready use.Steps to reproduce
Confirmed in a clean environment:
pip install pytorch-lightning==2.2.4(exactly whatenvironment.ymlspecifies) does not install thelightningpackage, andlightningis not among its dependencies (Requires: fsspec, lightning-utilities, numpy, packaging, PyYAML, torch, torchmetrics, tqdm, typing-extensions).Root cause
The codebase mixes the two Lightning distributions. The core already uses
pytorch_lightning:utils/training.py—Trainer,ModelCheckpoint,TensorBoardLogger,DDPStrategy/FSDPStrategymodels/*.py—import pytorch_lightning as plOnly three call sites reach for the other distribution:
pretrain.py:102classification.py:99segmentation.py:114each
from lightning.pytorch import seed_everything. Sinceenvironment.ymlpinspytorch-lightning==2.2.4and never installslightning, these three lines break the shipped environment.pytorch_lightningre-exportsseed_everythingas a top-level symbol (verified in 2.2.4), so unifying on it is behavior-preserving and avoids requiring two overlapping Lightning distributions.Fix
in
pretrain.py,classification.py, andsegmentation.py.Testing
from pytorch_lightning import seed_everythingresolves in the unmodifiedenvironment.ymlenvironment (pytorch-lightning 2.2.4, Python 3.10.8, PyTorch 2.2.1, CUDA 12.1, DGL 2.1.0).seed_everythingis the only symbol imported fromlightning.pytorchanywhere in the repo, so no other call sites are affected.