pytorch – Model_heplers.py in is_overridden > raise ValueError(“Expected a parent”)

Question:

I am running on a new remote server a code that used to work on another remote server. I think I setup things in the same way, but when I run my training script, I get this error:

Traceback (most recent call last):
  File "/home/andrea/code/vertikal-machine-learning/source/model/hss_bearing_mk2/hss_bearing_mk2/models/train_model.py", line 144, in <module>
    seq_len=seq_len, mname=mname)
  File "/home/andrea/code/vertikal-machine-learning/source/model/hss_bearing_mk2/hss_bearing_mk2/models/pytorch_models.py", line 321, in train_test
    trainer.fit(model, datamodule=dm)
  File "/home/andrea/anaconda3/envs/hss_bearing_mk2/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 552, in fit
    self._run(model)
  File "/home/andrea/anaconda3/envs/hss_bearing_mk2/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 849, in _run
    self.config_validator.verify_loop_configurations(model)
  File "/home/andrea/anaconda3/envs/hss_bearing_mk2/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/andrea/anaconda3/envs/hss_bearing_mk2/lib/python3.7/site-packages/pytorch_lightning/trainer/configuration_validator.py", line 49, in __verify_train_loop_configuration
    has_training_step = is_overridden("training_step", model)
  File "/home/andrea/anaconda3/envs/hss_bearing_mk2/lib/python3.7/site-packages/pytorch_lightning/utilities/model_helpers.py", line 45, in is_overridden
    raise ValueError("Expected a parent")
ValueError: Expected a parent

Here is the part of code that looks buggy for some reason:

    model = get_model(mname=mname)

    dm = DataModule(
        X_train=X_train,
        y_train=y_train,
        X_val=X_val,
        y_val=y_val,
        X_test=X_test,
        y_test=y_test,
        keys_train=keys_train,
        keys_val=keys_val,
        keys_test=keys_test,
        seq_len=seq_len,
        batch_size=batch_size,
        num_workers=4
    )
    # trainer.logger_connector.callback_metrics
    trainer.fit(model, datamodule=dm)

Is it something related to environment setup? Something overridden by something something??

Can someone point me in the right direction?

EDIT: I tried to run my project locally in a newly created environment and I have the same error.

EDIT 2: My DataModule inherits from LightningDataModule

class DataModule(pl.LightningDataModule):
Asked By: shamalaia

||

Answers:

The problem was that model was inheriting from nn.Module instead of from pl.LightningModule

Answered By: shamalaia

If you encounter the same error with the Ray Tune callback TuneReportCheckpointCallback while using import lightning as L on lightning versions 2.0.0 and above, there is a related GitHub issue which is being addressed. They plan to fix the issue soon.

Answered By: Ching Chang

With lightning versions 2.0.0, use import lightning.pytorch as pl instead of import pytorch_lightning as pl.

Answered By: arthur.sw
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.