-
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
LightningDeprecationWarning: DataModule.setup has already been called #9943
Comments
hi, I will check the warning With best Regars, |
hi can you send with best regards, |
This is literally the code shown in the Docs (see link above). The module is described above.
|
ok thank you, With best regards, |
Yes this MWE gets those too, but before those are displayed there is LightningDeprecationWarning: DataModule.prepare_data has already been called, so it will not be called again. In v1.6 this behavior will change to always call DataModule.prepare_data. LightningDeprecationWarning: DataModule.setup has already been called, so it will not be called again. In v1.6 this behavior will change to always call DataModule.setup. What is your point? |
I don't understand what do you mean? With best regards, |
When I posted that there was another message with some warning printed which has no been deleted. I was referring to that. If it was posted by mistake ignore my last message please. |
oh ok, I can understand, I just fixed this warning for now I will check the other warnings later. sorry for the misunderstanding. With best regards, |
Related to #9939 |
does this pull request help with the error? With best regards, |
@Programmer-RD-AI Your PR is not updated on master, additionally, I believe the deprecation only appears in the bug-fix branch so the fix needs to be applied to it directly, not to master. The branch is https://github.com/PyTorchLightning/pytorch-lightning/tree/release/1.4.x |
hi I create a new pull request #9953 with best regards, |
hi #9970 is the new PR |
Hi! The recommendation here is that You could also set and check your own def setup(self, stage=None):
if not self.has_setup_fit and stage == "fit":
expensive_work()
self.has_setup_fit = True Hope that helps! Feel free to ask any further questions. |
Hasn't has_setup_fit been deprecated from v1.4 ? |
What was deprecated is relying on the library setting and checking However, you can still replicate the behaviour as I described in my previous comment. Although you might need to change the variable name to avoid the collision |
When I use the solution suggested by @carmocca I get:
I'm using 1.5.10. |
@chanshing you can do this within your data module to ensure def __init__(self, ...) -> None:
self._already_called: Dict[str, bool] = {}
for stage in ("fit", "validate", "test", "predict"):
self._already_called[stage] = False
def setup(self, stage: Optional[str] = None) -> None:
if stage and self._already_called[stage]:
return
# do your logic here
self._already_called[stage] = True |
I also ran into this issue since my model depends on the dimensions of the data to be initialized and I followed the documentation but ended up with the aforementioned warning. Seems counter-intuitive to deprecate this property when the workaround is literally doing the same thing but with a different name |
We propose a different name to avoid the name collision as it would trigger the same deprecation warning you are trying to hide. Once the deprecation path is removed, you will be able to use |
I think the main point was why is it being deprecated if then the expectations are to do the exact same thing ourselves? |
See the issue which deprecated these: #7301 |
As of v1.4 properties sch as
has_setup_fit
have been deprecated in DataModule and are set to be removed in v1.6.However, the docs on latest still show "If you need information from the dataset to build your model, then run prepare_data() and setup() manually"
and the code:
This leads to the following warning being raised:
LightningDeprecationWarning: DataModule.setup has already been called, so it will not be called again. In v1.6 this behavior will change to always call DataModule.setup.
What is the recommended way to do this without ending up calling setup() twice as v1.6?
The text was updated successfully, but these errors were encountered: