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] Userbuffers support in operation-based API #1142

Merged
merged 31 commits into from
Nov 6, 2024

Conversation

timmoon10
Copy link
Collaborator

Description

This PR adds basic support in the linear operation for using Userbuffers to overlap tensor-parallel communication with GEMMs. This is implemented as fused operations:

model = te.ops.Sequential(
    te.ops.BasicLinear(...),
    te.ops.Bias(...),
    te.ops.ReduceScatter(...),
)  # Fused into UserbuffersForwardLinear

I've tried to avoid touching the core UB infrastructure in transformer_engine/pytorch/module/base.py, so I've kept the messy API and hackily worked around some bugs. This feature should be considered experimental and unstable.

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

Changes

  • Add fused operation for linear forward with Userbuffers
  • Add fused operation for linear backward with Userbuffers

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

Assumes FP8 RS, which is not a good assumption.

Signed-off-by: Tim Moon <[email protected]>
Bias pointers are not properly offset for different data chunks. Also removed logic for FP8 RS.

Signed-off-by: Tim Moon <[email protected]>
Test passes with row TP, fails with col TP.

Signed-off-by: Tim Moon <[email protected]>
Signed-off-by: Tim Moon <[email protected]>
@timmoon10
Copy link
Collaborator Author

/te-ci pytorch

@timmoon10
Copy link
Collaborator Author

/te-ci pytorch

Copy link
Collaborator

@denera denera left a comment

Choose a reason for hiding this comment

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

LGTM, at least on the Userbuffers code side.

@timmoon10
Copy link
Collaborator Author

/te-ci pytorch

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The previous UB GEMM+RS impl has a correctness bug. UB splits up the GEMM into multiple chunks so that it can do the GEMM to compute one output chunk at the same time it is doing an RS on another output chunk. However, each output chunk requires applying a different chunk of the bias. We previously used the same bias pointer for all chunks, while this PR computes the correct offsets in the bias pointer.

Comment on lines +685 to +690
data: Optional[torch.Tensor] = None,
scale: Optional[torch.Tensor] = None,
amax: Optional[torch.Tensor] = None,
scale_inv: Optional[torch.Tensor] = None,
with_transpose_cache: bool = False,
data_transpose: Optional[torch.Tensor] = None,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • The data kwarg allows us to easily initialize Float8Tensors that use the UB workspace buffer
  • The data_transpose kwarg is added for completeness

@timmoon10
Copy link
Collaborator Author

/te-ci pytorch

@timmoon10
Copy link
Collaborator Author

/te-ci L1

@timmoon10
Copy link
Collaborator Author

/te-ci pytorch jax paddle L1

@timmoon10
Copy link
Collaborator Author

/te-ci pytorch L1

@timmoon10 timmoon10 merged commit 095b27d into NVIDIA:main Nov 6, 2024
26 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