我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用torch.nn.Hardshrink()。
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))