-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List of Callbacks Raises ValueError("Expected a parent")
#17485
Comments
Can you share your code? I've seen this happen when import lightning.pytorch as lp
import pytorch_lightning as pl
class MyCallback(pl.Callback):
...
trainer = lp.Trainer(callbacks=MyCallback()) # bad! |
@carmocca I had this bug and your suggestion fixed it |
@carmocca Do you think we could inspect sys.modules and detect whether there are both pytorch_lightning and lightning loaded, and warn the user? Not sure whether that would help. |
@awaelchli I mean, better warnings are always great. |
this also solved a similar bug for learning rate monitor callbacks |
I feel like that's too strong of a check. Imagine you are in a team of data scientist who share utility python packages and two packages use lightning, each with a type of import. This check would break their code just on import even if they don't mix the classes. Fixing it might also be out of the control of the person who just tried to import it. I think it would be simpler that we add a specific check for this in |
ValueError("Expected a parent")
That solved my error. Thanks! |
I'm seeing this error with the Optuna My rather hacky workaround is this: import lightning
import optuna
class PatchedCallback(
optuna.integration.PyTorchLightningPruningCallback, lightning.Callback
):
pass I think since there's going to be two lightnings floating around for years, instance checks should be updated to be Also, will the fix #17548 just mean that I get an error if I use a package that is still on old Lightning? Or is it assuming direct use of the class and it doesn't handle the inheritance case? |
could you please fix the error msg for this? The error message is useless. in my case, it raised |
* ♻️ Refactor overall redundant codes * 🎨 Add config factory functionality * ✏️ Remove minor comments * 🐛 Fixed val_loss error and add error raising code when gpu is not detected * 🎨 Fix param_space to have more elegant representation * 🎨 Improve the pbt config * ♻️ Rename pytorch_lightning package as lightning * 📝 Update the precise guide * 🐛 Fix bug with moduel import * 🙈 Add .gitignore file * ✏️ Fix argparese argument to have dash * ♻️ Fixed the order of import * 🎨 Fix the old function of LightningModule * ♻️ Refactor the code and make loading checkpoint clearer * ♻️ Change the order of arguments for clarity * 🐛 Add a default model case * ✏️ Fix minor typo * ✏️ Fix typo * 🙈 Update to ignore lightning_logs * 🐛 Make dataset to read both train csv and test csv * 🚑 Make a quick fix for saving prediction csv file * 🎨 Add PredictionCallback * ✏️ Fix typo * ✏️ Fix typo * 🐛 Try to fix callback error * 🐛 Fix Expected a parent bug, see [the solution](Lightning-AI/pytorch-lightning#17485 (comment)) * 🐛 Move prediction feature from trainer to callback * 🙈 Update git not to read output csv file * ⬆️ Rewrite the requirements.yml
I'm posting this here for visibility, since this seems to be the issue that gets picked up by search engines when looking for The check for mixed imports implemented by @carmocca fails to detect and warn users in at least some configurations of old/new imports. For a minimal example that still produces the To fix the issue on their end I've proposed that they update their way of importing Lightning to use the new style. However, the uninformative error message made it difficult to troubleshoot the root cause of the error. I thought it was relevant to bring this up to the attention of the Lightning devs, to see if you could maybe improve the detection of mixed import styles. |
Bug description
If the callbacks list, passing to the trainer, has more than one element, it raises the error
ValueError("Expected a parent")
.If you pass any of those elements alone the code runs fine.
p.s. I'm already importing like this:
import lightning.pytorch as pl
which is version >=2. specific.What version are you seeing the problem on?
2.0+
How to reproduce the bug
No response
Error messages and logs
ValueError: Expected a parent
Environment
Current environment
More info
No response
cc @awaelchli
The text was updated successfully, but these errors were encountered: