-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update Frequency Transform #8537
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
base: dev
Are you sure you want to change the base?
Conversation
Signed-off-by: Eric Kerfoot <[email protected]>
WalkthroughInput signal dtype handling in monai/transforms/signal/array.py was changed: the signal is converted to a PyTorch double tensor at the start, iirnotch coefficients are created with dtype=torch.double, and filtfilt is invoked with the converted tensor. Public APIs remain unchanged. Development dependencies and CI/build constraints were updated: torchaudio added to requirements-dev.txt, torch minimum bumped to 2.5.1 in pyproject.toml and requirements.txt, and CI install steps adjusted to install torch/torchvision together with dev requirements. Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changes
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
monai/transforms/signal/array.py (1)
409-409
: Update function signature type hint.The function signature indicates it accepts
np.ndarray
but the implementation now works with any tensor-like input viaconvert_to_tensor
. Consider updating the type hint to reflect actual usage.Apply this diff to update the type hint:
- def __call__(self, signal: np.ndarray) -> Any: + def __call__(self, signal: NdarrayOrTensor) -> torch.Tensor:
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting
📒 Files selected for processing (2)
monai/transforms/signal/array.py
(1 hunks)requirements-dev.txt
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py
⚙️ CodeRabbit Configuration File
Review the Python code for quality and correctness. Ensure variable names adhere to PEP8 style guides, are sensible and informative in regards to their function, though permitting simple names for loop and comprehension variables. Ensure routine names are meaningful in regards to their function and use verbs, adjectives, and nouns in a semantically appropriate way. Docstrings should be present for all definition which describe each variable, return value, and raised exception in the appropriate section of the Google-style of docstrings. Examine code for logical error or inconsistencies, and suggest what may be changed to addressed these. Suggest any enhancements for code improving efficiency, maintainability, comprehensibility, and correctness. Ensure new or modified definitions will be covered by existing or new unit tests.
Files:
monai/transforms/signal/array.py
🧬 Code Graph Analysis (1)
monai/transforms/signal/array.py (1)
monai/utils/type_conversion.py (1)
convert_to_tensor
(113-181)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
- GitHub Check: min-dep-pytorch (2.7.1)
- GitHub Check: flake8-py3 (mypy)
- GitHub Check: build-docs
- GitHub Check: flake8-py3 (codeformat)
- GitHub Check: quick-py3 (ubuntu-latest)
- GitHub Check: flake8-py3 (pytype)
- GitHub Check: quick-py3 (windows-latest)
- GitHub Check: min-dep-os (ubuntu-latest)
- GitHub Check: packaging
- GitHub Check: min-dep-pytorch (2.8.0)
- GitHub Check: min-dep-os (windows-latest)
- GitHub Check: quick-py3 (macOS-latest)
- GitHub Check: min-dep-pytorch (2.6.0)
- GitHub Check: min-dep-py3 (3.9)
- GitHub Check: min-dep-py3 (3.12)
- GitHub Check: min-dep-pytorch (2.5.1)
- GitHub Check: min-dep-os (macOS-latest)
- GitHub Check: min-dep-py3 (3.11)
- GitHub Check: min-dep-py3 (3.10)
🔇 Additional comments (3)
monai/transforms/signal/array.py (3)
414-414
: LGTM - Explicit double precision conversion addresses NumPy compatibility.Converting the signal to double precision upfront resolves the numerical precision issues reported in issue #8520 with NumPy 2.3.1.
415-417
: LGTM - Consistent double precision for filter coefficients.The explicit dtype specification for iirnotch coefficients ensures numerical consistency with the input signal conversion.
418-418
: LGTM - Simplified filtfilt call with pre-converted signal.The change eliminates redundant tensor conversion inside filtfilt since the signal is already converted to a tensor at line 414.
Signed-off-by: Eric Kerfoot <[email protected]>
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
requirements.txt (1)
2-2
: Justify and document the Windows-specific exclusion of torch 2.7.0.If 2.7.0 is known-bad only on Windows, add a short comment and ensure CI excludes it. If the issue isn’t Windows-only, consider mirroring the exclusion on non-Windows too.
Proposed inline comment:
torch>=2.5.1, !=2.7.0; platform_system == "Windows" +# Exclude torch 2.7.0 on Windows due to a known upstream issue; re-evaluate when fixed.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting
📒 Files selected for processing (2)
pyproject.toml
(1 hunks)requirements.txt
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- pyproject.toml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
- GitHub Check: min-dep-pytorch (2.5.1)
- GitHub Check: min-dep-pytorch (2.8.0)
- GitHub Check: min-dep-pytorch (2.7.1)
- GitHub Check: min-dep-py3 (3.12)
- GitHub Check: min-dep-py3 (3.11)
- GitHub Check: min-dep-pytorch (2.6.0)
- GitHub Check: min-dep-os (windows-latest)
- GitHub Check: min-dep-py3 (3.9)
- GitHub Check: min-dep-py3 (3.10)
- GitHub Check: quick-py3 (ubuntu-latest)
- GitHub Check: min-dep-os (macOS-latest)
- GitHub Check: packaging
- GitHub Check: min-dep-os (ubuntu-latest)
- GitHub Check: quick-py3 (macOS-latest)
- GitHub Check: flake8-py3 (codeformat)
- GitHub Check: flake8-py3 (pytype)
- GitHub Check: quick-py3 (windows-latest)
- GitHub Check: flake8-py3 (mypy)
- GitHub Check: build-docs
🔇 Additional comments (1)
requirements.txt (1)
1-1
: Bump to torch>=2.5.1 (non-Windows) looks fine.Matches the pyproject change per PR notes. No syntax issues with the environment marker.
torch>=2.5.1; platform_system != "Windows" | ||
torch>=2.5.1, !=2.7.0; platform_system == "Windows" |
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.
💡 Verification agent
🧩 Analysis chain
Confirm non-breaking claim and dependency consistency (torch, torchaudio, numpy).
- Raising the torch floor to 2.5.1 narrows supported environments. If the PR is marked “non-breaking,” confirm our supported matrix already requires ≥2.5.1 and update docs/release notes if needed.
- PR summary mentions “adds torchaudio as a dependency.” If torchaudio is only added to dev requirements, that’s fine; if runtime code now depends on it, add a runtime pin (or an extra like monai[audio]) and ensure torch/torchaudio version compatibility.
- Given the NumPy 2.3.1 test failure is the driver, ensure our NumPy pin and CI cover 2.x and that the dtype fix resolves the test across OSes.
Run this script to check for constraint consistency and runtime usage:
I can help propose extras (e.g., [audio]
) and align pins once we see the scan output.
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Torch constraints across repo =="
rg -n --no-heading -A2 -B2 $'torch\\s*[<>=!]' || true
echo
echo "== Torchaudio presence (constraints/imports) =="
rg -n --no-heading -A2 -B2 $'torchaudio' || true
echo
echo "== Numpy constraints (requirements*/pyproject) =="
rg -n --no-heading $'^numpy.*' requirements* pyproject.toml || true
echo
echo "== CI workflows referencing torch versions =="
fd -t f -a .github | xargs -I {} rg -n --no-heading -H 'torch|pytorch|TORCH_VERSION' {} || true
Length of output: 18092
Action required — align torch pins, confirm torchaudio runtime vs dev, and verify NumPy 2.x CI
Scan summary (concise): pyproject.toml and requirements.txt require torch>=2.5.1, but setup.cfg/docs/env still allow older torch/pytorch; torchaudio appears only in dev requirements; numpy is pinned >=1.24,<3.0.
Files needing attention:
- pyproject.toml — torch>=2.5.1 (OK if intended).
- requirements.txt — torch>=2.5.1 / Windows variant (OK).
- setup.cfg — install_requires has torch>=2.4.1 — update to >=2.5.1 to match or document the intended variance.
- environment-dev.yml — pytorch>=2.3.0 — update or justify (dev env still allows older PyTorch).
- docs/requirements.txt — references torch>=2.4.1 and a 2.4.1 CPU wheel — update docs wheel/pin to match new floor.
- requirements-dev.txt — contains torchaudio (dev only). If torchaudio is now a runtime dependency, move it to runtime deps (pyproject/setup.cfg/requirements) or provide an extra (e.g., [audio]) and pin to a torchaudio version compatible with torch>=2.5.1.
- monai/transforms/signal/array.py & tests/transforms/test_signal_remove_frequency.py — use optional_import/skipUnless for torchaudio; ensure CI either installs torchaudio for those tests or accepts skips.
- numpy (requirements.txt / setup.cfg / environment-dev.yml) — pinned >=1.24,<3.0. If NumPy 2.3.1 caused failures, add CI coverage for numpy==2.3.1 and confirm the dtype fix resolves the test across OSes.
- .github workflows — no references to torch/pytorch/TORCH_VERSION found; add/update CI matrix to explicitly exercise the declared minimal torch and numpy versions.
Please update the listed files or confirm the intended supported matrix and whether torchaudio is a runtime dependency; I can prepare concrete diffs if you want.
🤖 Prompt for AI Agents
In requirements.txt lines 1-2, align the torch pins across the repository:
update setup.cfg install_requires, environment-dev.yml, and
docs/requirements.txt to require torch>=2.5.1 (or document intentional
divergence), and remove the outdated 2.4.1 CPU wheel reference; decide whether
torchaudio is a runtime dependency—if it is, move it from requirements-dev.txt
into runtime deps (pyproject/setup.cfg/requirements) or expose it as an optional
extra (e.g., [audio]) with a torchaudio version compatible with torch>=2.5.1,
otherwise make all torchaudio uses in monai/transforms/signal/array.py and its
tests use optional_import/skipUnless so tests skip when torchaudio is absent;
pin numpy policy consistently (keep >=1.24,<3.0), add CI jobs to run with
numpy==2.3.1 and the minimal torch>=2.5.1 (including Windows variant), and
update GitHub workflow matrices to explicitly exercise the declared minimal
torch and numpy versions so CI validates the compatibility matrix.
…ent PyTorch version Signed-off-by: Eric Kerfoot <[email protected]>
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.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
.github/workflows/pythonapp.yml (1)
95-98
: Avoid double-installing torch/vision on Windows; make the general install step non-Windows or unify installs.Windows installs torch/vision via the PyTorch CPU index (Lines 95–98), then the general step reinstalls them (Line 107) without the index, risking re-resolution and mismatched wheels.
Option A (minimal): gate the general dependency step to non-Windows:
- - name: Install the dependencies + - if: runner.os != 'windows' + name: Install the dependencies run: | python -m pip install --user --upgrade pip wheel cat "requirements-dev.txt" - python -m pip install torch==2.5.1 torchvision==0.20.1 -r requirements-dev.txt + python -m pip install --index-url https://download.pytorch.org/whl/cpu torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 + python -m pip install -r requirements-dev.txt python -m pip list python setup.py develop # test no compile installationOption B (preferred): remove the Windows-only torch step and rely on the unified CPU-index install for all OSes, to keep one source of truth. I can draft that change if you prefer.
Also applies to: 103-110
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting
📒 Files selected for processing (1)
.github/workflows/pythonapp.yml
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
- GitHub Check: min-dep-pytorch (2.8.0)
- GitHub Check: build-docs
- GitHub Check: packaging
- GitHub Check: flake8-py3 (codeformat)
- GitHub Check: min-dep-os (ubuntu-latest)
- GitHub Check: quick-py3 (windows-latest)
- GitHub Check: min-dep-pytorch (2.7.1)
- GitHub Check: flake8-py3 (mypy)
- GitHub Check: min-dep-os (macOS-latest)
- GitHub Check: quick-py3 (ubuntu-latest)
- GitHub Check: flake8-py3 (pytype)
- GitHub Check: min-dep-pytorch (2.5.1)
- GitHub Check: quick-py3 (macOS-latest)
- GitHub Check: min-dep-py3 (3.9)
- GitHub Check: min-dep-pytorch (2.6.0)
- GitHub Check: min-dep-py3 (3.12)
- GitHub Check: min-dep-py3 (3.10)
- GitHub Check: min-dep-os (windows-latest)
- GitHub Check: min-dep-py3 (3.11)
Hi @KumoLiu I think this works now. I had an issue with gloo not working under Windows with PyTorch 2.8 so dist tests wouldn't pass. I updated the CICD system to use the PyTorch 2.5.1 it should use for these tests in one place, but we should look into updating how the tests are run later to make this better. For now this fix works however, but other tests may be installing PyTorch 2.8 over top of version 2.5.1. |
Fixes #8520.
Description
This adds
torchaudio
as a dependency and changesSignalRemoveFrequency
to explicitly convert input to double precision, this seems to be needed for new versions.Types of changes
./runtests.sh -f -u --net --coverage
../runtests.sh --quick --unittests --disttests
.make html
command in thedocs/
folder.