Skip to content

Commit 8c6698e

Browse files
authored
Delete stub forward() method in Module
The current stub breaks TorchScript/`to_torchscript` with: ``` otSupportedError: Compiled functions can't take variable number of arguments or use keyword-only arguments with defaults: File "/opt/conda/envs/image-gen/lib/python3.11/site-packages/pytorch_lightning/core/module.py", line 657 def forward(self, *args: Any, **kwargs: Any) -> Any: ~~~~~~~ <--- HERE r"""Same as :meth:`torch.nn.Module.forward`. ``` This becomes an issue when you use a module as container for other modules with bespoke methods and do not rely on the default forward call.
1 parent 28a8023 commit 8c6698e

File tree

1 file changed

+0
-14
lines changed

1 file changed

+0
-14
lines changed

src/lightning/pytorch/core/module.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -676,20 +676,6 @@ def all_gather(
676676
data = convert_to_tensors(data, device=self.device)
677677
return apply_to_collection(data, Tensor, all_gather, group=group, sync_grads=sync_grads)
678678

679-
@override
680-
def forward(self, *args: Any, **kwargs: Any) -> Any:
681-
r"""Same as :meth:`torch.nn.Module.forward`.
682-
683-
Args:
684-
*args: Whatever you decide to pass into the forward method.
685-
**kwargs: Keyword arguments are also possible.
686-
687-
Return:
688-
Your model's output
689-
690-
"""
691-
return super().forward(*args, **kwargs)
692-
693679
def training_step(self, *args: Any, **kwargs: Any) -> STEP_OUTPUT:
694680
r"""Here you compute and return the training loss and some additional metrics for e.g. the progress bar or
695681
logger.

0 commit comments

Comments
 (0)