(self)
| 21 | class TestEvalMode(unittest.TestCase): |
| 22 | |
| 23 | def test_eval_mode(self): |
| 24 | t = torch.rand(1, 1, 4, 4) |
| 25 | p = torch.nn.Conv2d(1, 1, 3) |
| 26 | self.assertTrue(p.training) # True |
| 27 | with eval_mode(p): |
| 28 | self.assertFalse(p.training) # False |
| 29 | with self.assertRaises(RuntimeError): |
| 30 | p(t).sum().backward() |
| 31 | |
| 32 | |
| 33 | if __name__ == "__main__": |