Skip to content

Fix Invertd confusion with postprocessing transforms #8526

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

eclipse0922
Copy link

@eclipse0922 eclipse0922 commented Aug 6, 2025

Fixes #8396

Description

  • Modified Invertd to only invert preprocessing transforms
  • When orig_key == key, limits transform_info to preprocessing transforms only
  • Counts invertible transforms in preprocessing and uses only that many from applied_operations
  • Added test case to verify the fix

The issue occurred because Invertd would try to invert all transforms in applied_operations, including those from postprocessing. When Lambdad was applied in postprocessing before Invertd, it would be at the top of the stack, causing ID mismatch errors when preprocessing transforms tried to pop themselves.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

Copy link

coderabbitai bot commented Aug 6, 2025

Warning

Rate limit exceeded

@eclipse0922 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 51 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 8e34cc0 and 7d8e0b7.

📒 Files selected for processing (2)
  • monai/transforms/post/dictionary.py (1 hunks)
  • tests/transforms/inverse/test_invertd.py (1 hunks)

Walkthrough

The Invertd.__call__ method in monai/transforms/post/dictionary.py was updated to filter out postprocessing transforms from the applied operations metadata when inverting. This ensures only preprocessing transforms are considered during inversion if the original and current keys match. A new unit test was added in tests/transforms/inverse/test_invertd.py to verify correct inversion behavior when a Lambdad transform is present in the postprocessing pipeline.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Ensure Invertd ignores postprocessing transforms and only inverts those from preprocessing pipeline (#8396)
Add test to verify Invertd behavior with postprocessing Lambdad (#8396)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between b92b2ce and 9f1df99.

📒 Files selected for processing (2)
  • monai/transforms/post/dictionary.py (1 hunks)
  • tests/transforms/inverse/test_invertd.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/transforms/post/dictionary.py
  • tests/transforms/inverse/test_invertd.py
🔇 Additional comments (1)
tests/transforms/inverse/test_invertd.py (1)

140-182: Excellent test coverage for the fix.

Test directly validates the issue #8396 scenario - Lambdad in postprocessing before Invertd. Proper setup, assertions, and deterministic seeding.

@eclipse0922 eclipse0922 force-pushed the fix-invertd-postproc-transforms branch 2 times, most recently from 9c0b530 to 8e34cc0 Compare August 6, 2025 10:11
- Modified Invertd to only invert preprocessing transforms
- When orig_key == key, limits transform_info to preprocessing transforms only
- Counts invertible transforms in preprocessing and uses only that many from applied_operations
- Fixes issue Project-MONAI#8396 where Lambdad before Invertd caused errors
- Added test case to verify the fix

The issue occurred because Invertd would try to invert all transforms
in applied_operations, including those from postprocessing. When Lambdad
was applied in postprocessing before Invertd, it would be at the top of
the stack, causing ID mismatch errors when preprocessing transforms tried
to pop themselves.

Fix Invertd confusion with postprocessing transforms

- Modified Invertd to only invert preprocessing transforms
- When orig_key == key, limits transform_info to preprocessing transforms only
- Counts invertible transforms in preprocessing and uses only that many from applied_operations
- Fixes issue Project-MONAI#8396 where Lambdad before Invertd caused errors
- Added test case to verify the fix

The issue occurred because Invertd would try to invert all transforms
in applied_operations, including those from postprocessing. When Lambdad
was applied in postprocessing before Invertd, it would be at the top of
the stack, causing ID mismatch errors when preprocessing transforms tried
to pop themselves.

Signed-off-by: sewon.jeon <[email protected]>
@eclipse0922 eclipse0922 force-pushed the fix-invertd-postproc-transforms branch from 91b69ed to 7d8e0b7 Compare August 6, 2025 10:19
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.

Invertd Confused by Invertible Transforms in Postprocessing
1 participant