[Dynamo] Make profiler function will be ignored warn only once (#117585)

Fix #111632

#111622 accidentally reverted #111921, we should bring it back.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/117585
Approved by: https://github.com/williamwen42, https://github.com/mlazos, https://github.com/msaroufim
This commit is contained in:
Yanbo Liang 2024-01-17 04:05:45 +00:00 committed by PyTorch MergeBot
parent 2c5488d719
commit 735715e6d3

View File

@ -18,6 +18,7 @@ import torch._refs
import torch.fx
import torch.nn
import torch.onnx.operators
from torch._logging import warning_once
from .. import config, polyfill, variables
from ..device_interface import get_registered_device_interfaces
@ -187,7 +188,7 @@ class TorchCtxManagerClassVariable(BaseTorchVariable):
torch.autograd.profiler.profile,
torch.autograd.profiler.record_function,
):
log.warning("Profiler function %s will be ignored", self.value)
warning_once(log, "Profiler function %s will be ignored", self.value)
return NullContextVariable()
elif self.value is torch._C.DisableTorchFunctionSubclass:
assert not (args or kwargs)