-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement rotary_embedding for Ascend (#753)
* implement rotary_embedding for Ascend * create functions_ext folder and move rotary_embedding.cpp to it
- Loading branch information
Showing
6 changed files
with
33 additions
and
15 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -259,3 +259,6 @@ | |
|
||
- diopiScatterInpScalar: | ||
dtype: (uint8,int8)->int32 | ||
|
||
- diopiRotaryEmbedding: | ||
dtype: (float64)->float32 |
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
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
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 |
---|---|---|
|
@@ -211,3 +211,4 @@ ascend_npu: | |
- diopiNormalInp | ||
- diopiNorm | ||
- diopiMaxPool2dWithIndices | ||
- diopiRotaryEmbedding |
26 changes: 26 additions & 0 deletions
26
impl/ascend_npu/diopi_impl/functions_ext/rotary_embedding.cpp
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,26 @@ | ||
/** | ||
* @file | ||
* @author DeepLink | ||
* @copyright (c) 2023, DeepLink. | ||
*/ | ||
|
||
#include "../helper.hpp" | ||
#include "op_plugin/AclOpsInterface.h" | ||
|
||
namespace OP_IMPL_NS { | ||
|
||
DIOPI_API diopiError_t diopiRotaryEmbedding(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t x, diopiConstTensorHandle_t cos, | ||
diopiConstTensorHandle_t sin, const bool conj, const bool interleaved) { | ||
TORCH_CHECK(false == interleaved, "interleaved=true is currently not supported for Ascend"); | ||
BEGIN_CALL_ACL_OP(out, x, cos, sin); | ||
at::Tensor cosRepeated = acl_op::repeat(cosAt, {1, 1, 1, 2}); | ||
at::Tensor sinRepeated = acl_op::repeat(sinAt, {1, 1, 1, 2}); | ||
if (conj) { | ||
acl_op::neg_(sinRepeated); | ||
} | ||
at_npu::native::OpCommand cmd; | ||
cmd.Name("RotaryMul").Input(xAt).Input(cosRepeated).Input(sinRepeated).Output(outAt).Run(); | ||
END_CALL_ACL_OP(); | ||
} | ||
|
||
} // namespace OP_IMPL_NS |
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