diff --git a/paddle/fluid/operators/clip_by_norm_op.h b/paddle/fluid/operators/clip_by_norm_op.h index a2562c44d70f4038c6b0b93d5464796014f30db3..f6f99369636268b2d628a211e636f8e0770cfbcf 100644 --- a/paddle/fluid/operators/clip_by_norm_op.h +++ b/paddle/fluid/operators/clip_by_norm_op.h @@ -82,7 +82,12 @@ class ClipByNormKernel : public framework::OpKernel { auto scaling = temp + (static_cast(1) - temp) * max_norm / x_norm; Eigen::array one_dim{{1}}; Eigen::DSizes m_dsize(input->numel()); - out.device(place) = x * scaling.reshape(one_dim).broadcast(m_dsize); + if (context.GetPlace() == platform::CPUPlace()) { + out.device(place) = + x * scaling.reshape(one_dim).eval().broadcast(m_dsize); + } else { + out.device(place) = x * scaling.reshape(one_dim).broadcast(m_dsize); + } } };