Skip to content

Improve NEST GPU Utilization 4/N: 250x Faster Masking on GPU#15739

Open
MahmoudAshraf97 wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
MahmoudAshraf97:fast-masking
Open

Improve NEST GPU Utilization 4/N: 250x Faster Masking on GPU#15739
MahmoudAshraf97 wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
MahmoudAshraf97:fast-masking

Conversation

@MahmoudAshraf97
Copy link
Copy Markdown
Contributor

Important

The Update branch button must only be pressed in very rare occassions.
An outdated branch is never blocking the merge of a PR.
Please reach out to the automation team before pressing that button.

What does this PR do ?

SSL training requires feature masking which uses python for loops on gpu hot path, this causes poor utilization since the masking function execution time grows linearly with batch size
This PR vectorizes the masking functions and gains 250x speedup using block_size=48, masking_prob=0.01, and input_shape=[32,80,2000], 41ms down to 0.16ms, I did test higher batch sizes, but the utilization tanks for both implementations because the dataloader is the bottleneck at that stage, so I use grad accumulation for higher global batch sizes if needed

We get around 18% speedup E2E and 10-15% higher GPU utilization, I have verified that the masking distribution is the same in the overlapping path, and two training runs for 5k steps converged to the same loss

{1EE0C04C-C583-4032-8F76-355A10A3CBB7} {6ABDEC86-9B75-4FE1-A876-3E9CFF0A54E8} {C621F4E8-8E46-47B2-B0A8-5F74750A8E53}

Collection: [Note which collection this PR will affect]

Changelog

  • Add specific line by line info of high level changes in this PR.

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this 

GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and 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

If you haven't finished some of the above items you can still open "Draft" PR.

Who can review?

cc @stevehuang52 @pzelasko
Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.

Additional Information

Refactor forward methods

Signed-off-by: Mahmoud Ashraf <hassouna97.ma@gmail.com>
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented Jun 1, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@stevehuang52
Copy link
Copy Markdown
Collaborator

Thanks for the PR. We also have some optimization on masking and quantization in https://github.com/NVIDIA-NeMo/NeMo/tree/heh/ssl-v2 and the draft PR #15589. Need to compare the two before deciding which one to merge.

@MahmoudAshraf97
Copy link
Copy Markdown
Contributor Author

Thanks for the PR. We also have some optimization on masking and quantization in https://github.com/NVIDIA-NeMo/NeMo/tree/heh/ssl-v2 and the draft PR #15589. Need to compare the two before deciding which one to merge.

I looked at the draft PR, I noticed that it still uses the old implementation core, where it basically uses python for loops so it will have the same issues, given that it does change the masking logic, we can use my implementation as a starting point and implement the new logic on top of the vectorized implementation

Copy link
Copy Markdown
Collaborator

@stevehuang52 stevehuang52 left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for the improvement~!

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond and removed waiting-on-customer Waiting on the original author to respond labels Jun 1, 2026
@stevehuang52
Copy link
Copy Markdown
Collaborator

/ok to test df56f3d

@MahmoudAshraf97
Copy link
Copy Markdown
Contributor Author

The two failing tests are not related to the code, please retry again or skip if unnecessary

@stevehuang52
Copy link
Copy Markdown
Collaborator

/ok to test ac242b3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ASR community-request waiting-on-maintainers Waiting on maintainers to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants