mlx.nn.utils.clip_grad_norm_sharded#
- clip_grad_norm_sharded(gradients: Any, max_norm: float, group: Group | None = None)#
Clip the global norm of gradients that are sharded across a group.
This is the sharded equivalent of
mlx.optimizers.clip_grad_norm(). Each member of the group holds only a shard of the gradients, so the global norm is computed by summing the local squared norms across the group before rescaling. It is useful for clipping the gradients of a module wrapped withmlx.nn.layers.distributed.fully_shard().- Parameters:
- Returns:
The possibly rescaled local shard of the gradients and the global gradient norm.
- Return type:
(Any, array)