提交 775c6024 编写于 作者: Q qiaolongfei

remove using in sgd header file

上级 ee7b3ed0
...@@ -19,32 +19,25 @@ limitations under the License. */ ...@@ -19,32 +19,25 @@ limitations under the License. */
namespace paddle { namespace paddle {
namespace operators { namespace operators {
using Tensor = framework::Tensor;
template <typename T, int MajorType = Eigen::RowMajor,
typename IndexType = Eigen::DenseIndex>
using EigenVector = framework::EigenVector<T, MajorType, IndexType>;
template <typename T, int MajorType = Eigen::RowMajor,
typename IndexType = Eigen::DenseIndex>
using EigenScalar = framework::EigenScalar<T, MajorType, IndexType>;
template <typename Place, typename T> template <typename Place, typename T>
class SGDOpKernel : public framework::OpKernel<T> { class SGDOpKernel : public framework::OpKernel<T> {
public: public:
void Compute(const framework::ExecutionContext& ctx) const override { void Compute(const framework::ExecutionContext& ctx) const override {
auto param = ctx.Input<Tensor>("Param"); auto param = ctx.Input<framework::Tensor>("Param");
auto grad = ctx.Input<Tensor>("Grad"); auto grad = ctx.Input<framework::Tensor>("Grad");
auto param_out = ctx.Output<Tensor>("ParamOut"); auto param_out = ctx.Output<framework::Tensor>("ParamOut");
auto learning_rate = ctx.Input<Tensor>("LearningRate"); auto learning_rate = ctx.Input<framework::Tensor>("LearningRate");
param_out->mutable_data<T>(ctx.GetPlace()); param_out->mutable_data<T>(ctx.GetPlace());
auto p = EigenVector<T>::Flatten(*param); auto p = framework::EigenVector<T>::Flatten(*param);
auto g = EigenVector<T>::Flatten(*grad); auto g = framework::EigenVector<T>::Flatten(*grad);
auto o = EigenVector<T>::Flatten(*param_out); auto o = framework::EigenVector<T>::Flatten(*param_out);
auto lr = EigenScalar<T>::From(*learning_rate); auto lr = framework::EigenVector<T>::From(*learning_rate);
auto place = ctx.GetEigenDevice<Place>(); auto place = ctx.GetEigenDevice<Place>();
o.device(place) = p - lr * g; Eigen::DSizes<int, 2> grad_dsize(grad->dims()[0], grad->dims()[1]);
o.device(place) = p - lr.broadcast(grad_dsize) * g;
} }
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册