-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50a29d2
commit 29b9d8e
Showing
3 changed files
with
31 additions
and
28 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import torch | ||
from typing import Optional, Union | ||
import deeplink_ext.cpp_extensions as ext | ||
|
||
|
||
def apply_rotary_for_ascend_speed( | ||
x: torch.Tensor, | ||
cos: torch.Tensor, | ||
sin: torch.Tensor, | ||
seqlen_offsets: Union[int, torch.Tensor] = 0, | ||
cu_seqlens: Optional[torch.Tensor] = None, | ||
max_seqlen: Optional[int] = None, | ||
interleaved=False, | ||
inplace=False, | ||
conjugate=False, | ||
) -> torch.Tensor: | ||
output = torch.empty_like(x) | ||
ext.apply_rotary(output, x, cos, sin, conjugate, interleaved) | ||
return output | ||
|
||
|
||
class RotaryEmbedding_AscendSpeed(torch.autograd.Function): | ||
@staticmethod | ||
def forward(ctx, t, cos, sin): | ||
ctx.save_for_backward(cos, sin) | ||
return apply_rotary_for_ascend_speed(t, cos, sin) | ||
|
||
@staticmethod | ||
def backward(ctx, t): | ||
cos, sin = ctx.saved_tensors | ||
return apply_rotary_for_ascend_speed(t, cos, sin, conjugate=True), None, None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters