Skip to content

Commit b8bed65

Browse files
committed
fix: disable torch.compile tracing at the LightningModule.log boundary
Move the torch.compiler.disable from the generic is_param_in_hook_signature helper to LightningModule.log, and revert the helper to pure Python. Only self.log is reachable from a compiled training_step; its signature introspection (inspect.getfullargspec on a bound method) fails to trace on PyTorch 2.12/2.13. Disabling at the log boundary matches the existing idiom (toggle_optimizer, _ResultCollection.log) and keeps the introspection helper torch-free, since its other callers run outside the compiled graph.
1 parent 269d096 commit b8bed65

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/lightning/pytorch/core/module.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ def forward(self, x):
383383
else:
384384
print(*args, **kwargs)
385385

386+
@torch.compiler.disable
386387
def log(
387388
self,
388389
name: str,
@@ -408,6 +409,13 @@ def log(
408409
409410
The default behavior per hook is documented here: :ref:`extensions/logging:Automatic Logging`.
410411
412+
.. note::
413+
This method is decorated with :func:`torch.compiler.disable` so that it runs as regular Python when
414+
called from a :func:`torch.compile`-wrapped ``training_step``. Logging is bookkeeping that does not
415+
belong in the compiled graph, and tracing it fails on newer PyTorch versions (the signature
416+
introspection it performs is not supported by Dynamo). Disabling the compiler keeps behavior identical
417+
for eager users.
418+
411419
Args:
412420
name: key to log. Must be identical across all processes if using DDP or any other distributed strategy.
413421
value: value to log. Can be a ``float``, ``Tensor``, or a ``Metric``.

src/lightning/pytorch/utilities/signature_utils.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
import inspect
1515
from typing import Callable, Optional
1616

17-
import torch
1817

19-
20-
@torch.compiler.disable
2118
def is_param_in_hook_signature(
2219
hook_fx: Callable, param: str, explicit: bool = False, min_args: Optional[int] = None
2320
) -> bool:

0 commit comments

Comments
 (0)