Skip to content
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

Calling trainer.fit fails with: AttributeError: 'dict' object has no attribute 'pretty' #5672

Closed
nithinivi opened this issue Jan 27, 2021 · 7 comments
Labels
3rd party Related to a 3rd-party bug Something isn't working help wanted Open to be worked on waiting on author Waiting on user action, correction, or update

Comments

@nithinivi
Copy link

🐛 Bug

dataset = MNIST(os.getcwd(), download=True, transform=transforms.ToTensor())
train, val = random_split(dataset, [55000, 5000])

autoencoder = LitAutoEncoder()
trainer = pl.Trainer()
trainer.fit(autoencoder, DataLoader(train))

Calling trainer.fit fails with AttributeError: 'dict' object has no attribute 'pretty'

To Reproduce

GPU available: True, used: False
TPU available: None, using: 0 TPU cores
/home/nithin/.pyenv/versions/3.7.3/lib/python3.7/site-packages/pytorch_lightning/utilities/distributed.py:50: UserWarning: GPU available but not used. Set the --gpus flag when calling the script.
  warnings.warn(*args, **kwargs)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-9-ec8282b1f4ec> in <module>
      4 autoencoder = LitAutoEncoder()
      5 trainer = pl.Trainer()
----> 6 trainer.fit(autoencoder, DataLoader(train))

~/.pyenv/versions/3.7.3/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py in fit(self, model, train_dataloader, val_dataloaders, datamodule)
    508         self.call_hook('on_fit_start')
    509 
--> 510         results = self.accelerator_backend.train()
    511         self.accelerator_backend.teardown()
    512 

~/.pyenv/versions/3.7.3/lib/python3.7/site-packages/pytorch_lightning/accelerators/accelerator.py in train(self)
     54 
     55     def train(self):
---> 56         self.trainer.setup_trainer(self.trainer.model)
     57         return self.train_or_test()
     58 

~/.pyenv/versions/3.7.3/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py in setup_trainer(self, model)
    442             self.logger.log_hyperparams(ref_model.hparams_initial)
    443             self.logger.log_graph(ref_model)
--> 444             self.logger.save()
    445 
    446         # wait for all to join if on distributed

~/.pyenv/versions/3.7.3/lib/python3.7/site-packages/pytorch_lightning/utilities/distributed.py in wrapped_fn(*args, **kwargs)
     38     def wrapped_fn(*args, **kwargs):
     39         if rank_zero_only.rank == 0:
---> 40             return fn(*args, **kwargs)
     41 
     42     return wrapped_fn

~/.pyenv/versions/3.7.3/lib/python3.7/site-packages/pytorch_lightning/loggers/tensorboard.py in save(self)
    234         # save the metatags file if it doesn't exist
    235         if not self._fs.isfile(hparams_file):
--> 236             save_hparams_to_yaml(hparams_file, self.hparams)
    237 
    238     @rank_zero_only

~/.pyenv/versions/3.7.3/lib/python3.7/site-packages/pytorch_lightning/core/saving.py in save_hparams_to_yaml(config_yaml, hparams)
    386         with fs.open(config_yaml, "w", encoding="utf-8") as fp:
    387             try:
--> 388                 OmegaConf.save(hparams, fp)
    389                 return
    390             except (UnsupportedValueType, ValidationError):

~/.pyenv/versions/3.7.3/lib/python3.7/site-packages/omegaconf/omegaconf.py in save(config, f, resolve)
    268         :param resolve: True to save a resolved config (defaults to False)
    269         """
--> 270         data = config.pretty(resolve=resolve)
    271         if isinstance(f, (str, pathlib.Path)):
    272             with io.open(os.path.abspath(f), "w", encoding="utf-8") as file:

AttributeError: 'dict' object has no attribute 'pretty'

Expected behavior

Calling trainer.fit(autoencoder, DataLoader(train)) should train MNIST classifier without errors.

Environment

  • CUDA:
    • GPU:
      • GeForce GTX 1050 Ti
    • available: True
    • version: 10.2
  • Packages:
    • numpy: 1.19.5
    • pyTorch_debug: False
    • pyTorch_version: 1.7.1
    • pytorch-lightning: 1.1.6
    • tqdm: 4.50.0
  • System:

Additional context

The program was running on jupyter notebook.

@nithinivi nithinivi added bug Something isn't working help wanted Open to be worked on labels Jan 27, 2021
@omry
Copy link
Contributor

omry commented Jan 28, 2021

Try to upgrade to OmegaConf 2.0, you have an incompatible version installed.

@Borda Borda added the 3rd party Related to a 3rd-party label Jan 29, 2021
@Borda
Copy link
Member

Borda commented Jan 29, 2021

@nithinivi what OmegaConf are you using?

@Borda Borda added the waiting on author Waiting on user action, correction, or update label Jan 29, 2021
@nithinivi
Copy link
Author

nithinivi commented Jan 30, 2021

@Borda @omry The version number of OmegaConf is 2.0.0

@omry
Copy link
Contributor

omry commented Jan 30, 2021

@nithinivi,

config.pretty() is deprecated in OmegaConf 2.0 and the source code no longer contain calls to it.
The stack trace is definitely not from OmegaConf 2.0. If you think this is wrong please provide repro instructions from scratch (including the creation of a virtualenv or a conda environment).

By the way, please upgrade to latest OmegaConf 2.0 release (currently 2.0.6).

@nithinivi
Copy link
Author

I created a new conda env and installed the torch and pytorch-ligthing.
Tried out the same code and the issue was not reproduced. So I do believe this was a issues with the environment setup and it's not using OmegaConf 2.0.

I have installed python using pyenv and executing the code in a jupyter notebook.

@roytseng-tw
Copy link

I had the same issue with omegaconf 2.0.1rc11.
After update to the latest version 2.0.6, the issue is gone.

@rohitgr7
Copy link
Contributor

rohitgr7 commented Feb 2, 2021

I believe issue is resolved now. Please feel free to reopen if required :)

@rohitgr7 rohitgr7 closed this as completed Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd party Related to a 3rd-party bug Something isn't working help wanted Open to be worked on waiting on author Waiting on user action, correction, or update
Projects
None yet
Development

No branches or pull requests

5 participants