AttributeError: 'DataLoader' object has no attribute '__code__' #11492
Unanswered
SongyiGao
asked this question in
Lightning Trainer API: Trainer, LightningModule, LightningDataModule
Replies: 1 comment 1 reply
-
Hello You are patching your module: algo.train_dataloader = train_dataloader
algo.val_dataloader= val_dataloader This is most likely the reason you see this error. These are not attributes, but methods on the LightningModule. You need to implement these methods or patch them properly with a callable, although I don't recommend the latter. See our documentation for data here: https://pytorch-lightning.readthedocs.io/en/latest/guides/data.html#using-lightningdatamodule |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My code:
`
....
algo = Rank(task=task)
algo.train_dataloader = train_dataloader
algo.val_dataloader= val_dataloader
trainer = pl.Trainer()
print("train_dataloader:",algo.train_dataloader)
print("val_dataloader:",algo.val_dataloader)
trainer.fit(algo)
`
The Error massage:
`
train_dataloader: <torch.utils.data.dataloader.DataLoader object at 0x7f679a996e90>
val_dataloader: <torch.utils.data.dataloader.DataLoader object at 0x7f679aabeb10>
Traceback (most recent call last):
File "/home/ubuntu/yi/resarch/quantopt/quantopt/algo/task/task.py", line 158, in
trainer.fit(algo)
File "/home/ubuntu/anaconda3/envs/yi/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 552, in fit
self._run(model)
File "/home/ubuntu/anaconda3/envs/yi/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 849, in _run
self.config_validator.verify_loop_configurations(model)
File "/home/ubuntu/anaconda3/envs/yi/lib/python3.7/site-packages/pytorch_lightning/trainer/configuration_validator.py", line 34, in verify_loop_configurations
self.__verify_train_loop_configuration(model)
File "/home/ubuntu/anaconda3/envs/yi/lib/python3.7/site-packages/pytorch_lightning/trainer/configuration_validator.py", line 59, in __verify_train_loop_configuration
has_train_dataloader = is_overridden("train_dataloader", model)
File "/home/ubuntu/anaconda3/envs/yi/lib/python3.7/site-packages/pytorch_lightning/utilities/model_helpers.py", line 68, in is_overridden
instance_code = getattr(instance_attr, "patch_loader_code", None) or instance_attr.code
AttributeError: 'DataLoader' object has no attribute 'code'
`
Beta Was this translation helpful? Give feedback.
All reactions