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

Delete stub forward() method in LightningModule #19423

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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 @@ -677,18 +677,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 @@ -26,6 +26,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.parametrize("modelclass", [BoringModel, ParityModuleRNN, BasicGAN])
def test_torchscript_input_output(modelclass):
"""Test that scripted LightningModule forward works."""
Expand Down
Loading