Address docs for clip_grad functions (#155125)

This PR takes the opinionated stance that `torch.nn.utils.<func>` should be the preferred API over `torch.nn.utils.clip_grad.<func>`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/155125
Approved by: https://github.com/albanD, https://github.com/mikaylagawarecki, https://github.com/janeyx99
This commit is contained in:
Joel Schlosser
2025-06-04 11:50:13 -04:00
committed by PyTorch MergeBot
parent dd41a3907c
commit 5e93abe3c0
2 changed files with 6 additions and 9 deletions

View File

@ -1297,10 +1297,6 @@ coverage_ignore_functions = [
"scatter_kwargs",
# torch.nn.parameter
"is_lazy",
# torch.nn.utils.clip_grad
"clip_grad_norm",
"clip_grad_norm_",
"clip_grad_value_",
# torch.nn.utils.convert_parameters
"parameters_to_vector",
"vector_to_parameters",

View File

@ -16,11 +16,7 @@ from torch.utils._foreach_utils import (
)
__all__ = [
"clip_grad_norm_",
"clip_grad_norm",
"clip_grad_value_",
]
__all__: list[str] = []
_tensor_or_tensors = Union[
@ -292,3 +288,8 @@ def clip_grad_value_(
else:
for grad in grads:
cast(Tensor, grad).clamp_(min=-clip_value, max=clip_value)
clip_grad_norm.__module__ = "torch.nn.utils"
clip_grad_norm_.__module__ = "torch.nn.utils"
clip_grad_value_.__module__ = "torch.nn.utils"