docformer
docformer copied to clipboard
NotImplementedError: Support for `validation_epoch_end` has been removed in v2.0.0. `DocFormer` implements this method
Ran into this issue while running sample notebook on colab ... https://github.com/shabie/docformer/blob/master/examples/docformer_pl/document_image_classification_on_rvl_cdip/4.Document-image-classification-with-docformer.ipynb
1 if __name__ == "__main__":
----> 2 main()
6 frames
[<ipython-input-25-82eba9431764>](https://localhost:8080/#) in main()
29 deterministic=True
30 )
---> 31 trainer.fit(docformer, datamodule)
[/usr/local/lib/python3.10/dist-packages/pytorch_lightning/trainer/trainer.py](https://localhost:8080/#) in fit(self, model, train_dataloaders, val_dataloaders, datamodule, ckpt_path)
527 model = _maybe_unwrap_optimized(model)
528 self.strategy._lightning_module = model
--> 529 call._call_and_handle_interrupt(
530 self, self._fit_impl, model, train_dataloaders, val_dataloaders, datamodule, ckpt_path
531 )
[/usr/local/lib/python3.10/dist-packages/pytorch_lightning/trainer/call.py](https://localhost:8080/#) in _call_and_handle_interrupt(trainer, trainer_fn, *args, **kwargs)
40 if trainer.strategy.launcher is not None:
41 return trainer.strategy.launcher.launch(trainer_fn, *args, trainer=trainer, **kwargs)
---> 42 return trainer_fn(*args, **kwargs)
43
44 except _TunerExitException:
[/usr/local/lib/python3.10/dist-packages/pytorch_lightning/trainer/trainer.py](https://localhost:8080/#) in _fit_impl(self, model, train_dataloaders, val_dataloaders, datamodule, ckpt_path)
566 model_connected=self.lightning_module is not None,
567 )
--> 568 self._run(model, ckpt_path=ckpt_path)
569
570 assert self.state.stopped
[/usr/local/lib/python3.10/dist-packages/pytorch_lightning/trainer/trainer.py](https://localhost:8080/#) in _run(self, model, ckpt_path)
919 self._callback_connector._attach_model_logging_functions()
920
--> 921 _verify_loop_configurations(self)
922
923 # hook
[/usr/local/lib/python3.10/dist-packages/pytorch_lightning/trainer/configuration_validator.py](https://localhost:8080/#) in _verify_loop_configurations(trainer)
34 raise ValueError("Unexpected: Trainer state fn must be set before validating loop configuration.")
35 if trainer.state.fn == TrainerFn.FITTING:
---> 36 __verify_train_val_loop_configuration(trainer, model)
37 __verify_manual_optimization_support(trainer, model)
38 __check_training_step_requires_dataloader_iter(model)
[/usr/local/lib/python3.10/dist-packages/pytorch_lightning/trainer/configuration_validator.py](https://localhost:8080/#) in __verify_train_val_loop_configuration(trainer, model)
82 )
83 if callable(getattr(model, "validation_epoch_end", None)):
---> 84 raise NotImplementedError(
85 f"Support for `validation_epoch_end` has been removed in v2.0.0. `{type(model).__name__}` implements this"
86 " method. You can use the `on_validation_epoch_end` hook instead. To access outputs, save them in-memory as"
NotImplementedError: Support for `validation_epoch_end` has been removed in v2.0.0. `DocFormer` implements this method. You can use the `on_validation_epoch_end` hook instead. To access outputs, save them in-memory as instance attributes. You can find migration examples in https://github.com/Lightning-AI/lightning/pull/16520.
As it's written on the error explanation, if you are using pytorch-lightning or lightning v2.0.0 or higher this code might not work appropriately.
Here's what you can do.
- Check what lightning package version is installed in your environment by 'pip list | grep lightning' or 'conda list lightning' etc. (It's up to how you have built your environment.) You might get 'lightning-utilities' and 'pytorch-lightning' as a result. It means that you've followed the old method of installing lightning package. It is deprecated.
- (Not recommended) If you want to run this code without changing some parts, I recommend you to install older lightning package like v1.9.0. (Note that 'pip install pytorch-lightning' has been deprecated and stopped being updated since June 2023. 'pip install lightning==[version]' might work, but I haven't tried that way.)
- (Recommended) If you could change some codes, I recommend installing the recent version of lightning package. You might have to change some parts. Main things that have to be changed are listed below.
- 'import pytorch_lightning as pl' -> 'import lightning.pytorch as pl'
- function 'train_epoch_end', 'validation_epoch_end' -> function 'on_train_epoch_end', 'on_validation_epoch_end' (Find them from class DocFormer(pl.LightningModule))
You might need to look at lightning offical page. Please refer to the link below. https://lightning.ai/docs/pytorch/stable/
Hi @Arun-purakkatt, if that's the case, I think here is what we can do
- See how the
validation_epoch_endis actually implemented forpytorch_lightning v2, and then just rename the functions accordingly - This should work
Cheers, Akarsh