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

[PyTorch] Reduce the CPU overheads of GroupedLinear #1072

Merged
merged 10 commits into from
Aug 9, 2024

Conversation

yaox12
Copy link
Collaborator

@yaox12 yaox12 commented Aug 2, 2024

Description

Try to reduce the CPU overheads of GroupedLinear by:

  1. Using fused_multi_cast_transpose instead of iterating cast_transpose_fused in a for-loop.
    a. Changed the API of fused_multi_cast_transpose to avoid index-select ops in PyTorch.
    b. Allocate output tensors in CPP.
  2. Use at::cuda::current_device(), which has a cache, to get current device id to avoid cudaGetDriverEntryPoint calls.
  3. Reduce torch.Tensor() calls.
  4. TODO.

Fix:

  1. Zero grad_bias in fused_cast_transpose_bgrad when input is empty.
  2. Typos.

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refractor

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@yaox12 yaox12 force-pushed the xiny/fused_multi_cast_transpose branch 2 times, most recently from c163caa to c0cf5a9 Compare August 5, 2024 03:51
yaox12 and others added 7 commits August 8, 2024 02:27
Signed-off-by: Xin Yao <xiny@nvidia.com>
Signed-off-by: Xin Yao <xiny@nvidia.com>
Signed-off-by: Xin Yao <xiny@nvidia.com>
Signed-off-by: Xin Yao <xiny@nvidia.com>
Signed-off-by: Xin Yao <xiny@nvidia.com>
Signed-off-by: Xin Yao <xiny@nvidia.com>
@yaox12 yaox12 force-pushed the xiny/fused_multi_cast_transpose branch from 354f634 to 3a9d2f3 Compare August 8, 2024 09:27
@yaox12 yaox12 marked this pull request as ready for review August 8, 2024 09:29
@yaox12
Copy link
Collaborator Author

yaox12 commented Aug 8, 2024

@timmoon10 Can you help review this PR?

@phu0ngng phu0ngng requested a review from timmoon10 August 8, 2024 15:31
@timmoon10
Copy link
Collaborator

/te-ci pytorch

Copy link
Collaborator

@timmoon10 timmoon10 left a comment

Choose a reason for hiding this comment

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

Overall LGTM. What kinds of speedups are you seeing? It would be helpful to see what optimizations had the biggest impact so we can apply it to other PyTorch modules.

tests/pytorch/test_numerics.py Outdated Show resolved Hide resolved
@yaox12
Copy link
Collaborator Author

yaox12 commented Aug 9, 2024

Overall LGTM. What kinds of speedups are you seeing? It would be helpful to see what optimizations had the biggest impact so we can apply it to other PyTorch modules.

Here're some numbers for num_gemms=6 and small gemm sizes.

fwd (us) fwd speedup
baseline 750.075 /
+fused_multi_cast_transpose 662.756 1.13
+cpp alloc 615.818 1.22
+Reduce cudaGetDriverEntryPoint and torch.Tensor() 604.722 1.24

Signed-off-by: Xin Yao <xiny@nvidia.com>
@timmoon10
Copy link
Collaborator

/te-ci pytorch

@timmoon10 timmoon10 merged commit 8b32605 into NVIDIA:main Aug 9, 2024
13 of 15 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.

2 participants