From e5d9d8e106397807c1c226ba46d76ee1789180c4 Mon Sep 17 00:00:00 2001 From: sherie <963372609@qq.com> Date: Fri, 20 Oct 2023 16:52:14 +0800 Subject: [PATCH] Fix torch 1.8 adpater npu bug (#2970) --- mmcv/ops/csrc/common/pytorch_npu_helper.hpp | 1 - mmcv/ops/csrc/pytorch/npu/focal_loss_npu.cpp | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/mmcv/ops/csrc/common/pytorch_npu_helper.hpp b/mmcv/ops/csrc/common/pytorch_npu_helper.hpp index fe0cdce545..50e11d7456 100644 --- a/mmcv/ops/csrc/common/pytorch_npu_helper.hpp +++ b/mmcv/ops/csrc/common/pytorch_npu_helper.hpp @@ -18,7 +18,6 @@ #ifndef PYTORCH_NPU_HELPER_HPP_ #define PYTORCH_NPU_HELPER_HPP_ -#include #include #include diff --git a/mmcv/ops/csrc/pytorch/npu/focal_loss_npu.cpp b/mmcv/ops/csrc/pytorch/npu/focal_loss_npu.cpp index b7c995a223..5d79a11f34 100644 --- a/mmcv/ops/csrc/pytorch/npu/focal_loss_npu.cpp +++ b/mmcv/ops/csrc/pytorch/npu/focal_loss_npu.cpp @@ -99,8 +99,20 @@ void softmax_focal_loss_forward_npu(Tensor input, Tensor target, Tensor weight, c10::SmallVector offsets = {0, 0}; c10::SmallVector sizes = {n_batch, 1}; at::IntArrayRef offset = at::IntArrayRef(offsets); - at::IntArrayRef size = at::IntArrayRef(sizes); - at_npu::native::custom_ops::npu_slice_out(op_output, offset, size, output); + at::IntArrayRef size_array = at::IntArrayRef(sizes); + c10::SmallVector output_size; + for (uint64_t i = 0; i < size_array.size(); i++) { + output_size.emplace_back(size_array[i]); + } + at::Tensor result = at::empty(output_size, op_output.options()); + c10::SmallVector offsetVec = array_to_small_vector(offset); + c10::SmallVector sizeVec = array_to_small_vector(size_array); + cmd.Name("Slice") + .Input(op_output) + .Input(offsetVec) + .Input(sizeVec) + .Output(output) + .Run(); } void softmax_focal_loss_forward_impl(Tensor input, Tensor target, Tensor weight,