Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions src/lightning/pytorch/core/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,18 +694,17 @@ def all_gather(
return apply_to_collection(data, Tensor, all_gather, group=group, sync_grads=sync_grads)

@override
def forward(self, *args: Any, **kwargs: Any) -> Any:
def forward(self, *inputs) -> Any:
r"""Same as :meth:`torch.nn.Module.forward`.

Args:
*args: Whatever you decide to pass into the forward method.
**kwargs: Keyword arguments are also possible.

Return:
Your model's output

"""
return super().forward(*args, **kwargs)
return super().forward(*inputs)

def training_step(self, *args: Any, **kwargs: Any) -> STEP_OUTPUT:
r"""Here you compute and return the training loss and some additional metrics for e.g. the progress bar or
Expand Down
8 changes: 8 additions & 0 deletions tests/tests_pytorch/models/test_torchscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
from tests_pytorch.helpers.runif import RunIf


def test_torchscript_vanilla():
"""Test that LightningModule itself can be converted."""
model = LightningModule()

script = model.to_torchscript()
assert isinstance(script, torch.jit.ScriptModule)


@pytest.mark.skipif(_IS_WINDOWS and _TORCH_GREATER_EQUAL_2_4, reason="not close on Windows + PyTorch 2.4")
@pytest.mark.parametrize("modelclass", [BoringModel, ParityModuleRNN, BasicGAN])
def test_torchscript_input_output(modelclass):
Expand Down
Loading