-
Notifications
You must be signed in to change notification settings - Fork 1.3k
docs: add differentiability warning for Warp with mode='nearest' #8629
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?
docs: add differentiability warning for Warp with mode='nearest' #8629
Conversation
WalkthroughThis PR adds an informational note to the Warp class constructor docstring in Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Cache: Disabled due to data retention organization setting Knowledge base: Disabled due to 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
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 |
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: 0
🧹 Nitpick comments (1)
monai/networks/blocks/warp.py (1)
56-61: Fix minor formatting inconsistencies in the documentation note.The content is accurate and addresses the issue well, but two formatting tweaks are needed for consistency with the existing docstring style:
- Line 56: Remove the space after
=inmode=(should bemode="nearest"notmode= "nearest")- Line 58: Use backticks for code literals (
"bilinear","trilinear") instead of straight quotes, consistent with the rest of the docstringApply this diff to fix the formatting:
- Note that using mode= ``"nearest"`` makes the warping operation effectively non-differentiable: + Note that using mode=``"nearest"`` makes the warping operation effectively non-differentiable: gradients are zero almost everywhere, which can block gradient flow during training. - For learning-based registration, use "bilinear" (2D) or "trilinear" (3D) interpolation instead. + For learning-based registration, use ``"bilinear"`` (2D) or ``"trilinear"`` (3D) interpolation instead.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
📒 Files selected for processing (1)
monai/networks/blocks/warp.py(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/networks/blocks/warp.py
ericspod
left a comment
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.
Fixes #8540 .
Description
This PR updates the docstring of monai.networks.blocks.Warp to clarify that mode='nearest' results in zero gradients almost everywhere, effectively blocking gradient flow in registration training.
Changes:
Added a note to the Warp docstring about the gradient behavior of mode='nearest'.
Added a reference to the semi-supervised registration tutorial:
https://github.com/Project-MONAI/tutorials/blob/main/3d_registration/learn2reg_oasis_unpaired_brain_mr.ipynb
Next Steps (future PR):
Extend VoxelMorph.forward to handle optional label and keypoint arguments for consistent warping behavior.
Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.