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

[Ascend] fuj / fix rotary_embedding and getDefaultGenerator #1138

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ at::Tensor viewAs4D(const at::Tensor& input) {
for (int i = 0; i < dim; ++i) {
viewShape[i + n - dim] = inputShape[i];
}
return input.view(viewShape);
return impl::aten::viewStorage(input, viewShape);
}

DIOPI_API diopiError_t diopiRotaryEmbedding(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t x, diopiConstTensorHandle_t cos,
Expand Down
13 changes: 11 additions & 2 deletions impl/ascend_npu/torch_npu/csrc/DIOPIAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2928,9 +2928,16 @@ std::pair<uint64_t, uint64_t> NPUGeneratorImpl::philox_engine_inputs(uint64_t in
return ret;
}

thread_local static at::Generator gDiopiGenerator[16];

namespace detail {

const at::Generator& getDefaultNPUGenerator(c10::DeviceIndex device_index) { INTERFACE_NOT_IMPL; }
const at::Generator& getDefaultNPUGenerator(c10::DeviceIndex device_index) {
if (device_index == -1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里的-1用那个未初始化的变量来表示。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个后面再考虑,未初始化的变量在dipu里面

device_index = current_device();
}
return gDiopiGenerator[device_index];
}

} // namespace detail

Expand Down Expand Up @@ -3109,9 +3116,11 @@ inline const at::Tensor buildATen(diopiConstTensorHandle_t tensor) {
#endif

at::Generator buildATen(diopiGeneratorHandle_t generator) {
auto gen = at::make_generator<at_npu::NPUGeneratorImpl>(current_device());
int64_t currentDeviceIndex = current_device();
auto gen = at::make_generator<at_npu::NPUGeneratorImpl>(currentDeviceIndex);
auto impl = static_cast<at_npu::NPUGeneratorImpl*>(gen.unsafeGetGeneratorImpl());
impl->generator_ = generator;
at_npu::gDiopiGenerator[currentDeviceIndex] = gen;
return gen;
}

Expand Down
Loading