Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion torchrec/optim/clipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def step(self, closure: Any = None) -> None:
self._step_num += 1

@torch.no_grad()
def clip_grad_norm_(self) -> None:
def clip_grad_norm_(self) -> Optional[Union[float, torch.Tensor]]:
"""Clip the gradient norm of all parameters."""
max_norm = self._max_gradient
norm_type = float(self._norm_type)
Expand Down Expand Up @@ -224,6 +224,7 @@ def clip_grad_norm_(self) -> None:
clip_coef = cast(torch.Tensor, max_norm / (total_grad_norm + 1e-6))
clip_coef_clamped = torch.clamp(clip_coef, max=1.0)
torch._foreach_mul_(all_grads, clip_coef_clamped)
return total_grad_norm


def _batch_cal_norm(
Expand Down
Loading