Skip to content

Conversation

@chizuchizu
Copy link
Contributor

@chizuchizu chizuchizu commented Feb 26, 2021

Fix AttributeError: 'NoneType' object has no attribute 'finalize'

What does this PR do?

Issue

import pytorch_lightning as pl

my_model = MyLightningModule()
trainer = pl.Trainer(tpu_cores=8, logger=None)
trainer.fit(my_model)

If you run the code written above, you will get the error below.

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/plugins/training_type/tpu_spawn.py in _close_logger(self, trainer)
    236     def _close_logger(self, trainer) -> None:
    237         if hasattr(trainer, "logger"):
--> 238             trainer.logger.finalize("success")
    239 
    240     @property

AttributeError: 'NoneType' object has no attribute 'finalize'

This bug is caused by not being able to handle the case where the attribute logger exists and logger.finalize does not.

CHANGE

pytorch_lightning/plugins/training_type/tpu_spawn.py the 249th line

BEFORE

def _close_logger(self, trainer) -> None:
    if hasattr(trainer, "logger"):
        trainer.logger.finalize("success")

AFTER

def _close_logger(self, trainer) -> None:
    if hasattr(trainer, "logger.finalize"):
        trainer.logger.finalize("success")

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

This is the first pull request to OSS in my life. So, of course, yes:)

Fix AttributeError: 'NoneType' object has no attribute 'finalize'
@codecov
Copy link

codecov bot commented Feb 26, 2021

Codecov Report

Merging #6221 (8af16be) into master (ff16104) will decrease coverage by 3%.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master   #6221    +/-   ##
=======================================
- Coverage      94%     90%    -3%     
=======================================
  Files         161     161            
  Lines       11486   11376   -110     
=======================================
- Hits        10745   10275   -470     
- Misses        741    1101   +360     

@Borda Borda added the bug Something isn't working label Feb 26, 2021
@Borda Borda added this to the 1.2.x milestone Feb 26, 2021
Copy link
Collaborator

@Borda Borda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind add chlog :]
also pls keep the bullet-list form template

@Borda Borda added the ready PRs ready to be merged label Feb 26, 2021
@chizuchizu
Copy link
Contributor Author

@Borda

Thanks for the review.

I've added bulle-list and CHANGELOG.md.

Co-authored-by: Akihiro Nitta <nitta@akihironitta.com>
@mergify mergify bot removed the has conflicts label Feb 27, 2021
@rohitgr7 rohitgr7 enabled auto-merge (squash) February 27, 2021 09:19
@mergify mergify bot added the has conflicts label Mar 1, 2021
Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for resolving my bug :)

@mergify mergify bot removed the has conflicts label Mar 3, 2021
@Borda Borda added the accelerator: tpu Tensor Processing Unit label Mar 4, 2021
@rohitgr7 rohitgr7 merged commit a6c98c4 into Lightning-AI:master Mar 8, 2021
@tchaton tchaton mentioned this pull request Mar 8, 2021
tchaton pushed a commit that referenced this pull request Mar 9, 2021
…TPU (#6221)

* Fix bug

Fix AttributeError: 'NoneType' object has no attribute 'finalize'

* Update CHANGELOG.md

* deleted a period

* Update CHANGELOG.md

Co-authored-by: Akihiro Nitta <nitta@akihironitta.com>

* Update CHANGELOG.md

* Update pytorch_lightning/plugins/training_type/tpu_spawn.py

Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com>

Co-authored-by: Akihiro Nitta <nitta@akihironitta.com>
Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com>
Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com>
Borda pushed a commit that referenced this pull request Mar 9, 2021
…TPU (#6221)

* Fix bug

Fix AttributeError: 'NoneType' object has no attribute 'finalize'

* Update CHANGELOG.md

* deleted a period

* Update CHANGELOG.md

Co-authored-by: Akihiro Nitta <nitta@akihironitta.com>

* Update CHANGELOG.md

* Update pytorch_lightning/plugins/training_type/tpu_spawn.py

Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com>

Co-authored-by: Akihiro Nitta <nitta@akihironitta.com>
Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com>
Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com>
tchaton pushed a commit that referenced this pull request Mar 9, 2021
…TPU (#6221)

* Fix bug

Fix AttributeError: 'NoneType' object has no attribute 'finalize'

* Update CHANGELOG.md

* deleted a period

* Update CHANGELOG.md

Co-authored-by: Akihiro Nitta <nitta@akihironitta.com>

* Update CHANGELOG.md

* Update pytorch_lightning/plugins/training_type/tpu_spawn.py

Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com>

Co-authored-by: Akihiro Nitta <nitta@akihironitta.com>
Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com>
Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com>
lexierule pushed a commit that referenced this pull request Mar 9, 2021
…TPU (#6221)

* Fix bug

Fix AttributeError: 'NoneType' object has no attribute 'finalize'

* Update CHANGELOG.md

* deleted a period

* Update CHANGELOG.md

Co-authored-by: Akihiro Nitta <nitta@akihironitta.com>

* Update CHANGELOG.md

* Update pytorch_lightning/plugins/training_type/tpu_spawn.py

Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com>

Co-authored-by: Akihiro Nitta <nitta@akihironitta.com>
Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com>
Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accelerator: tpu Tensor Processing Unit bug Something isn't working ready PRs ready to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants