(self, device, dtype, module_info, training)
| 213 | |
| 214 | @modules(module_db) |
| 215 | def test_pickle(self, device, dtype, module_info, training): |
| 216 | # Test that module can be pickled and unpickled. |
| 217 | module_cls = module_info.module_cls |
| 218 | module_inputs = module_info.module_inputs_func(module_info, device=device, dtype=dtype, |
| 219 | requires_grad=False, training=training) |
| 220 | for module_input in module_inputs: |
| 221 | if module_input.forward_input is None: |
| 222 | continue |
| 223 | |
| 224 | args, kwargs = module_input.constructor_input.args, module_input.constructor_input.kwargs |
| 225 | |
| 226 | with freeze_rng_state(): |
| 227 | # === Instantiate the module. === |
| 228 | args, kwargs = module_input.constructor_input.args, module_input.constructor_input.kwargs |
| 229 | m = module_cls(*args, **kwargs) |
| 230 | m.to(device).to(dtype) |
| 231 | m.train(training) |
| 232 | |
| 233 | # === Do forward pass. === |
| 234 | args, kwargs = module_input.forward_input.args, module_input.forward_input.kwargs |
| 235 | output = m(*args, **kwargs) |
| 236 | |
| 237 | # === Check unpickled module gives the same output. === |
| 238 | with tempfile.TemporaryFile() as f: |
| 239 | torch.save(m, f) |
| 240 | f.seek(0) |
| 241 | m_copy = torch.load(f) |
| 242 | output_from_copy = m_copy(*args, **kwargs) |
| 243 | self.assertEqual(output, output_from_copy) |
| 244 | |
| 245 | @skipMeta |
| 246 | @modules([module_info for module_info in module_db |
nothing calls this directly
no test coverage detected