Test the ability to save `net` as a Torchscript object, reload it, and apply inference. The value `inputs` is forward-passed through the original and loaded copy of the network and their results returned. The forward pass for both is done without gradient accumulation. The test wil
(net, *inputs, device=None, rtol=1e-4, atol=0.0)
| 785 | |
| 786 | |
| 787 | def test_script_save(net, *inputs, device=None, rtol=1e-4, atol=0.0): |
| 788 | """ |
| 789 | Test the ability to save `net` as a Torchscript object, reload it, and apply inference. The value `inputs` is |
| 790 | forward-passed through the original and loaded copy of the network and their results returned. |
| 791 | The forward pass for both is done without gradient accumulation. |
| 792 | |
| 793 | The test will be performed with CUDA if available, else CPU. |
| 794 | """ |
| 795 | # TODO: would be nice to use GPU if available, but it currently causes CI failures. |
| 796 | device = "cpu" |
| 797 | with tempfile.TemporaryDirectory() as tempdir: |
| 798 | convert_to_torchscript( |
| 799 | model=net, |
| 800 | filename_or_obj=os.path.join(tempdir, "model.ts"), |
| 801 | verify=True, |
| 802 | inputs=inputs, |
| 803 | device=device, |
| 804 | rtol=rtol, |
| 805 | atol=atol, |
| 806 | ) |
| 807 | |
| 808 | |
| 809 | def test_onnx_save(net, *inputs, device=None, rtol=1e-4, atol=0.0): |
no test coverage detected
searching dependent graphs…