We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b02c818 commit 1f8834aCopy full SHA for 1f8834a
paddle/fluid/operators/clip_by_norm_op.h
@@ -81,7 +81,12 @@ class ClipByNormKernel : public framework::OpKernel<T> {
81
*context.template device_context<DeviceContext>().eigen_device();
82
83
auto temp = (x_norm <= max_norm).template cast<T>();
84
- auto scaling = temp + (static_cast<T>(1) - temp) * max_norm / x_norm;
+ auto epsilon =
85
+ ((x_norm <= static_cast<T>(1e-30)).all().template cast<T>()) *
86
+ static_cast<T>(1e-6);
87
+
88
+ auto scaling =
89
+ temp + (static_cast<T>(1) - temp) * max_norm / (x_norm + epsilon);
90
Eigen::array<int, 1> one_dim{{1}};
91
Eigen::DSizes<int, 1> m_dsize(input->numel());
92
if (context.GetPlace() == platform::CPUPlace()) {
0 commit comments