Skip to content

Commit

Permalink
amend for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jayggh authored and GuoGuanghao committed Dec 8, 2022
1 parent 0869a60 commit 5477510
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
43 changes: 24 additions & 19 deletions mmcv/ops/csrc/pytorch/npu/fused_bias_leakyrelu_npu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,35 @@
using namespace NPU_NAME_SPACE;
using namespace std;

Tensor fused_bias_leakyrelu_op_impl(const Tensor& input, const Tensor& bias,
const Tensor& refer, int act,
int grad, float alpha, float scale);
Tensor fused_bias_leakyrelu_op_impl(const Tensor &input, const Tensor &bias,
const Tensor &refer, int act, int grad,
float alpha, float scale);

Tensor fused_bias_leakyrelu_npu(const Tensor& input, const Tensor& bias,
const Tensor& refer, int act,
int grad, float alpha, float scale){
Tensor fused_bias_leakyrelu_npu(const Tensor &input, const Tensor &bias,
const Tensor &refer, int act, int grad,
float alpha, float scale)
{
at::Tensor py = at::empty_like(input);
//forward
if (grad == 0){
// forward
if (grad == 0)
{
auto input_size = input.sizes();
int input_length = input_size.size();
c10::SmallVector<int64_t, SIZE> input_size_tmp;
input_size_tmp = array_to_small_vector(input_size);
if (input_length > 1){
for (int i = 0; i < input_length; i++){
if (i != 1){
input_size_tmp[i] = 1;
}
if (input_length > 1)
{
for (int i = 0; i < input_length; i++)
{
if (i != 1)
{
input_size_tmp[i] = 1;
}
}
}
at::Tensor bias_tmp = at::reshape(bias, input_size_tmp);
at::Tensor bias_ = at_npu::native::NPUNativeFunctions::npu_broadcast(bias_tmp, input.sizes());
at::Tensor bias_ = at_npu::native::NPUNativeFunctions::npu_broadcast(
bias_tmp, input.sizes());
OpCommand cmd;
cmd.Name("FusedBiasLeakyRelu")
.Input(input)
Expand All @@ -36,8 +42,9 @@ Tensor fused_bias_leakyrelu_npu(const Tensor& input, const Tensor& bias,
.Run();
}

//backward
if (grad == 1){
// backward
if (grad == 1)
{
OpCommand cmd;
cmd.Name("FusedBiasLeakyReluGrad")
.Input(input)
Expand All @@ -48,8 +55,6 @@ Tensor fused_bias_leakyrelu_npu(const Tensor& input, const Tensor& bias,
.Run();
}
return py;

}

REGISTER_NPU_IMPL(fused_bias_leakyrelu_op_impl,
fused_bias_leakyrelu_npu);
REGISTER_NPU_IMPL(fused_bias_leakyrelu_op_impl, fused_bias_leakyrelu_npu);
1 change: 1 addition & 0 deletions tests/test_ops/test_fused_bias_leakyrelu.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch

from mmcv.utils import IS_CUDA_AVAILABLE, IS_NPU_AVAILABLE

_USING_PARROTS = True
Expand Down

0 comments on commit 5477510

Please sign in to comment.