Skip to content

Commit 5e93abe

Browse files
jbschlosserpytorchmergebot
authored andcommitted
Address docs for clip_grad functions (pytorch#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: pytorch#155125 Approved by: https://github.com/albanD, https://github.com/mikaylagawarecki, https://github.com/janeyx99
1 parent dd41a39 commit 5e93abe

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

docs/source/conf.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,10 +1297,6 @@
12971297
"scatter_kwargs",
12981298
# torch.nn.parameter
12991299
"is_lazy",
1300-
# torch.nn.utils.clip_grad
1301-
"clip_grad_norm",
1302-
"clip_grad_norm_",
1303-
"clip_grad_value_",
13041300
# torch.nn.utils.convert_parameters
13051301
"parameters_to_vector",
13061302
"vector_to_parameters",

torch/nn/utils/clip_grad.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616
)
1717

1818

19-
__all__ = [
20-
"clip_grad_norm_",
21-
"clip_grad_norm",
22-
"clip_grad_value_",
23-
]
19+
__all__: list[str] = []
2420

2521

2622
_tensor_or_tensors = Union[
@@ -292,3 +288,8 @@ def clip_grad_value_(
292288
else:
293289
for grad in grads:
294290
cast(Tensor, grad).clamp_(min=-clip_value, max=clip_value)
291+
292+
293+
clip_grad_norm.__module__ = "torch.nn.utils"
294+
clip_grad_norm_.__module__ = "torch.nn.utils"
295+
clip_grad_value_.__module__ = "torch.nn.utils"

0 commit comments

Comments
 (0)