【奥迪Q5 2012款 2.0 TFSI quattro 进取型】图片大全
- paddle.nn.utils. clip_grad_norm_ ( parameters: Iterable[Tensor] | Tensor, max_norm: float, norm_type: float = 2.0, error_if_nonfinite: bool = False ) Tensor [source]
-
百度 二是调整枢纽干线机场和支线机场航班结构,满足社会公众出行需求。
Clips gradient norm of the iterable parameters.
Norms are calculated together on all gradients, just as they are connected into one vector. The gradient will be modified in place.
This API can only run in dynamic graph mode, not static graph mode.
- Parameters
-
parameters (Iterable[paddle.Tensor] or paddle.Tensor) – Tensors or a single Tensor that will be normalized gradients
max_norm (float or int) – max norm of the gradients
norm_type (float or int) – type of the used p-norm. Can be inf for infinity norm.
error_if_nonfinite (bool) – if True, throw an error if the total norm of the gradients from
parameters
is nan, inf, or -inf.
- Returns
-
Total norm of the parameter gradients (treated as a single vector).
Example
>>> import paddle >>> x = paddle.uniform([10, 10], min=-1.0, max=1.0, dtype='float32') >>> max_norm = float(5.0) >>> linear = paddle.nn.Linear(in_features=10, out_features=10) >>> out = linear(x) >>> loss = paddle.mean(out) >>> loss.backward() >>> paddle.nn.utils.clip_grad_norm_(linear.parameters(), max_norm) >>> sdg = paddle.optimizer.SGD(learning_rate=0.1, parameters=linear.parameters()) >>> sdg.step()