From bf2b258e5912cdbf77182e30cbbf68d6677c1189 Mon Sep 17 00:00:00 2001 From: hxf12345677 Date: Thu, 14 Apr 2022 17:19:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- torch_npu/csrc/aten/ops/LogSumExpKernelNpu.cpp | 2 +- .../csrc/aten/ops/QuantizePerChannelKernelNpu.cpp | 5 +++-- .../csrc/aten/ops/QuantizePerTensorKernelNpu.cpp | 15 +++++++++------ torch_npu/csrc/aten/ops/RenormKernelNpu.cpp | 9 ++++----- .../csrc/aten/ops/RepeatInterLeaveKernelNpu.cpp | 4 +--- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/torch_npu/csrc/aten/ops/LogSumExpKernelNpu.cpp b/torch_npu/csrc/aten/ops/LogSumExpKernelNpu.cpp index 6f9eaa480c..a14ddfbb4a 100644 --- a/torch_npu/csrc/aten/ops/LogSumExpKernelNpu.cpp +++ b/torch_npu/csrc/aten/ops/LogSumExpKernelNpu.cpp @@ -45,7 +45,7 @@ at::Tensor& NPUNativeFunctions::logsumexp_out(const at::Tensor& self, at::IntArr at::Tensor NPUNativeFunctions::logsumexp(const at::Tensor& self, at::IntArrayRef dims, bool keepdim) { auto outputSize = logsumexp_npu_output_size(self, dims, keepdim); - at::Tensor result = OpPreparation::ApplyTensorWithSizes(outputSize, self.options()); + at::Tensor result = OpPreparation::ApplyTensor(self, outputSize); return logsumexp_out_nocheck(self, dims, keepdim, result); } diff --git a/torch_npu/csrc/aten/ops/QuantizePerChannelKernelNpu.cpp b/torch_npu/csrc/aten/ops/QuantizePerChannelKernelNpu.cpp index e7248a57b5..2ce7443def 100644 --- a/torch_npu/csrc/aten/ops/QuantizePerChannelKernelNpu.cpp +++ b/torch_npu/csrc/aten/ops/QuantizePerChannelKernelNpu.cpp @@ -83,9 +83,10 @@ at::Tensor NPUNativeFunctions::quantize_per_channel( } else if (dtype == at::ScalarType::QInt32) { outputDtype = at::kInt; } - at::Tensor result = OpPreparation::ApplyTensorWithSizes( + at::Tensor result = OpPreparation::ApplyTensorWithFormat( outputSize, - self.options().dtype(outputDtype)); + self.options().dtype(outputDtype), + CalcuOpUtil::get_tensor_npu_format(self)); quantize_per_channel_out_nocheck(result, self, scales, zero_points, axis, dtype); return result; } diff --git a/torch_npu/csrc/aten/ops/QuantizePerTensorKernelNpu.cpp b/torch_npu/csrc/aten/ops/QuantizePerTensorKernelNpu.cpp index ce83ad715f..c2afae426b 100644 --- a/torch_npu/csrc/aten/ops/QuantizePerTensorKernelNpu.cpp +++ b/torch_npu/csrc/aten/ops/QuantizePerTensorKernelNpu.cpp @@ -59,17 +59,20 @@ at::Tensor NPUNativeFunctions::quantize_per_tensor( } else if (dtype == at::ScalarType::QInt32) { outputDtype = at::kInt; } - at::Tensor scaleTensor = OpPreparation::ApplyTensorWithSizes( + at::Tensor scaleTensor = OpPreparation::ApplyTensorWithFormat( {1}, - self.options().dtype(at::kFloat)); + self.options().dtype(at::kFloat), + CalcuOpUtil::get_tensor_npu_format(self)); scaleTensor[0] = scaleFloat; - at::Tensor zpTensor = OpPreparation::ApplyTensorWithSizes( + at::Tensor zpTensor = OpPreparation::ApplyTensorWithFormat( {1}, - self.options().dtype(at::kInt)); + self.options().dtype(at::kInt), + CalcuOpUtil::get_tensor_npu_format(self)); zpTensor[0] = zero_point; - at::Tensor result = OpPreparation::ApplyTensorWithSizes( + at::Tensor result = OpPreparation::ApplyTensorWithFormat( outputSize, - self.options().dtype(outputDtype)); + self.options().dtype(outputDtype), + CalcuOpUtil::get_tensor_npu_format(self)); quantize_per_tensor_out_nocheck(result, self, scaleTensor, zpTensor, dtype); return result; } diff --git a/torch_npu/csrc/aten/ops/RenormKernelNpu.cpp b/torch_npu/csrc/aten/ops/RenormKernelNpu.cpp index 96572651f5..3ec5d26a4c 100644 --- a/torch_npu/csrc/aten/ops/RenormKernelNpu.cpp +++ b/torch_npu/csrc/aten/ops/RenormKernelNpu.cpp @@ -68,9 +68,10 @@ at::Tensor& renorm_out_nocheck( } dim = CalcuOpUtil::make_wrap_dim(dim, self.dim()); auto outputSize = renorm_npu_output_size(self, dim); - at::Tensor result_bak = OpPreparation::ApplyTensorWithSizes( + at::Tensor result_bak = OpPreparation::ApplyTensorWithFormat( outputSize, - self.options().dtype(at::kFloat)); + self.options().dtype(at::kFloat), + CalcuOpUtil::get_tensor_npu_format(self)); if(ori_type == c10::ScalarType::Half) { at::Tensor self_no_name = self.rename(c10::nullopt); at::Tensor result_no_name = result.rename(c10::nullopt); @@ -131,9 +132,7 @@ at::Tensor& NPUNativeFunctions::renorm_out( at::Tensor NPUNativeFunctions::renorm(const at::Tensor& self, at::Scalar p, int64_t dim, at::Scalar maxnorm) { // calculate the output size auto outputSize = input_same_output_size(self); - at::Tensor result = OpPreparation::ApplyTensorWithSizes( - outputSize, - self.options()); + at::Tensor result = OpPreparation::ApplyTensor(self); return renorm_out_nocheck(result, self, p, dim, maxnorm); } diff --git a/torch_npu/csrc/aten/ops/RepeatInterLeaveKernelNpu.cpp b/torch_npu/csrc/aten/ops/RepeatInterLeaveKernelNpu.cpp index db0f0d80f9..acb1e1494e 100644 --- a/torch_npu/csrc/aten/ops/RepeatInterLeaveKernelNpu.cpp +++ b/torch_npu/csrc/aten/ops/RepeatInterLeaveKernelNpu.cpp @@ -48,9 +48,7 @@ at::Tensor NPUNativeFunctions::repeat_interleave( } auto outputSize = repeat_interleave_npu_output_size(selfTensor, repeats, realDim); - at::Tensor result = OpPreparation::ApplyTensorWithSizes( - outputSize, - selfTensor.options()); + at::Tensor result = OpPreparation::ApplyTensor(selfTensor, outputSize); repeat_interleave_out_npu(result, selfTensor, repeats, realDim); return result; -- Gitee