(self)
| 223 | self.assertAlmostEqual(output2, output3, places=5) |
| 224 | |
| 225 | def test_skip_layer_hook(self): |
| 226 | registry = HookRegistry.check_if_exists_or_initialize(self.model) |
| 227 | registry.register_hook(SkipLayerHook(skip_layer=True), "skip_layer_hook") |
| 228 | |
| 229 | input = torch.zeros(1, 4, device=torch_device) |
| 230 | output = self.model(input).mean().detach().cpu().item() |
| 231 | self.assertEqual(output, 0.0) |
| 232 | |
| 233 | registry.remove_hook("skip_layer_hook") |
| 234 | registry.register_hook(SkipLayerHook(skip_layer=False), "skip_layer_hook") |
| 235 | output = self.model(input).mean().detach().cpu().item() |
| 236 | self.assertNotEqual(output, 0.0) |
| 237 | |
| 238 | def test_skip_layer_internal_block(self): |
| 239 | registry = HookRegistry.check_if_exists_or_initialize(self.model.linear_1) |
nothing calls this directly
no test coverage detected