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

Parallel Cross Entropy using online softmax #1456

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sanandaraj5597
Copy link
Contributor

Description

This PR implements a parallel cross entropy function using the online technique to calculate softmax. This feature has multiple aspects:

  1. The vocab dimension can be sharded along the TP axis to perform this loss calculation in a distributed fashion.
  2. Online softmax helps us parallelize the softmax calculation giving us more efficiency.
  3. Calculating gradients in the forward itself, so backward step is a no-op.
  4. Storing the gradients in-place of the input tensor saving memory.
  5. OAI Triton implementation helps us integrate GPU kernel level semantics and torch level communication API's together.

[Thanks to Liger kernel implementation for providing the idea about online softmax and in-place gradient calculation.]

Selvaraj Anandaraj and others added 2 commits February 4, 2025 14:20
Signed-off-by: Selvaraj Anandaraj <selvaraja@cw-dfw-cs-001-login-01.cm.cluster>
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.

Can you add a test in tests/pytorch?

@timmoon10 timmoon10 self-requested a review February 4, 2025 22:38
@timmoon10 timmoon10 added the enhancement New feature or request label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants