Must run in a separate function to ensure deletion happens before mod unloads. When a module returns an object, the object deleter address is part of the loaded library. We need to keep the module loaded until the object is deleted.
()
| 243 | assert torch is not None |
| 244 | |
| 245 | def run_check() -> None: |
| 246 | """Must run in a separate function to ensure deletion happens before mod unloads. |
| 247 | |
| 248 | When a module returns an object, the object deleter address is part of the |
| 249 | loaded library. We need to keep the module loaded until the object is deleted. |
| 250 | """ |
| 251 | assert torch is not None |
| 252 | x_cpu = torch.asarray([1, 2, 3, 4, 5], dtype=torch.float32, device="cpu") |
| 253 | # test support for nested container passing |
| 254 | y_cpu = mod.return_add_one({"x": [x_cpu]}) |
| 255 | assert isinstance(y_cpu, torch.Tensor) |
| 256 | assert y_cpu.shape == (5,) |
| 257 | assert y_cpu.dtype == torch.float32 |
| 258 | torch.testing.assert_close(x_cpu + 1, y_cpu) |
| 259 | |
| 260 | run_check() |
| 261 |
no outgoing calls
no test coverage detected