Skip to content

Fix using a non-tuple sequence for multidimensional indexing that wil…#8732

Open
aarpon wants to merge 1 commit intoProject-MONAI:devfrom
aitoo:fix/non_tuple_indexing
Open

Fix using a non-tuple sequence for multidimensional indexing that wil…#8732
aarpon wants to merge 1 commit intoProject-MONAI:devfrom
aitoo:fix/non_tuple_indexing

Conversation

@aarpon
Copy link

@aarpon aarpon commented Feb 5, 2026

Fix using a non-tuple sequence for multidimensional indexing that will result in error in pytorch 2.9.

Fixes # .

Description

The SlidingWindowInferer complains that from PyTorch 2.9, using non-tuple sequences to slice into Tensors will result in an error (or, worse, misbehave). This patch targets all places in monai/inferers/utils.py where indexing may happen with lists or other types of sequences.

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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

This PR modifies monai/inferers/utils.py to normalize tensor indexing by converting list-based indices to tuples throughout the sliding window inference logic. Changes affect batched and non-batched inference paths, including data gathering, buffer writes, and coordinate accumulation operations. No public API signatures are altered.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed Title directly relates to the main change: converting non-tuple sequences to tuples for multidimensional indexing in PyTorch 2.9.
Description check ✅ Passed Description covers the issue, solution, and testing status. Some non-critical checklist items are unchecked, but required information is present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

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

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.

1 participant