KEMBAR78
Safely import optional python packages by roclark · Pull Request #13936 · NVIDIA-NeMo/NeMo · GitHub
Skip to content

Conversation

@roclark
Copy link
Contributor

@roclark roclark commented Jun 16, 2025

What does this PR do ?

This update safely imports optional Python packages which are incompatible with Windows and MacOS. This allows nemo_toolkit to be installable and usable on Windows and MacOS, especially in conjunction with NeMo-Run.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • Documentation

@dimapihtar dimapihtar self-requested a review June 17, 2025 15:41
Copy link
Collaborator

@dimapihtar dimapihtar left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

@github-actions
Copy link
Contributor

github-actions bot commented Jul 9, 2025

This PR is stale because it has been open for 14 days with no activity. Remove stale label or comment or update or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Jul 9, 2025
@ahmadki
Copy link
Member

ahmadki commented Jul 9, 2025

@dimapihtar , @marcromeyn : what is the next step for this PR ?

@ri-roee
Copy link

ri-roee commented Jul 10, 2025

This would be huge for us as well, +1!

roclark and others added 3 commits July 10, 2025 12:14
The nvidia-resiliency-ext package is not compatible with Windows/MacOS
currently and cannot be installed directly on those platforms. Given the
number of nested imports in the nemo.collections.llm API, it will try and
automatically import the resliency package even if not used. Safely
importing the package allows all modules to be imported without blocking
on the resiliency package for incompatible platforms. This opens up
greater support on more platforms.

If the nvidia-resiliency-ext package is needed when these lines are called,
it will throw an import error only when directly called.

Signed-Off-By: Robert Clark <roclark@nvidia.com>
The default modelopt model transforms rely on the modelopt package being
installed which is not available on all platforms. This module gets
auto-imported when importing the nemo.collections.llm module and will
fail on platforms that don't support modelopt, such as Windows and MacOS,
even if the package isn't used.

Safely importing the package should allow the toolkit to be runnable on
both Windows and MacOS in a minimal state, which increases its
functionality, especially while paired with NeMo-Run.

Signed-Off-By: Robert Clark <roclark@nvidia.com>
Signed-off-by: roclark <roclark@users.noreply.github.com>
@hemildesai hemildesai force-pushed the roclark/safe-import-nvidia-resiliency branch from c7026b7 to cee2726 Compare July 10, 2025 19:14
@hemildesai hemildesai merged commit e04ee42 into NVIDIA-NeMo:main Jul 10, 2025
53 checks passed
chtruong814 pushed a commit that referenced this pull request Jul 11, 2025
This reverts commit e04ee42.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
chtruong814 added a commit that referenced this pull request Jul 11, 2025
This reverts commit e04ee42.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Co-authored-by: Robert Clark <roclark@users.noreply.github.com>
chtruong814 added a commit that referenced this pull request Jul 11, 2025
)"

This reverts commit 808845b.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
chtruong814 added a commit that referenced this pull request Jul 11, 2025
* Revert "Revert "Safely import optional python packages (#13936)" (#14197)"

This reverts commit 808845b.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>

* Fix LocalCheckpointCallback safe import

Signed-off-by: Charlie Truong <chtruong@nvidia.com>

---------

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
AmirHussein96 pushed a commit to AmirHussein96/NeMo that referenced this pull request Jul 23, 2025
* Safely import nvidia-resiliency-ext package

The nvidia-resiliency-ext package is not compatible with Windows/MacOS
currently and cannot be installed directly on those platforms. Given the
number of nested imports in the nemo.collections.llm API, it will try and
automatically import the resliency package even if not used. Safely
importing the package allows all modules to be imported without blocking
on the resiliency package for incompatible platforms. This opens up
greater support on more platforms.

If the nvidia-resiliency-ext package is needed when these lines are called,
it will throw an import error only when directly called.

Signed-Off-By: Robert Clark <roclark@nvidia.com>

* Safely import modelopt algorithms

The default modelopt model transforms rely on the modelopt package being
installed which is not available on all platforms. This module gets
auto-imported when importing the nemo.collections.llm module and will
fail on platforms that don't support modelopt, such as Windows and MacOS,
even if the package isn't used.

Safely importing the package should allow the toolkit to be runnable on
both Windows and MacOS in a minimal state, which increases its
functionality, especially while paired with NeMo-Run.

Signed-Off-By: Robert Clark <roclark@nvidia.com>

* Apply isort and black reformatting

Signed-off-by: roclark <roclark@users.noreply.github.com>

---------

Signed-off-by: Robert Clark <roclark@nvidia.com>
Signed-off-by: roclark <roclark@users.noreply.github.com>
Signed-off-by: Amir Hussein <amhussein@nvidia.com>
AmirHussein96 pushed a commit to AmirHussein96/NeMo that referenced this pull request Jul 23, 2025
…VIDIA-NeMo#14197)

This reverts commit e04ee42.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Co-authored-by: Robert Clark <roclark@users.noreply.github.com>
Signed-off-by: Amir Hussein <amhussein@nvidia.com>
AmirHussein96 pushed a commit to AmirHussein96/NeMo that referenced this pull request Jul 23, 2025
…DIA-NeMo#14198)

* Revert "Revert "Safely import optional python packages (NVIDIA-NeMo#13936)" (NVIDIA-NeMo#14197)"

This reverts commit 808845b.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>

* Fix LocalCheckpointCallback safe import

Signed-off-by: Charlie Truong <chtruong@nvidia.com>

---------

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Signed-off-by: Amir Hussein <amhussein@nvidia.com>
monica-sekoyan pushed a commit that referenced this pull request Aug 4, 2025
* Safely import nvidia-resiliency-ext package

The nvidia-resiliency-ext package is not compatible with Windows/MacOS
currently and cannot be installed directly on those platforms. Given the
number of nested imports in the nemo.collections.llm API, it will try and
automatically import the resliency package even if not used. Safely
importing the package allows all modules to be imported without blocking
on the resiliency package for incompatible platforms. This opens up
greater support on more platforms.

If the nvidia-resiliency-ext package is needed when these lines are called,
it will throw an import error only when directly called.

Signed-Off-By: Robert Clark <roclark@nvidia.com>

* Safely import modelopt algorithms

The default modelopt model transforms rely on the modelopt package being
installed which is not available on all platforms. This module gets
auto-imported when importing the nemo.collections.llm module and will
fail on platforms that don't support modelopt, such as Windows and MacOS,
even if the package isn't used.

Safely importing the package should allow the toolkit to be runnable on
both Windows and MacOS in a minimal state, which increases its
functionality, especially while paired with NeMo-Run.

Signed-Off-By: Robert Clark <roclark@nvidia.com>

* Apply isort and black reformatting

Signed-off-by: roclark <roclark@users.noreply.github.com>

---------

Signed-off-by: Robert Clark <roclark@nvidia.com>
Signed-off-by: roclark <roclark@users.noreply.github.com>
monica-sekoyan pushed a commit that referenced this pull request Aug 4, 2025
This reverts commit e04ee42.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Co-authored-by: Robert Clark <roclark@users.noreply.github.com>
monica-sekoyan pushed a commit that referenced this pull request Aug 4, 2025
* Revert "Revert "Safely import optional python packages (#13936)" (#14197)"

This reverts commit 808845b.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>

* Fix LocalCheckpointCallback safe import

Signed-off-by: Charlie Truong <chtruong@nvidia.com>

---------

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
AmirHussein96 pushed a commit to AmirHussein96/NeMo that referenced this pull request Aug 5, 2025
* Safely import nvidia-resiliency-ext package

The nvidia-resiliency-ext package is not compatible with Windows/MacOS
currently and cannot be installed directly on those platforms. Given the
number of nested imports in the nemo.collections.llm API, it will try and
automatically import the resliency package even if not used. Safely
importing the package allows all modules to be imported without blocking
on the resiliency package for incompatible platforms. This opens up
greater support on more platforms.

If the nvidia-resiliency-ext package is needed when these lines are called,
it will throw an import error only when directly called.

Signed-Off-By: Robert Clark <roclark@nvidia.com>

* Safely import modelopt algorithms

The default modelopt model transforms rely on the modelopt package being
installed which is not available on all platforms. This module gets
auto-imported when importing the nemo.collections.llm module and will
fail on platforms that don't support modelopt, such as Windows and MacOS,
even if the package isn't used.

Safely importing the package should allow the toolkit to be runnable on
both Windows and MacOS in a minimal state, which increases its
functionality, especially while paired with NeMo-Run.

Signed-Off-By: Robert Clark <roclark@nvidia.com>

* Apply isort and black reformatting

Signed-off-by: roclark <roclark@users.noreply.github.com>

---------

Signed-off-by: Robert Clark <roclark@nvidia.com>
Signed-off-by: roclark <roclark@users.noreply.github.com>
Signed-off-by: Amir Hussein <amhussein@nvidia.com>
AmirHussein96 pushed a commit to AmirHussein96/NeMo that referenced this pull request Aug 5, 2025
…VIDIA-NeMo#14197)

This reverts commit e04ee42.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Co-authored-by: Robert Clark <roclark@users.noreply.github.com>
Signed-off-by: Amir Hussein <amhussein@nvidia.com>
AmirHussein96 pushed a commit to AmirHussein96/NeMo that referenced this pull request Aug 5, 2025
…DIA-NeMo#14198)

* Revert "Revert "Safely import optional python packages (NVIDIA-NeMo#13936)" (NVIDIA-NeMo#14197)"

This reverts commit 808845b.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>

* Fix LocalCheckpointCallback safe import

Signed-off-by: Charlie Truong <chtruong@nvidia.com>

---------

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Signed-off-by: Amir Hussein <amhussein@nvidia.com>
AmirHussein96 pushed a commit to AmirHussein96/NeMo that referenced this pull request Aug 5, 2025
* Safely import nvidia-resiliency-ext package

The nvidia-resiliency-ext package is not compatible with Windows/MacOS
currently and cannot be installed directly on those platforms. Given the
number of nested imports in the nemo.collections.llm API, it will try and
automatically import the resliency package even if not used. Safely
importing the package allows all modules to be imported without blocking
on the resiliency package for incompatible platforms. This opens up
greater support on more platforms.

If the nvidia-resiliency-ext package is needed when these lines are called,
it will throw an import error only when directly called.

Signed-Off-By: Robert Clark <roclark@nvidia.com>

* Safely import modelopt algorithms

The default modelopt model transforms rely on the modelopt package being
installed which is not available on all platforms. This module gets
auto-imported when importing the nemo.collections.llm module and will
fail on platforms that don't support modelopt, such as Windows and MacOS,
even if the package isn't used.

Safely importing the package should allow the toolkit to be runnable on
both Windows and MacOS in a minimal state, which increases its
functionality, especially while paired with NeMo-Run.

Signed-Off-By: Robert Clark <roclark@nvidia.com>

* Apply isort and black reformatting

Signed-off-by: roclark <roclark@users.noreply.github.com>

---------

Signed-off-by: Robert Clark <roclark@nvidia.com>
Signed-off-by: roclark <roclark@users.noreply.github.com>
Signed-off-by: Amir Hussein <amhussein@nvidia.com>
AmirHussein96 pushed a commit to AmirHussein96/NeMo that referenced this pull request Aug 5, 2025
…VIDIA-NeMo#14197)

This reverts commit e04ee42.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Co-authored-by: Robert Clark <roclark@users.noreply.github.com>
Signed-off-by: Amir Hussein <amhussein@nvidia.com>
AmirHussein96 pushed a commit to AmirHussein96/NeMo that referenced this pull request Aug 5, 2025
…DIA-NeMo#14198)

* Revert "Revert "Safely import optional python packages (NVIDIA-NeMo#13936)" (NVIDIA-NeMo#14197)"

This reverts commit 808845b.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>

* Fix LocalCheckpointCallback safe import

Signed-off-by: Charlie Truong <chtruong@nvidia.com>

---------

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Signed-off-by: Amir Hussein <amhussein@nvidia.com>
nasretdinovr pushed a commit to nasretdinovr/NeMo that referenced this pull request Aug 8, 2025
* Safely import nvidia-resiliency-ext package

The nvidia-resiliency-ext package is not compatible with Windows/MacOS
currently and cannot be installed directly on those platforms. Given the
number of nested imports in the nemo.collections.llm API, it will try and
automatically import the resliency package even if not used. Safely
importing the package allows all modules to be imported without blocking
on the resiliency package for incompatible platforms. This opens up
greater support on more platforms.

If the nvidia-resiliency-ext package is needed when these lines are called,
it will throw an import error only when directly called.

Signed-Off-By: Robert Clark <roclark@nvidia.com>

* Safely import modelopt algorithms

The default modelopt model transforms rely on the modelopt package being
installed which is not available on all platforms. This module gets
auto-imported when importing the nemo.collections.llm module and will
fail on platforms that don't support modelopt, such as Windows and MacOS,
even if the package isn't used.

Safely importing the package should allow the toolkit to be runnable on
both Windows and MacOS in a minimal state, which increases its
functionality, especially while paired with NeMo-Run.

Signed-Off-By: Robert Clark <roclark@nvidia.com>

* Apply isort and black reformatting

Signed-off-by: roclark <roclark@users.noreply.github.com>

---------

Signed-off-by: Robert Clark <roclark@nvidia.com>
Signed-off-by: roclark <roclark@users.noreply.github.com>
nasretdinovr pushed a commit to nasretdinovr/NeMo that referenced this pull request Aug 8, 2025
…VIDIA-NeMo#14197)

This reverts commit e04ee42.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Co-authored-by: Robert Clark <roclark@users.noreply.github.com>
nasretdinovr pushed a commit to nasretdinovr/NeMo that referenced this pull request Aug 8, 2025
…DIA-NeMo#14198)

* Revert "Revert "Safely import optional python packages (NVIDIA-NeMo#13936)" (NVIDIA-NeMo#14197)"

This reverts commit 808845b.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>

* Fix LocalCheckpointCallback safe import

Signed-off-by: Charlie Truong <chtruong@nvidia.com>

---------

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
guyueh1 pushed a commit to guyueh1/NeMo that referenced this pull request Aug 25, 2025
* Safely import nvidia-resiliency-ext package

The nvidia-resiliency-ext package is not compatible with Windows/MacOS
currently and cannot be installed directly on those platforms. Given the
number of nested imports in the nemo.collections.llm API, it will try and
automatically import the resliency package even if not used. Safely
importing the package allows all modules to be imported without blocking
on the resiliency package for incompatible platforms. This opens up
greater support on more platforms.

If the nvidia-resiliency-ext package is needed when these lines are called,
it will throw an import error only when directly called.

Signed-Off-By: Robert Clark <roclark@nvidia.com>

* Safely import modelopt algorithms

The default modelopt model transforms rely on the modelopt package being
installed which is not available on all platforms. This module gets
auto-imported when importing the nemo.collections.llm module and will
fail on platforms that don't support modelopt, such as Windows and MacOS,
even if the package isn't used.

Safely importing the package should allow the toolkit to be runnable on
both Windows and MacOS in a minimal state, which increases its
functionality, especially while paired with NeMo-Run.

Signed-Off-By: Robert Clark <roclark@nvidia.com>

* Apply isort and black reformatting

Signed-off-by: roclark <roclark@users.noreply.github.com>

---------

Signed-off-by: Robert Clark <roclark@nvidia.com>
Signed-off-by: roclark <roclark@users.noreply.github.com>
Signed-off-by: Guyue Huang <guyueh@nvidia.com>
guyueh1 pushed a commit to guyueh1/NeMo that referenced this pull request Aug 25, 2025
…VIDIA-NeMo#14197)

This reverts commit e04ee42.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Co-authored-by: Robert Clark <roclark@users.noreply.github.com>
Signed-off-by: Guyue Huang <guyueh@nvidia.com>
guyueh1 pushed a commit to guyueh1/NeMo that referenced this pull request Aug 25, 2025
…DIA-NeMo#14198)

* Revert "Revert "Safely import optional python packages (NVIDIA-NeMo#13936)" (NVIDIA-NeMo#14197)"

This reverts commit 808845b.

Signed-off-by: Charlie Truong <chtruong@nvidia.com>

* Fix LocalCheckpointCallback safe import

Signed-off-by: Charlie Truong <chtruong@nvidia.com>

---------

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Signed-off-by: Guyue Huang <guyueh@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants