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

[Operator] Fix embedding op backward with bf16 #309

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zhzhcookie
Copy link
Collaborator

@zhzhcookie zhzhcookie commented Nov 21, 2024

PR Category

Operator

Type of Change

Bug Fix

Description

Fix embedding op backward with bf16. Before atomic_add(bf16), we convert both ptr and data to fp32.

Issue

Progress

  • Change is properly reviewed (1 reviewer required, 2 recommended).
  • Change is responded to an issue.
  • Change is fully covered by a UT.

Performance

@@ -70,11 +70,15 @@ def embedding_backward_kernel(
if not HAS_PADDING_IDX:
grad_in += row_idx * N
embedding_grad = tl.load(grad_out + cols, mask, other=0.0)
if tl.constexpr(embedding_grad.dtype.is_bf16()):
embedding_grad = embedding_grad.to(tl.float32)
tl.atomic_add(grad_in + cols, embedding_grad, mask=mask)
Copy link
Contributor

@tongxin tongxin Nov 22, 2024

Choose a reason for hiding this comment

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

Atomically updating gradients from a massive number of ctas may be a problem. Could we reduce contention with local updates in a gsl style kernel?

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.

在跑通『LLaVA单卡+gems』过程总遇到的embedding反向BF16的bug
2 participants