-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Avoid rewriting the metrics file in CSVLogger unless necessary #18567
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
awaelchli
force-pushed
the
bugfix/csv-append
branch
from
September 15, 2023 16:57
a2fb364
to
ec86624
Compare
awaelchli
requested review from
carmocca,
justusschock,
Borda and
williamFalcon
as code owners
September 15, 2023 17:12
awaelchli
commented
Sep 15, 2023
awaelchli
commented
Sep 15, 2023
awaelchli
commented
Sep 15, 2023
awaelchli
commented
Sep 15, 2023
carmocca
reviewed
Sep 15, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this
carmocca
approved these changes
Sep 16, 2023
Borda
approved these changes
Sep 18, 2023
mergify
bot
added
ready
PRs ready to be merged
and removed
has conflicts
ready
PRs ready to be merged
labels
Sep 18, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
Something isn't working
fabric
lightning.fabric.Fabric
performance
pl
Generic label for PyTorch Lightning package
priority: 0
High priority task
ready
PRs ready to be merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #17725
The CSVLogger in master accumulates all metrics in memory and writes them to a single file periodically. Naturally, this leads to an increasingly larger file, and with every write the time it takes increases. This was done for simplicity to avoid complicated optimizations, but ever since the CSVLogger was made the default, users noticed its naive implementation.
This PR mitigates the file-write costs by appending to the file. However, a naive change from file-write mode "w" to "a" is not sufficient, because the keys in the metrics dict could change anytime (the user may log a new key in the future). Appending naively would lead to an invalid csv file. For this reason we still need to rewrite the entire file to update the new columns, which can be costly but we expect that new keys get added infrequently. When the keys don't change from one flush to the next, we simply append to the file.
My personal recommendation is that we stop here. While we could do many more optimizations, it is probably not our intention to reinvent tools like tensorboard etc. The CSVLogger in my opinion should not be used for production training runs.
📚 Documentation preview 📚: https://pytorch-lightning--18567.org.readthedocs.build/en/18567/
cc @Borda @tchaton @carmocca @justusschock @awaelchli