-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Remove numpy
dependencies in src/lightning/pytorch
#19841
base: master
Are you sure you want to change the base?
Conversation
…/multiprocessing.py
src/lightning/pytorch
numpy
dependencies in src/lightning/pytorch
for more information, see https://pre-commit.ci
@@ -253,7 +252,9 @@ def update_main_process_results(self, trainer: "pl.Trainer", extra: Dict[str, An | |||
""" | |||
# NOTE: `get_extra_results` needs to be called before | |||
callback_metrics = extra["callback_metrics"] | |||
trainer.callback_metrics.update(apply_to_collection(callback_metrics, np.ndarray, lambda x: torch.tensor(x))) | |||
trainer.callback_metrics.update( | |||
apply_to_collection(callback_metrics, type(Tensor().numpy()), lambda x: torch.tensor(x)) |
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.
Is there a cleaner way to access numpy types (without import numpy
obviously)?
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.
I suggest to remove this conversion altogether (L255). The counterpart in L239 should then just clone the tensor instead of calling numpy(). This would then cover the case that is described in the comment and a numpy conversion is no longer needed.
What does this PR do?
Removes dependency on
numpy
in part of the codebase (src/lightning/pytorch
), as mentioned in #17278.Partially fixes #17278
Before submitting
PR review
Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:
Reviewer checklist
📚 Documentation preview 📚: https://pytorch-lightning--19841.org.readthedocs.build/en/19841/