NeMo icon indicating copy to clipboard operation
NeMo copied to clipboard

Incompatible with numpy>2.0

Open julius-richter opened this issue 10 months ago • 11 comments

The function _convert_samples_to_float32 in NeMo/nemo/collections/asr/parts/preprocessing/segment.py is not compatible with numpy>2.0

Consider changing to:

def _convert_samples_to_float32(samples):
      """Convert sample type to float32.
      Audio sample type is usually integer or float-point.
      Integers will be scaled to [-1, 1] in float32.
      """
      float32_samples = samples.astype('float32')
      if np.issubdtype(samples.dtype, np.integer):
          bits = np.iinfo(samples.dtype).bits
          float32_samples *= 1.0 / 2 ** (bits - 1)
      elif np.issubdtype(samples.dtype, np.floating):
          pass
      else:
          raise TypeError("Unsupported sample type: %s." % samples.dtype)
      return float32_samples

julius-richter avatar Feb 26 '25 12:02 julius-richter

Faced the same issue. Awaiting fix.

ceyxasm avatar Mar 03 '25 07:03 ceyxasm

There's already a PR (#11447) for supporting numpy>2 but there hasn't been any response from the ASR maintainers.

JanetVictorious avatar Mar 19 '25 21:03 JanetVictorious

@julius-richter, I am the author of the aforementioned PR from @JanetVictorious. However, I've been trying for weeks to get a review for it from the Nvidia folks with no luck. For what's worth, and if it helps - you can use my branch temporarily as it has the fixes baked in.

It'd be really great to merge this as I'd like to contribute more... However, given the lack of responses my motivation is not exactly high if its bound to receive the "silent" treatment.

(edit: the only reason that it's closed is that there was no activity for 7 days, but I got tired of posting and pinging people to keep it alive)

andylamp avatar Mar 19 '25 22:03 andylamp

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

github-actions[bot] avatar Apr 19 '25 02:04 github-actions[bot]

@nithinraok I have already created a PR (https://github.com/NVIDIA/NeMo/pull/11447) for this... therefore all @monica-sekoyan has to do is just provide a review...

andylamp avatar Apr 19 '25 02:04 andylamp

Hi @andylamp . Thank you for the help.

Unfortunately we found multiple dependencies like tensorrt-llm , thinc, lightning-thunder still requires numpy<2,>=1.23.0. @ko3n1g FYI

nithinraok avatar Apr 19 '25 15:04 nithinraok

@nithinraok thanks for the visibility and the interaction - it really was a long time since I received an official reply on this.

As a question, is that the entire list of packages that have a dependency with numpy<2? If so, can I help you in upgrading/replacing the said dependencies so we can finally resolve the compatibility issue?

andylamp avatar Apr 19 '25 17:04 andylamp

As far I noticed that should be it. @ko3n1g could you please confirm.

nithinraok avatar Apr 19 '25 17:04 nithinraok

Alright @nithinraok , that's cool. After looking a bit at the compatibility of recent versions of these packages with numpy>=2.0:

  • tensorrt-llm: I do not see any issues that show incompatibility with numpy>=2.0... but on requirements there is a hard pin for numpy versions < 2. Therefore, am not sure how this can easily be fixed without updating that library on Nvidia's side.
  • thinc: incompatibility seems to be resolved in recent versions as of here.
  • lightning-thunder: seems to be compatible in recent versions (see here).

The only blocker seems to be the Nvidia tensorrt-llm library.

However, if you take a look at the PR (#11447) it addresses the numpy incompatibility by using a backwards compatible method -- i.e. it works with both 1.x and 2.x numpy versions. Therefore, I do not see a reason why this could not be merged... Do you think that'll be possible? I am asking since that fix will help those who use bits of NeMo that don't require the above libraries but want to use numpy>=2 (e.g. ASR).

andylamp avatar Apr 21 '25 02:04 andylamp

Thanks @andylamp for your help with this!

We're working on upgrading all NeMo collections to NumPy 2.0 via this draft PR: https://github.com/NVIDIA/NeMo/pull/12868. This approach is safer than updating each collection individually, like ASR.

That said, your PR updating the ASR signatures should work for those who want to use NumPy 2.0 with ASR specifically.

I've opened an issue to track the TRT-LLM update for NumPy >2.0. In the meantime, I’ve approved your PR — let’s wait for CI to pass before merging.

Thanks again!

nithinraok avatar Apr 21 '25 13:04 nithinraok

@nithinraok thanks a lot! Yeah, this is a quick win that can help those that do not use these dependencies. It would be great to eventually iron out any kinks and get numpy>=2.0 compatible with the entire NeMo suite.

andylamp avatar Apr 21 '25 20:04 andylamp

Hey. Thanks for the thread above. What is the current status on this? numpy >= 2 is a common dependency.

ArthurBook avatar Jun 03 '25 16:06 ArthurBook

General requirements is updated on main now. So next pip installable will have numpy >2

@ko3n1g I see https://github.com/NVIDIA/NeMo/blob/f652c583c85a3b909725d010cb15a8a040403e92/requirements/requirements_nlp.txt#L14 need to be updated @thomasdhc FYI

nithinraok avatar Jun 03 '25 16:06 nithinraok

Amazing! Thanks @nithinraok @thomasdhc. Do you guys have a target date for the release? Some things at work that would benefit from having @latest

ArthurBook avatar Jun 04 '25 15:06 ArthurBook

If you are executing ASR pathways please pip install from source using: pip install -e ".[asr]" This will install all packages needed for the ASR pathway and excludes NLP requirements.

Numpy restrictions for NLP module is being tested separately.

thomasdhc avatar Jun 06 '25 15:06 thomasdhc

@ArthurBook

Amazing! Thanks @nithinraok @thomasdhc. Do you guys have a target date for the release? Some things at work that would benefit from having @latest

We'd target for our next major release which is roughly every two months.

chtruong814 avatar Jun 06 '25 19:06 chtruong814

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

github-actions[bot] avatar Jul 07 '25 02:07 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Jul 14 '25 02:07 github-actions[bot]