Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3498 Correct kwargs arg for convert_to_torchscript #3499

Merged
merged 7 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion monai/networks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,13 @@ def convert_to_torchscript(
device: target device to verify the model, if None, use CUDA if available.
rtol: the relative tolerance when comparing the outputs of PyTorch model and TorchScript model.
atol: the absolute tolerance when comparing the outputs of PyTorch model and TorchScript model.
kwargs: other arguments for `torch.jit.script()` to convert model except `obj`, for more details:
https://pytorch.org/docs/master/generated/torch.jit.script.html.

"""
model.eval()
with torch.no_grad():
script_module = torch.jit.script(model)
script_module = torch.jit.script(model, **kwargs)
if filename_or_obj is not None:
if not pytorch_after(1, 7):
torch.jit.save(m=script_module, f=filename_or_obj)
Expand Down
1 change: 1 addition & 0 deletions tests/test_convert_to_torchscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_value(self):
device="cuda" if torch.cuda.is_available() else "cpu",
rtol=1e-3,
atol=1e-4,
optimize=None,
)
self.assertTrue(isinstance(torchscript_model, torch.nn.Module))

Expand Down