Python torch.nn 模块,Hardshrink() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用torch.nn.Hardshrink()

项目:pytorch    作者:pytorch    | 项目源码 | 文件源码
def add_test(test):
    test_name = test.get_name()
    cuda_test_name = test_name + '_cuda'
    if hasattr(TestNN, test_name):
        raise RuntimeError('Found two tests with the same name: ' + test_name)
    if hasattr(TestNN, cuda_test_name):
        raise RuntimeError('Found two tests with the same name: ' + cuda_test_name)
    setattr(TestNN, test_name, lambda self, test=test: test(self))
    # Hardshrink is not implemented in CUDA, so we must not test it.
    if test_name != "test_Hardshrink":
        setattr(TestNN, cuda_test_name, lambda self, test=test: test.test_cuda(self))