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

[bugfix] Resolve memory not logged when missing metrics #8174

Merged
merged 6 commits into from
Jun 28, 2021

Conversation

tchaton
Copy link
Contributor

@tchaton tchaton commented Jun 28, 2021

What does this PR do?

This PR adds gpus_metrics to ResultCollection + filter the non requested gpus for logging

Fixes #8159

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?

Make sure you had fun coding 🙃

@tchaton tchaton added bug Something isn't working logging Related to the `LoggerConnector` and `log()` labels Jun 28, 2021
@tchaton tchaton added this to the v1.3.x milestone Jun 28, 2021
@tchaton tchaton self-assigned this Jun 28, 2021
@codecov
Copy link

codecov bot commented Jun 28, 2021

Codecov Report

Merging #8174 (319ad41) into master (2a372e3) will decrease coverage by 5%.
The diff coverage is 62%.

@@           Coverage Diff           @@
##           master   #8174    +/-   ##
=======================================
- Coverage      93%     88%    -5%     
=======================================
  Files         211     211            
  Lines       13440   13450    +10     
=======================================
- Hits        12474   11837   -637     
- Misses        966    1613   +647     

@tchaton tchaton marked this pull request as ready for review June 28, 2021 12:20
Copy link
Member

@ethanwharris ethanwharris left a comment

Choose a reason for hiding this comment

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

LGTM 😃

@justusschock justusschock enabled auto-merge (squash) June 28, 2021 13:34
@lexierule lexierule disabled auto-merge June 28, 2021 13:39
@lexierule lexierule merged commit c4492ad into master Jun 28, 2021
@lexierule lexierule deleted the bugfix/8159_log_gpu_memory_on_step branch June 28, 2021 13:39
for key, mem in self.gpus_metrics.items():
gpu_id = int(key.split('/')[0].split(':')[1])
if gpu_id in self.trainer.accelerator_connector.parallel_device_ids:
self.trainer.lightning_module.log(key, mem, prog_bar=False, logger=True, on_step=True, on_epoch=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

since we're already in the trainer, why do we have to log through the lightning module's log ?

Comment on lines +283 to +289
@property
def gpus_metrics(self) -> Dict[str, str]:
if self.trainer._device_type == DeviceType.GPU and self.log_gpu_memory:
mem_map = memory.get_memory_profile(self.log_gpu_memory)
self._gpus_metrics.update(mem_map)
return self._gpus_metrics

Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this PR need to add _gpu_metrics? Doesn't seem related to the issue linked.

This means that gpu metrics are now duplicated in this dictionary and in logged metrics.

Also it only gets filled when self.log_gpu_memory so it can't be used anyways without the flag.

Copy link

@thomasw21 thomasw21 Aug 20, 2021

Choose a reason for hiding this comment

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

I think this broke log_gpu_memory="min_max" option in Trainer.fit. Looks related to: #9010

Essentially memory. get_memory_profile adds two keys that are not in conventional format min_gpu_mem and max_gpu_mem (typically keys are in f"gpu_id: {gpu_id}/memory.used (MB)"

I see #9013 fixed it.

@carmocca carmocca modified the milestones: v1.3.x, v1.4 Jun 29, 2021
@mergify mergify bot added the ready PRs ready to be merged label Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working logging Related to the `LoggerConnector` and `log()` ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot log gpu memory without making on step = True while logging train loss
8 participants