Perf(test): reuse random data across container types in quantile test#8985
Open
aymuos15 wants to merge 2 commits into
Open
Perf(test): reuse random data across container types in quantile test#8985aymuos15 wants to merge 2 commits into
aymuos15 wants to merge 2 commits into
Conversation
test_many_elements_quantile regenerated random data for every container type; generate it once per element count and reuse across types. Test-only speedup, identical coverage. Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
Contributor
📝 WalkthroughWalkthroughThe change updates a test in test_utils_pytorch_numpy_unification.py. The random data array is now generated once per elements size, outside the backend conversion loop, rather than being regenerated within nested loop iterations. The data is converted to x per backend, then quantile assertions run per input type using that shared x. Estimated code review effort: 1 (Trivial) | ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
test_many_elements_quantileallocated a freshnp.random.randn(elements)array — up to 17M elements (~130 MB) — inside the innermost loop, so the same large array was regenerated once for every(container type, element count, quantile-arg type)combination. The random values are irrelevant to the test (assertions only check the return type and that CPU/GPU results agree), so the repeated allocation and RNG fill added runtime without adding coverage.This makes for the data generation to once per element count and reuses it across the container and argument types.
@skip_if_quick def test_many_elements_quantile(self): # pytorch#64947 - for p in TEST_NDARRAYS: - for elements in (1000, 17_000_000): + for elements in (1000, 17_000_000): + data = np.random.randn(elements) + for p in TEST_NDARRAYS: + x = p(data) for t in [*TEST_NDARRAYS, list]: - x = p(np.random.randn(elements)) q = percentile(x, t([10, 50]))Performance
Wall-clock of
pytest tests/transforms/test_utils_pytorch_numpy_unification.py, median of 3 runs on the same machine:Machine: 12th Gen Intel Core i7-12800H (20 threads), Ubuntu 22.04.5 (kernel 6.8.0-124), Python 3.10.12, torch 2.10.0+cu128, CUDA available (NVIDIA RTX A1000 Laptop GPU).
Types of changes
pytest tests/transforms/test_utils_pytorch_numpy_unification.py)