Skip to content
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

Fix packaging imports in version comparison logic #8347

Merged

Conversation

nkaenzig
Copy link
Contributor

@nkaenzig nkaenzig commented Feb 18, 2025

Fixes #8349

Description

The current behaviour is that pkging, has_ver = optional_import("packaging.Version") always returns has_ver=False because the import always fails (the Version class is exposed by the packaging.version submodule).

This issue previously didn't surface, because when the import fails, it would just continue to use the fallback logic. However, there seem to be more hidden and more severe implications, which ultimately led me to discovering this particular bug: Function like floor_divide() in monai.transforms that check the module version using this logic are called many times in common ML dataloading workflows. The failed imports somehow can lead to OOM errors and the main process being killed (see #8348). Maybe when optional_import fails to import a module, the lazy exceptions somehow stack up in memory when this function is called many times in a short time period?

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.

@nkaenzig nkaenzig marked this pull request as draft February 18, 2025 16:21
@nkaenzig nkaenzig marked this pull request as ready for review February 18, 2025 17:26
Copy link
Contributor

@KumoLiu KumoLiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, LGTM.

@KumoLiu
Copy link
Contributor

KumoLiu commented Feb 19, 2025

/build

@KumoLiu KumoLiu enabled auto-merge (squash) February 19, 2025 05:41
@KumoLiu KumoLiu merged commit 960c59b into Project-MONAI:dev Feb 19, 2025
28 checks passed
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.

Faulty imports of packaging in version comparison logic
2 participants