Skip to content

Perf(test): reuse random data across container types in quantile test - #8985

Merged
ericspod merged 5 commits into
Project-MONAI:devfrom
aymuos15:perf/quantile-reuse-data
Oct 1, 2026
Merged

ericspod merged 5 commits into
Project-MONAI:devfrom
aymuos15:perf/quantile-reuse-data

Conversation

@aymuos15

@aymuos15 aymuos15 commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

test_many_elements_quantile allocated a fresh np.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:

Median wall (3 runs) Individual runs
Before 17.16s 18.36, 16.74, 17.16
After 12.01s 12.19, 11.99, 12.01

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

  • Non-breaking change (test-only; no functional code touched)
  • Tests pass locally (pytest tests/transforms/test_utils_pytorch_numpy_unification.py)

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>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: Project-MONAI/MONAI/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: fc90af69-755a-42b8-9138-4253c7cd9bd1

📥 Commits

Reviewing files that changed from the base of the PR and between 8becf41 and d6695b0.

📒 Files selected for processing (1)
  • tests/transforms/test_utils_pytorch_numpy_unification.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The quantile test now generates one random NumPy array for each element count. It converts that array to each supported array type before checking percentile results.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~3 minutes

Merge Risk: ⚪ Minimal · up to d6695

This test-only change reuses inputs across array types without an identified loss of test coverage; no actionable mergeability risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: reusing random data across container types in the quantile test.
Description check ✅ Passed The description explains the motivation, implementation, performance impact, test scope, and relevant environment. It omits the issue reference and several template checklist items, but it is otherwis…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ericspod
ericspod enabled auto-merge (squash) October 1, 2026 14:47
@ericspod
ericspod merged commit 5a61f40 into Project-MONAI:dev Oct 1, 2026
30 checks passed
@aymuos15
aymuos15 deleted the perf/quantile-reuse-data branch October 6, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants