mmcv/tests/test_ops/test_fused_bias_leakyrelu.py
Rui Xu 933b052d95
[Feature] Add cuda ops: UpFirDn2d and fused_bias_leakyrelu (#900)
* add upfirdn2d op

* fix bug in pybind

* add fused bias leakyrelu

* fix bug in fused-bias-leakyrelu

* fix lint error

* fix bug in build cpu version

* fix bug in build cpu version

* fix lint

* fix comment from zww

Co-authored-by: zhangshilong <zhangshilong@sensetime.com>
2021-03-21 21:23:09 +08:00

34 lines
963 B
Python

import pytest
import torch
from torch.autograd import gradcheck, gradgradcheck
class TestFusedBiasLeakyReLU(object):
@classmethod
def setup_class(cls):
if not torch.cuda.is_available():
return
cls.input_tensor = torch.randn((2, 2, 2, 2), requires_grad=True).cuda()
cls.bias = torch.zeros(2, requires_grad=True).cuda()
@pytest.mark.skipif(not torch.cuda.is_available(), reason='requires cuda')
def test_gradient(self):
from mmcv.ops import FusedBiasLeakyReLU
gradcheck(
FusedBiasLeakyReLU(2).cuda(),
self.input_tensor,
eps=1e-4,
atol=1e-3)
@pytest.mark.skipif(not torch.cuda.is_available(), reason='requires cuda')
def test_gradgradient(self):
from mmcv.ops import FusedBiasLeakyReLU
gradgradcheck(
FusedBiasLeakyReLU(2).cuda(),
self.input_tensor,
eps=1e-4,
atol=1e-3)