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

Add AttributeDict container for Fabric #18943

Merged
merged 21 commits into from
Nov 18, 2023
Merged

Add AttributeDict container for Fabric #18943

merged 21 commits into from
Nov 18, 2023

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented Nov 4, 2023

What does this PR do?

Fixes #18515

Adds a convenience container to make training scripts stateful. An immediate application of this would be a script like the one in lit-gpt, where state gets defined here and accessed in several places.


📚 Documentation preview 📚: https://pytorch-lightning--18943.org.readthedocs.build/en/18943/

cc @Borda @justusschock @awaelchli @carmocca

@awaelchli awaelchli added feature Is an improvement or enhancement refactor checkpointing Related to checkpointing labels Nov 4, 2023
@github-actions github-actions bot added fabric lightning.fabric.Fabric pl Generic label for PyTorch Lightning package labels Nov 4, 2023
@awaelchli awaelchli added this to the 2.2 milestone Nov 4, 2023
@github-actions github-actions bot added the docs Documentation related label Nov 4, 2023
@awaelchli awaelchli added the fun Staff contributions outside working hours - to differentiate from the "community" label label Nov 4, 2023
@awaelchli awaelchli marked this pull request as ready for review November 4, 2023 14:46
Copy link
Contributor

github-actions bot commented Nov 4, 2023

⚡ Required checks status: All passing 🟢

Groups summary

🟢 pytorch_lightning: Tests workflow
Check ID Status
pl-cpu (macOS-11, lightning, 3.8, 1.12, oldest) success
pl-cpu (macOS-11, lightning, 3.9, 1.12) success
pl-cpu (macOS-11, lightning, 3.10, 1.13) success
pl-cpu (macOS-11, lightning, 3.10, 2.0) success
pl-cpu (macOS-11, lightning, 3.10, 2.1) success
pl-cpu (ubuntu-20.04, lightning, 3.8, 1.12, oldest) success
pl-cpu (ubuntu-20.04, lightning, 3.9, 1.12) success
pl-cpu (ubuntu-20.04, lightning, 3.10, 1.13) success
pl-cpu (ubuntu-20.04, lightning, 3.10, 2.0) success
pl-cpu (ubuntu-20.04, lightning, 3.10, 2.1) success
pl-cpu (windows-2022, lightning, 3.8, 1.12, oldest) success
pl-cpu (windows-2022, lightning, 3.9, 1.12) success
pl-cpu (windows-2022, lightning, 3.10, 1.13) success
pl-cpu (windows-2022, lightning, 3.10, 2.0) success
pl-cpu (windows-2022, lightning, 3.10, 2.1) success
pl-cpu (macOS-11, pytorch, 3.8, 1.13) success
pl-cpu (ubuntu-20.04, pytorch, 3.8, 1.13) success
pl-cpu (windows-2022, pytorch, 3.8, 1.13) success
pl-cpu (macOS-12, pytorch, 3.11, 2.0) success
pl-cpu (macOS-12, pytorch, 3.11, 2.1) success
pl-cpu (ubuntu-22.04, pytorch, 3.11, 2.0) success
pl-cpu (ubuntu-22.04, pytorch, 3.11, 2.1) success
pl-cpu (windows-2022, pytorch, 3.11, 2.0) success
pl-cpu (windows-2022, pytorch, 3.11, 2.1) success

These checks are required after the changes to src/lightning/fabric/utilities/__init__.py, src/lightning/fabric/utilities/data.py, src/lightning/pytorch/core/mixins/hparams_mixin.py, src/lightning/pytorch/core/saving.py, src/lightning/pytorch/utilities/parsing.py, tests/tests_pytorch/utilities/test_parsing.py.

🟢 pytorch_lightning: Azure GPU
Check ID Status
pytorch-lightning (GPUs) (testing Lightning | latest) success
pytorch-lightning (GPUs) (testing PyTorch | latest) success

These checks are required after the changes to src/lightning/pytorch/core/mixins/hparams_mixin.py, src/lightning/pytorch/core/saving.py, src/lightning/pytorch/utilities/parsing.py, tests/tests_pytorch/utilities/test_parsing.py, src/lightning/fabric/utilities/__init__.py, src/lightning/fabric/utilities/data.py.

🟢 pytorch_lightning: Benchmarks
Check ID Status
lightning.Benchmarks success

These checks are required after the changes to src/lightning/fabric/utilities/__init__.py, src/lightning/fabric/utilities/data.py, src/lightning/pytorch/core/mixins/hparams_mixin.py, src/lightning/pytorch/core/saving.py, src/lightning/pytorch/utilities/parsing.py.

🟢 fabric: Docs
Check ID Status
docs-make (fabric, doctest) success
docs-make (fabric, html) success

These checks are required after the changes to src/lightning/fabric/utilities/__init__.py, src/lightning/fabric/utilities/data.py, docs/source-fabric/api/utilities.rst, docs/source-fabric/guide/checkpoint.rst.

🟢 pytorch_lightning: Docs
Check ID Status
docs-make (pytorch, doctest) success
docs-make (pytorch, html) success

These checks are required after the changes to src/lightning/pytorch/core/mixins/hparams_mixin.py, src/lightning/pytorch/core/saving.py, src/lightning/pytorch/utilities/parsing.py, docs/source-pytorch/conf.py.

🟢 lightning_fabric: CPU workflow
Check ID Status
fabric-cpu (macOS-11, lightning, 3.8, 1.12, oldest) success
fabric-cpu (macOS-11, lightning, 3.9, 1.12) success
fabric-cpu (macOS-11, lightning, 3.10, 1.13) success
fabric-cpu (macOS-11, lightning, 3.10, 2.0) success
fabric-cpu (macOS-11, lightning, 3.11, 2.1) success
fabric-cpu (ubuntu-20.04, lightning, 3.8, 1.12, oldest) success
fabric-cpu (ubuntu-20.04, lightning, 3.9, 1.12) success
fabric-cpu (ubuntu-20.04, lightning, 3.10, 1.13) success
fabric-cpu (ubuntu-20.04, lightning, 3.10, 2.0) success
fabric-cpu (ubuntu-20.04, lightning, 3.11, 2.1) success
fabric-cpu (windows-2022, lightning, 3.8, 1.12, oldest) success
fabric-cpu (windows-2022, lightning, 3.9, 1.12) success
fabric-cpu (windows-2022, lightning, 3.10, 1.13) success
fabric-cpu (windows-2022, lightning, 3.10, 2.0) success
fabric-cpu (windows-2022, lightning, 3.11, 2.1) success
fabric-cpu (macOS-11, fabric, 3.8, 1.13) success
fabric-cpu (ubuntu-20.04, fabric, 3.8, 1.13) success
fabric-cpu (windows-2022, fabric, 3.8, 1.13) success
fabric-cpu (macOS-12, fabric, 3.11, 2.0) success
fabric-cpu (macOS-12, fabric, 3.11, 2.1) success
fabric-cpu (ubuntu-22.04, fabric, 3.11, 2.0) success
fabric-cpu (ubuntu-22.04, fabric, 3.11, 2.1) success
fabric-cpu (windows-2022, fabric, 3.11, 2.0) success
fabric-cpu (windows-2022, fabric, 3.11, 2.1) success

These checks are required after the changes to src/lightning/fabric/utilities/__init__.py, src/lightning/fabric/utilities/data.py, tests/tests_fabric/utilities/test_data.py.

🟢 lightning_fabric: Azure GPU
Check ID Status
lightning-fabric (GPUs) (testing Fabric | latest) success
lightning-fabric (GPUs) (testing Lightning | latest) success

These checks are required after the changes to src/lightning/fabric/utilities/__init__.py, src/lightning/fabric/utilities/data.py, tests/tests_fabric/utilities/test_data.py.

🟢 mypy
Check ID Status
mypy success

These checks are required after the changes to src/lightning/fabric/utilities/__init__.py, src/lightning/fabric/utilities/data.py, src/lightning/pytorch/core/mixins/hparams_mixin.py, src/lightning/pytorch/core/saving.py, src/lightning/pytorch/utilities/parsing.py.

🟢 install
Check ID Status
install-pkg (ubuntu-22.04, app, 3.8) success
install-pkg (ubuntu-22.04, app, 3.11) success
install-pkg (ubuntu-22.04, fabric, 3.8) success
install-pkg (ubuntu-22.04, fabric, 3.11) success
install-pkg (ubuntu-22.04, pytorch, 3.8) success
install-pkg (ubuntu-22.04, pytorch, 3.11) success
install-pkg (ubuntu-22.04, lightning, 3.8) success
install-pkg (ubuntu-22.04, lightning, 3.11) success
install-pkg (ubuntu-22.04, notset, 3.8) success
install-pkg (ubuntu-22.04, notset, 3.11) success
install-pkg (macOS-12, app, 3.8) success
install-pkg (macOS-12, app, 3.11) success
install-pkg (macOS-12, fabric, 3.8) success
install-pkg (macOS-12, fabric, 3.11) success
install-pkg (macOS-12, pytorch, 3.8) success
install-pkg (macOS-12, pytorch, 3.11) success
install-pkg (macOS-12, lightning, 3.8) success
install-pkg (macOS-12, lightning, 3.11) success
install-pkg (macOS-12, notset, 3.8) success
install-pkg (macOS-12, notset, 3.11) success
install-pkg (windows-2022, app, 3.8) success
install-pkg (windows-2022, app, 3.11) success
install-pkg (windows-2022, fabric, 3.8) success
install-pkg (windows-2022, fabric, 3.11) success
install-pkg (windows-2022, pytorch, 3.8) success
install-pkg (windows-2022, pytorch, 3.11) success
install-pkg (windows-2022, lightning, 3.8) success
install-pkg (windows-2022, lightning, 3.11) success
install-pkg (windows-2022, notset, 3.8) success
install-pkg (windows-2022, notset, 3.11) success

These checks are required after the changes to src/lightning/fabric/utilities/__init__.py, src/lightning/fabric/utilities/data.py, src/lightning/pytorch/core/mixins/hparams_mixin.py, src/lightning/pytorch/core/saving.py, src/lightning/pytorch/utilities/parsing.py.


Thank you for your contribution! 💜

Note
This comment is automatically generated and updates for 60 minutes every 180 seconds. If you have any other questions, contact carmocca for help.

Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

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

I think this pattern is not very Pythonic and can be confusing for users who are not super knowledgeable about Python: there's already been discussions around whether it's a good idea or not: https://lwn.net/Articles/818777

However, if we still want to suggest it, I would not call it State which might sound like this is the state of Fabric, or the model, or something similar to new users.

I would be specific and call it AttributeDict as before, which is exactly what it is and has been around for at leat 13 years (https://code.activestate.com/recipes/576972-attrdict)

@awaelchli awaelchli changed the title Add State container for Fabric Add AttributeDict container for Fabric Nov 15, 2023
@awaelchli awaelchli requested a review from carmocca November 16, 2023 06:00
@mergify mergify bot added the ready PRs ready to be merged label Nov 16, 2023
Copy link

codecov bot commented Nov 18, 2023

Codecov Report

Merging #18943 (7ddbaf3) into master (4e72dcc) will decrease coverage by 22%.
Report is 3 commits behind head on master.
The diff coverage is 77%.

Additional details and impacted files
@@            Coverage Diff            @@
##           master   #18943     +/-   ##
=========================================
- Coverage      76%      54%    -22%     
=========================================
  Files         443      438      -5     
  Lines       36120    36030     -90     
=========================================
- Hits        27303    19430   -7873     
- Misses       8817    16600   +7783     

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
checkpointing Related to checkpointing docs Documentation related fabric lightning.fabric.Fabric feature Is an improvement or enhancement fun Staff contributions outside working hours - to differentiate from the "community" label pl Generic label for PyTorch Lightning package ready PRs ready to be merged refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move AttributeDict to Fabric for convenient state representation
3 participants