Skip to content

fix: replace set_track_meta with F.interpolate in RandSimulateLowResolution (#8409)#8837

Draft
chhayankjain wants to merge 2 commits intoProject-MONAI:devfrom
chhayankjain:8242-add-use-softmax-to-dice-focal-loss
Draft

fix: replace set_track_meta with F.interpolate in RandSimulateLowResolution (#8409)#8837
chhayankjain wants to merge 2 commits intoProject-MONAI:devfrom
chhayankjain:8242-add-use-softmax-to-dice-focal-loss

Conversation

@chhayankjain
Copy link
Copy Markdown

Fixes #8409

Description

RandSimulateLowResolution internally performs a downsample → upsample cycle using two
Resize transforms. To prevent these from being recorded in the invertible transform
stack, the previous implementation temporarily toggled the global set_track_meta(False)
flag and restored it afterward.

This is not thread-safe: in multi-threaded data loading (e.g. ThreadDataLoader), another
thread calling get_track_meta() between the toggle and the restore would silently receive
the wrong value, causing incorrect metadata tracking behaviour.

Fix: replace the Resize transforms with direct torch.nn.functional.interpolate calls on
a plain tensor obtained via convert_to_tensor(img, track_meta=False). This avoids any
global state mutation entirely. Output dtype (float32) and metadata-copy behaviour are
preserved from the original implementation. set_track_meta is also removed from the import
since it is no longer used anywhere in the file.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • 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.

…lution (Project-MONAI#8409)

Signed-off-by: chhayankjain <chhayank44@gmail.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e63fb162-d8c8-4dfb-9cf9-60ac2db83dbc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

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

@chhayankjain
Copy link
Copy Markdown
Author

/black

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.

RandSimulateLowResolution race condition with set_track_meta()

1 participant