Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a533dae3
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
a533dae3
编写于
8月 18, 2023
作者:
H
huangjiyi
提交者:
GitHub
8月 18, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move dgc_momentum InferShape to phi (#56358)
上级
ee01d78f
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
88 addition
and
87 deletion
+88
-87
paddle/fluid/operators/optimizers/dgc_momentum_op.cc
paddle/fluid/operators/optimizers/dgc_momentum_op.cc
+8
-87
paddle/phi/infermeta/multiary.cc
paddle/phi/infermeta/multiary.cc
+61
-0
paddle/phi/infermeta/multiary.h
paddle/phi/infermeta/multiary.h
+19
-0
未找到文件。
paddle/fluid/operators/optimizers/dgc_momentum_op.cc
浏览文件 @
a533dae3
...
...
@@ -14,7 +14,9 @@
#include <string>
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/phi/infermeta/multiary.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -24,92 +26,6 @@ class DGCMomentumOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"current_step"
),
"Input"
,
"current_step"
,
"DGCMomentumOp"
);
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"nranks"
),
"Input"
,
"nranks"
,
"DGCMomentumOp"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
"Grad_out"
),
"Output"
,
"Grad_out"
,
"DGCMomentumOp"
);
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"Param"
),
true
,
platform
::
errors
::
NotFound
(
"Input(param) of Momentum should not be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"Grad"
),
true
,
platform
::
errors
::
NotFound
(
"Input(grad) of Momentum should not be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"Velocity"
),
true
,
platform
::
errors
::
NotFound
(
"Input(velocity) of Momentum should not be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"LearningRate"
),
true
,
platform
::
errors
::
NotFound
(
"Input(LearningRate) of Momentum should not be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
GetInputsVarType
(
"Param"
).
front
(),
framework
::
proto
::
VarType
::
LOD_TENSOR
,
platform
::
errors
::
InvalidArgument
(
"The input var's type should be phi::DenseTensor, "
"but the received is %s"
,
ctx
->
GetInputsVarType
(
"Param"
).
front
()));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"ParamOut"
),
true
,
platform
::
errors
::
NotFound
(
"Output(ParamOut) of Momentum should not be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"VelocityOut"
),
true
,
platform
::
errors
::
NotFound
(
"Output(VelocityOut) of Momentum should not be null."
));
auto
lr_dims
=
ctx
->
GetInputDim
(
"LearningRate"
);
PADDLE_ENFORCE_NE
(
phi
::
product
(
lr_dims
),
0
,
platform
::
errors
::
InvalidArgument
(
"Maybe the Input variable LearningRate has not "
"been initialized. You may need to confirm "
"if you put exe.run(startup_program) "
"after optimizer.minimize function."
));
PADDLE_ENFORCE_EQ
(
phi
::
product
(
lr_dims
),
1
,
platform
::
errors
::
InvalidArgument
(
"Learning_rate should be a scalar. But Received "
"LearningRate's dim [%s]"
,
phi
::
product
(
lr_dims
)));
auto
param_dim
=
ctx
->
GetInputDim
(
"Param"
);
if
(
ctx
->
GetInputsVarType
(
"Grad"
)[
0
]
==
framework
::
proto
::
VarType
::
LOD_TENSOR
)
{
PADDLE_ENFORCE_EQ
(
param_dim
,
ctx
->
GetInputDim
(
"Grad"
),
platform
::
errors
::
InvalidArgument
(
"Param and Grad input of MomentumOp should have the same "
"dimension. But received Param's dim [%s] and Grad's dim [%s]."
,
param_dim
,
ctx
->
GetInputDim
(
"Grad"
)));
PADDLE_ENFORCE_EQ
(
param_dim
,
ctx
->
GetInputDim
(
"Velocity"
),
platform
::
errors
::
InvalidArgument
(
"Param and Velocity of MomentumOp should have the same "
"dimension. But received Param's dim [%s] and Velocity [%s]."
,
param_dim
,
ctx
->
GetInputDim
(
"Velocity"
)));
}
ctx
->
SetOutputDim
(
"ParamOut"
,
param_dim
);
ctx
->
SetOutputDim
(
"VelocityOut"
,
param_dim
);
if
(
ctx
->
HasOutput
(
"MasterParamOut"
))
{
ctx
->
SetOutputDim
(
"MasterParamOut"
,
param_dim
);
}
}
phi
::
KernelKey
GetKernelTypeForVar
(
const
std
::
string
&
var_name
,
const
phi
::
DenseTensor
&
tensor
,
...
...
@@ -199,7 +115,12 @@ DGC Momentum Operator.
}
// namespace operators
}
// namespace paddle
DECLARE_INFER_SHAPE_FUNCTOR
(
dgc_momentum
,
DGCMomentumInferShapeFunctor
,
PD_INFER_META
(
phi
::
DGCMomentumInferMeta
));
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_WITHOUT_GRADIENT
(
dgc_momentum
,
ops
::
DGCMomentumOp
,
ops
::
DGCMomentumOpMaker
);
ops
::
DGCMomentumOpMaker
,
DGCMomentumInferShapeFunctor
);
paddle/phi/infermeta/multiary.cc
浏览文件 @
a533dae3
...
...
@@ -1305,6 +1305,67 @@ void DeformableConvInferMeta(const MetaTensor& x,
out
->
set_dtype
(
x
.
dtype
());
}
void
DGCMomentumInferMeta
(
const
MetaTensor
&
param
,
const
MetaTensor
&
grad
,
const
MetaTensor
&
velocity
,
const
MetaTensor
&
learning_rate
,
const
MetaTensor
&
master_param
,
const
MetaTensor
&
current_step_tensor
,
const
MetaTensor
&
nranks_tensor
,
float
mu
,
bool
use_nesterov
,
const
std
::
string
&
regularization_method
,
float
regularization_coeff
,
bool
multi_precision
,
float
rescale_grad
,
float
rampup_begin_step
,
MetaTensor
*
param_out
,
MetaTensor
*
velocity_out
,
MetaTensor
*
master_param_out
,
MetaTensor
*
grad_out
)
{
auto
lr_dims
=
learning_rate
.
dims
();
PADDLE_ENFORCE_NE
(
phi
::
product
(
lr_dims
),
0
,
phi
::
errors
::
InvalidArgument
(
"Maybe the Input variable LearningRate has not "
"been initialized. You may need to confirm "
"if you put exe.run(startup_program) "
"after optimizer.minimize function."
));
PADDLE_ENFORCE_EQ
(
phi
::
product
(
lr_dims
),
1
,
phi
::
errors
::
InvalidArgument
(
"Learning_rate should be a scalar. But Received "
"LearningRate's dim [%s]"
,
phi
::
product
(
lr_dims
)));
auto
param_dims
=
param
.
dims
();
auto
grad_dims
=
grad
.
dims
();
auto
velocity_dims
=
velocity
.
dims
();
PADDLE_ENFORCE_EQ
(
param_dims
,
grad_dims
,
phi
::
errors
::
InvalidArgument
(
"Param and Grad input of MomentumOp should have the same "
"dimension. But received Param's dim [%s] and Grad's dim [%s]."
,
param_dims
,
grad_dims
));
PADDLE_ENFORCE_EQ
(
param_dims
,
velocity_dims
,
phi
::
errors
::
InvalidArgument
(
"Param and Velocity of MomentumOp should have the same "
"dimension. But received Param's dim [%s] and Velocity [%s]."
,
param_dims
,
velocity_dims
));
param_out
->
set_dims
(
param_dims
);
velocity_out
->
set_dims
(
param_dims
);
if
(
master_param
!=
nullptr
)
{
master_param_out
->
set_dims
(
param_dims
);
}
}
void
EditDistanceInferMeta
(
const
MetaTensor
&
hyps
,
const
MetaTensor
&
refs
,
const
MetaTensor
&
hypslength
,
...
...
paddle/phi/infermeta/multiary.h
浏览文件 @
a533dae3
...
...
@@ -280,6 +280,25 @@ void DeformableConvInferMeta(const MetaTensor& x,
MetaTensor
*
out
,
MetaConfig
config
=
MetaConfig
());
void
DGCMomentumInferMeta
(
const
MetaTensor
&
param
,
const
MetaTensor
&
grad
,
const
MetaTensor
&
velocity
,
const
MetaTensor
&
learning_rate
,
const
MetaTensor
&
master_param
,
const
MetaTensor
&
current_step_tensor
,
const
MetaTensor
&
nranks_tensor
,
float
mu
,
bool
use_nesterov
,
const
std
::
string
&
regularization_method
,
float
regularization_coeff
,
bool
multi_precision
,
float
rescale_grad
,
float
rampup_begin_step
,
MetaTensor
*
param_out
,
MetaTensor
*
velocity_out
,
MetaTensor
*
master_param_out
,
MetaTensor
*
grad_out
);
void
EditDistanceInferMeta
(
const
MetaTensor
&
hyps
,
const
MetaTensor
&
refs
,
const
MetaTensor
&
hypslength
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录