-
Notifications
You must be signed in to change notification settings - Fork 21.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
make torch.testing asserts importable #54769
Conversation
move coda out of torch.testing.__init__ make everything importable again delete torch/testing/asserts.py please flake8 provide more stuff in torch.testing provide even more stuff in torch.testing expose more fix import make private expose more fix mypy [ghstack-poisoned]
move coda out of torch.testing.__init__ make everything importable again delete torch/testing/asserts.py please flake8 provide more stuff in torch.testing provide even more stuff in torch.testing expose more fix import make private expose more fix mypy ghstack-source-id: 6c34c237c4d8c0d248edd66a329aefc7260b8723 Pull Request resolved: #54769
💊 CI failures summary and remediationsAs of commit 436356e (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions to the (internal) Dr. CI Users group. |
move coda out of torch.testing.__init__ make everything importable again delete torch/testing/asserts.py please flake8 provide more stuff in torch.testing provide even more stuff in torch.testing expose more fix import make private expose more fix mypy [ghstack-poisoned]
Follow-up to #53820. This - makes the `asserts.py` module private as per suggestion from @rgommers in #53820 (comment). With this the functions should only be accessible through `torch.testing`, giving us the option the change the underlying structure later. - moves the code from `torch/testing/__init__.py` to `torch/testing/_core.py` (happy to accept other name suggestions). Otherwise we can't import the new `_asserts.py` in `torch/testing/__init__.py` due to circular imports. ghstack-source-id: 3b9dfacf4bf5f01b827276be4c3724bec6745e9f Pull Request resolved: #54769
@mruberry Not sure about the test failures. For some reason importing
it seems someone planned for this. Do you have insights? |
I'd spend some more time debugging (possibly after a rebase for good measure). It looks like two tests are failing. The ModuleNotFoundError is coming from a "fake NumPy" that was added for testing purposes in February. What's causing it to fail? |
#52794 added a test to check that
The new |
Follow-up to #53820. This - makes the `asserts.py` module private as per suggestion from @rgommers in #53820 (comment). With this the functions should only be accessible through `torch.testing`, giving us the option the change the underlying structure later. - moves the code from `torch/testing/__init__.py` to `torch/testing/_core.py` (happy to accept other name suggestions). Otherwise we can't import the new `_asserts.py` in `torch/testing/__init__.py` due to circular imports. [ghstack-poisoned]
Follow-up to #53820. This - makes the `asserts.py` module private as per suggestion from @rgommers in #53820 (comment). With this the functions should only be accessible through `torch.testing`, giving us the option the change the underlying structure later. - moves the code from `torch/testing/__init__.py` to `torch/testing/_core.py` (happy to accept other name suggestions). Otherwise we can't import the new `_asserts.py` in `torch/testing/__init__.py` due to circular imports. [ghstack-poisoned]
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.
Cool; so this also fixes that importing torch imports numpy?
I wonder if we should add a test for that?
I like the comment you made in the code about this. Would you update this PR description, too? We should talk about our plan for the structure of all this code at our next testing sync next week. |
Correct.
The test that failed before tests for exactly that: pytorch/.jenkins/pytorch/test.sh Lines 160 to 164 in 444e5f0
Still, the error message through me off
Maybe we can change it into something more descriptive like raise ModuleNotFoundError("Importing 'torch' must not require 'numpy' to be present.") Cc @malfet |
I need to investigate this further internally. The new structure either requires some internal tweaks or there's a problem with the specifying the imports relative to the current location. Example failure:
|
Follow-up to #53820. This - makes the `asserts.py` module private as per suggestion from @rgommers in #53820 (comment). With this the functions should only be accessible through `torch.testing`, giving us the option the change the underlying structure later. - moves the code from `torch/testing/__init__.py` to `torch/testing/_core.py` (happy to accept other name suggestions). Otherwise we can't import the new `_asserts.py` in `torch/testing/__init__.py` due to circular imports. - factors out some functionality from `torch/testing/_internal/common_utils.py` that is needed in new `_asserts.py` to `torch/testing/_internal/testing_utils.py` to not be dependent on `numpy` at import. Differential Revision: [D27438451](https://our.internmc.facebook.com/intern/diff/D27438451) [ghstack-poisoned]
I had some more time to investigate the internal build system, and I think the issue is simply that the current build system isn't designed to allow _internal to be imported into testing, since torch.testing is always imported but torch.testing._internal is only imported on test builds. We could try and tweak the internal build system, but I'd prefer we just work around the issue. Can we just copy parts of _internal we need for asserts.py into torch/testing/asserts.py for now, for example? |
Follow-up to #53820. This - makes the `asserts.py` module private as per suggestion from @rgommers in #53820 (comment). With this the functions should only be accessible through `torch.testing`, giving us the option the change the underlying structure later. - moves the code from `torch/testing/__init__.py` to `torch/testing/_core.py` (happy to accept other name suggestions). Otherwise we can't import the new `_asserts.py` in `torch/testing/__init__.py` due to circular imports. - factors out some functionality from `torch/testing/_internal/common_utils.py` that is needed in new `_asserts.py` to `torch/testing/_internal/testing_utils.py` to not be dependent on `numpy` at import. Differential Revision: [D27438451](https://our.internmc.facebook.com/intern/diff/D27438451) [ghstack-poisoned]
Yes, we can. I've removed the pytorch/torch/testing/_internal/common_utils.py Lines 858 to 873 in df299db
Thus, it can simply replaced by |
Let's see what the internal build system thinks. |
* #54769 make torch.testing asserts importable [ghstack-poisoned]
* #54769 make torch.testing asserts importable [ghstack-poisoned]
Summary: Pull Request resolved: pytorch#54784 * pytorch#54769 make torch.testing asserts importable Test Plan: Imported from OSS Reviewed By: jbschlosser Differential Revision: D27717422 Pulled By: mruberry fbshipit-source-id: 7526af4f17d8ffcc4ea5e5a5d98f07ceac89df40
Stack from ghstack:
torch.testing
#55385 Add support for checking tensor containers intorch.testing
Follow-up to #53820. This
asserts.py
module private as per suggestion from @rgommers in initial draft for assert_tensors_(equal|allclose) in torch.testing #53820 (comment). With this the functions should only be accessible throughtorch.testing
, giving us the option the change the underlying structure later.torch/testing/__init__.py
totorch/testing/_core.py
(happy to accept other name suggestions). Otherwise we can't import the new_asserts.py
intorch/testing/__init__.py
due to circular imports.torch/testing/_internal/common_utils.py
that is needed in new_asserts.py
totorch/testing/_internal/testing_utils.py
to not be dependent onnumpy
at import.Differential Revision: D27438451