ValueError("Expected a parent")
when using new Lightning imports and PyG Lightning DataModule wrappers
#9811
Labels
🐛 Describe the bug
Bug
When using modern Lightning imports (i.e.
from lightning import ...
) rather than old imports (i.e.from pytorch_lightning import ...
) in a project mixing Lightning and PyG, the code crashes on a non-intuitiveValueError("Expected a parent")
. I suspect the exact line that raises this message depends on the user application.This seems to be caused by Lightning sometimes (but not always!) failing when import styles are mixed together (see this issue for context). Given that PyG's Lightning wrappers use the old style, but most other codebases use the modern style, a conflict happens.
Below is the smallest working example I could come up with that reproduces the issue:
Alternative considered
In this specific example, the error can be fixed by reverting back to the old import style:
However, in more complex projects, e.g. with other dependencies using Lightning, it's not realistic (and often outside of the user's power) to revert all imports to the old style. For example, in the real project where I first encountered this error, troubleshooting lead me to edit imports in dependencies...
Suggested fix
Given that the modern Lightning import style is not so new anymore (and rather widely adopted from I could see), I would suggest PyG update how they import Lightning. I was able to fix the example above (and the issue in my real project) by simply changing PyG's Lightning imports like below:
Versions
I was not able to obtain the full info about my environment because I'm using
uv
and the script crashes on auv
environment. But I am experiencing this with Python 3.12, and here is the relevant info about the torch-related dependencies:The text was updated successfully, but these errors were encountered: