Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
飞不过沧海
Paddle
提交
c335288d
P
Paddle
项目概览
飞不过沧海
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c335288d
编写于
3月 17, 2022
作者:
Z
zyfncg
提交者:
GitHub
3月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move infershape of set_value to phi (#40636)
上级
ed8a9370
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
83 addition
and
26 deletion
+83
-26
paddle/fluid/framework/infershape_utils.cc
paddle/fluid/framework/infershape_utils.cc
+45
-0
paddle/fluid/operators/set_value_op.cc
paddle/fluid/operators/set_value_op.cc
+12
-12
paddle/phi/infermeta/unary.cc
paddle/phi/infermeta/unary.cc
+10
-0
paddle/phi/infermeta/unary.h
paddle/phi/infermeta/unary.h
+2
-0
paddle/phi/ops/compat/set_value_sig.cc
paddle/phi/ops/compat/set_value_sig.cc
+14
-14
未找到文件。
paddle/fluid/framework/infershape_utils.cc
浏览文件 @
c335288d
...
@@ -442,6 +442,51 @@ phi::InferMetaContext BuildInferMetaContext(InferShapeContext* ctx,
...
@@ -442,6 +442,51 @@ phi::InferMetaContext BuildInferMetaContext(InferShapeContext* ctx,
attr_name
,
infershape_input
.
size
()));
attr_name
,
infershape_input
.
size
()));
}
}
}
}
}
else
if
(
attr_defs
[
i
].
type_index
==
std
::
type_index
(
typeid
(
std
::
vector
<
phi
::
Scalar
>
)))
{
auto
&
attr
=
attr_reader
.
GetAttr
(
attr_name
);
if
(
std
::
type_index
(
attr
.
type
())
==
std
::
type_index
(
typeid
(
std
::
vector
<
int32_t
>
)))
{
const
auto
&
vec
=
BOOST_GET_CONST
(
std
::
vector
<
int32_t
>
,
attr
);
std
::
vector
<
phi
::
Scalar
>
scalar_list
;
scalar_list
.
reserve
(
vec
.
size
());
for
(
const
auto
&
val
:
vec
)
{
scalar_list
.
emplace_back
(
val
);
}
infer_meta_context
.
EmplaceBackAttr
(
std
::
move
(
scalar_list
));
}
else
if
(
std
::
type_index
(
attr
.
type
())
==
std
::
type_index
(
typeid
(
std
::
vector
<
int64_t
>
)))
{
const
auto
&
vec
=
BOOST_GET_CONST
(
std
::
vector
<
int64_t
>
,
attr
);
std
::
vector
<
phi
::
Scalar
>
scalar_list
;
scalar_list
.
reserve
(
vec
.
size
());
for
(
const
auto
&
val
:
vec
)
{
scalar_list
.
emplace_back
(
val
);
}
infer_meta_context
.
EmplaceBackAttr
(
std
::
move
(
scalar_list
));
}
else
if
(
std
::
type_index
(
attr
.
type
())
==
std
::
type_index
(
typeid
(
std
::
vector
<
float
>
)))
{
const
auto
&
vec
=
BOOST_GET_CONST
(
std
::
vector
<
float
>
,
attr
);
std
::
vector
<
phi
::
Scalar
>
scalar_list
;
scalar_list
.
reserve
(
vec
.
size
());
for
(
const
auto
&
val
:
vec
)
{
scalar_list
.
emplace_back
(
val
);
}
infer_meta_context
.
EmplaceBackAttr
(
std
::
move
(
scalar_list
));
}
else
if
(
std
::
type_index
(
attr
.
type
())
==
std
::
type_index
(
typeid
(
std
::
vector
<
double
>
)))
{
const
auto
&
vec
=
BOOST_GET_CONST
(
std
::
vector
<
double
>
,
attr
);
std
::
vector
<
phi
::
Scalar
>
scalar_list
;
scalar_list
.
reserve
(
vec
.
size
());
for
(
const
auto
&
val
:
vec
)
{
scalar_list
.
emplace_back
(
val
);
}
infer_meta_context
.
EmplaceBackAttr
(
std
::
move
(
scalar_list
));
}
else
{
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"Unsupported cast op attribute `%s` to vector<Scalar> when "
"construct InferMetaContext."
,
attr_names
[
i
]));
}
}
else
if
(
ctx
->
HasAttr
(
attr_name
))
{
}
else
if
(
ctx
->
HasAttr
(
attr_name
))
{
// Emplace Back Attr according to the type of attr.
// Emplace Back Attr according to the type of attr.
auto
&
attr
=
attr_reader
.
GetAttr
(
attr_name
);
auto
&
attr
=
attr_reader
.
GetAttr
(
attr_name
);
...
...
paddle/fluid/operators/set_value_op.cc
浏览文件 @
c335288d
...
@@ -13,9 +13,15 @@
...
@@ -13,9 +13,15 @@
// limitations under the License.
// limitations under the License.
#include "paddle/fluid/operators/set_value_op.h"
#include "paddle/fluid/operators/set_value_op.h"
#include <string>
#include <string>
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/infermeta/unary.h"
namespace
paddle
{
namespace
paddle
{
namespace
framework
{
namespace
framework
{
class
InferShapeContext
;
class
InferShapeContext
;
...
@@ -34,6 +40,8 @@ class CPUDeviceContext;
...
@@ -34,6 +40,8 @@ class CPUDeviceContext;
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
using
Tensor
=
framework
::
Tensor
;
class
SetValue
:
public
framework
::
OperatorWithKernel
{
class
SetValue
:
public
framework
::
OperatorWithKernel
{
public:
public:
SetValue
(
const
std
::
string
&
type
,
const
framework
::
VariableNameMap
&
inputs
,
SetValue
(
const
std
::
string
&
type
,
const
framework
::
VariableNameMap
&
inputs
,
...
@@ -41,17 +49,6 @@ class SetValue : public framework::OperatorWithKernel {
...
@@ -41,17 +49,6 @@ class SetValue : public framework::OperatorWithKernel {
const
framework
::
AttributeMap
&
attrs
)
const
framework
::
AttributeMap
&
attrs
)
:
OperatorWithKernel
(
type
,
inputs
,
outputs
,
attrs
)
{}
:
OperatorWithKernel
(
type
,
inputs
,
outputs
,
attrs
)
{}
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"Input"
),
"Input"
,
"Input"
,
"SetValue"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
"Out"
),
"Output"
,
"Out"
,
"SetValue"
);
auto
in_dims
=
ctx
->
GetInputDim
(
"Input"
);
PADDLE_ENFORCE_LT
(
in_dims
.
size
(),
7
,
platform
::
errors
::
InvalidArgument
(
"The rank of input should be less than 7, but received %d."
,
in_dims
.
size
()));
}
protected:
protected:
framework
::
OpKernelType
GetExpectedKernelType
(
framework
::
OpKernelType
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
...
@@ -236,10 +233,13 @@ DECLARE_INPLACE_OP_INFERER(SetValueOpInplaceInferer, {"Input", "Out"});
...
@@ -236,10 +233,13 @@ DECLARE_INPLACE_OP_INFERER(SetValueOpInplaceInferer, {"Input", "Out"});
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
namespace
plat
=
paddle
::
platform
;
DECLARE_INFER_SHAPE_FUNCTOR
(
set_value
,
SetValueInferShapeFunctor
,
PD_INFER_META
(
phi
::
SetValueInferMeta
));
REGISTER_OPERATOR
(
set_value
,
ops
::
SetValue
,
ops
::
SetValueMaker
,
REGISTER_OPERATOR
(
set_value
,
ops
::
SetValue
,
ops
::
SetValueMaker
,
ops
::
SetValueGradMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
SetValueGradMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
SetValueGradMaker
<
paddle
::
imperative
::
OpBase
>
,
ops
::
SetValueGradMaker
<
paddle
::
imperative
::
OpBase
>
,
ops
::
SetValueOpInplaceInferer
);
ops
::
SetValueOpInplaceInferer
,
SetValueInferShapeFunctor
);
REGISTER_OPERATOR
(
set_value_grad
,
ops
::
SetValueGrad
);
REGISTER_OPERATOR
(
set_value_grad
,
ops
::
SetValueGrad
);
...
...
paddle/phi/infermeta/unary.cc
浏览文件 @
c335288d
...
@@ -1090,6 +1090,16 @@ void RollInferMeta(const MetaTensor& x,
...
@@ -1090,6 +1090,16 @@ void RollInferMeta(const MetaTensor& x,
out
->
set_dtype
(
x
.
dtype
());
out
->
set_dtype
(
x
.
dtype
());
}
}
void
SetValueInferMeta
(
const
MetaTensor
&
x
,
MetaTensor
*
out
)
{
auto
in_dims
=
x
.
dims
();
PADDLE_ENFORCE_LT
(
in_dims
.
size
(),
7
,
phi
::
errors
::
InvalidArgument
(
"The rank of input should be less than 7, but received %d."
,
in_dims
.
size
()));
}
void
ShapeInferMeta
(
const
MetaTensor
&
input
,
MetaTensor
*
out
)
{
void
ShapeInferMeta
(
const
MetaTensor
&
input
,
MetaTensor
*
out
)
{
auto
in_dim
=
input
.
dims
();
auto
in_dim
=
input
.
dims
();
out
->
set_dims
(
phi
::
make_ddim
({
in_dim
.
size
()}));
out
->
set_dims
(
phi
::
make_ddim
({
in_dim
.
size
()}));
...
...
paddle/phi/infermeta/unary.h
浏览文件 @
c335288d
...
@@ -177,6 +177,8 @@ void RollInferMeta(const MetaTensor& x,
...
@@ -177,6 +177,8 @@ void RollInferMeta(const MetaTensor& x,
const
std
::
vector
<
int64_t
>&
axis
,
const
std
::
vector
<
int64_t
>&
axis
,
MetaTensor
*
out
);
MetaTensor
*
out
);
void
SetValueInferMeta
(
const
MetaTensor
&
x
,
MetaTensor
*
out
);
void
ShapeInferMeta
(
const
MetaTensor
&
input
,
MetaTensor
*
out
);
void
ShapeInferMeta
(
const
MetaTensor
&
input
,
MetaTensor
*
out
);
void
ShardIndexInferMeta
(
const
MetaTensor
&
in
,
void
ShardIndexInferMeta
(
const
MetaTensor
&
in
,
...
...
paddle/phi/ops/compat/set_value_sig.cc
浏览文件 @
c335288d
...
@@ -19,9 +19,9 @@ namespace phi {
...
@@ -19,9 +19,9 @@ namespace phi {
KernelSignature
SetValueOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
KernelSignature
SetValueOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
if
(
ctx
.
IsDenseTensorInput
(
"Input"
))
{
if
(
ctx
.
IsDenseTensorInput
(
"Input"
))
{
if
(
ctx
.
HasInput
(
"StartsTensorList"
)
)
{
if
(
ctx
.
InputSize
(
"StartsTensorList"
)
>
0
)
{
if
(
ctx
.
HasInput
(
"EndsTensorList"
)
)
{
if
(
ctx
.
InputSize
(
"EndsTensorList"
)
>
0
)
{
if
(
ctx
.
HasInput
(
"StepsTensorList"
)
)
{
if
(
ctx
.
InputSize
(
"StepsTensorList"
)
>
0
)
{
if
(
ctx
.
HasInput
(
"ValueTensor"
))
{
if
(
ctx
.
HasInput
(
"ValueTensor"
))
{
return
KernelSignature
(
"set_value_with_tensor"
,
return
KernelSignature
(
"set_value_with_tensor"
,
{
"Input"
,
"ValueTensor"
},
{
"Input"
,
"ValueTensor"
},
...
@@ -197,7 +197,7 @@ KernelSignature SetValueOpArgumentMapping(const ArgumentMappingContext& ctx) {
...
@@ -197,7 +197,7 @@ KernelSignature SetValueOpArgumentMapping(const ArgumentMappingContext& ctx) {
}
}
}
}
}
else
{
}
else
{
if
(
ctx
.
HasInput
(
"StepsTensorList"
)
)
{
if
(
ctx
.
InputSize
(
"StepsTensorList"
)
>
0
)
{
if
(
ctx
.
HasInput
(
"ValueTensor"
))
{
if
(
ctx
.
HasInput
(
"ValueTensor"
))
{
return
KernelSignature
(
"set_value_with_tensor"
,
return
KernelSignature
(
"set_value_with_tensor"
,
{
"Input"
,
"ValueTensor"
},
{
"Input"
,
"ValueTensor"
},
...
@@ -374,8 +374,8 @@ KernelSignature SetValueOpArgumentMapping(const ArgumentMappingContext& ctx) {
...
@@ -374,8 +374,8 @@ KernelSignature SetValueOpArgumentMapping(const ArgumentMappingContext& ctx) {
}
}
}
}
}
else
{
}
else
{
if
(
ctx
.
HasInput
(
"EndsTensorList"
)
)
{
if
(
ctx
.
InputSize
(
"EndsTensorList"
)
>
0
)
{
if
(
ctx
.
HasInput
(
"StepsTensorList"
)
)
{
if
(
ctx
.
InputSize
(
"StepsTensorList"
)
>
0
)
{
if
(
ctx
.
HasInput
(
"ValueTensor"
))
{
if
(
ctx
.
HasInput
(
"ValueTensor"
))
{
return
KernelSignature
(
"set_value_with_tensor"
,
return
KernelSignature
(
"set_value_with_tensor"
,
{
"Input"
,
"ValueTensor"
},
{
"Input"
,
"ValueTensor"
},
...
@@ -551,7 +551,7 @@ KernelSignature SetValueOpArgumentMapping(const ArgumentMappingContext& ctx) {
...
@@ -551,7 +551,7 @@ KernelSignature SetValueOpArgumentMapping(const ArgumentMappingContext& ctx) {
}
}
}
}
}
else
{
}
else
{
if
(
ctx
.
HasInput
(
"StepsTensorList"
)
)
{
if
(
ctx
.
InputSize
(
"StepsTensorList"
)
>
0
)
{
if
(
ctx
.
HasInput
(
"ValueTensor"
))
{
if
(
ctx
.
HasInput
(
"ValueTensor"
))
{
return
KernelSignature
(
"set_value_with_tensor"
,
return
KernelSignature
(
"set_value_with_tensor"
,
{
"Input"
,
"ValueTensor"
},
{
"Input"
,
"ValueTensor"
},
...
@@ -734,9 +734,9 @@ KernelSignature SetValueOpArgumentMapping(const ArgumentMappingContext& ctx) {
...
@@ -734,9 +734,9 @@ KernelSignature SetValueOpArgumentMapping(const ArgumentMappingContext& ctx) {
KernelSignature
SetValueGradOpArgumentMapping
(
KernelSignature
SetValueGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
const
ArgumentMappingContext
&
ctx
)
{
if
(
ctx
.
HasInput
(
"StartsTensorList"
)
)
{
if
(
ctx
.
InputSize
(
"StartsTensorList"
)
>
0
)
{
if
(
ctx
.
HasInput
(
"EndsTensorList"
)
)
{
if
(
ctx
.
InputSize
(
"EndsTensorList"
)
>
0
)
{
if
(
ctx
.
HasInput
(
"StepsTensorList"
)
)
{
if
(
ctx
.
InputSize
(
"StepsTensorList"
)
>
0
)
{
return
KernelSignature
(
return
KernelSignature
(
"set_value_grad"
,
"set_value_grad"
,
{
GradVarName
(
"Out"
)},
{
GradVarName
(
"Out"
)},
...
@@ -760,7 +760,7 @@ KernelSignature SetValueGradOpArgumentMapping(
...
@@ -760,7 +760,7 @@ KernelSignature SetValueGradOpArgumentMapping(
{
GradVarName
(
"Input"
),
GradVarName
(
"ValueTensor"
)});
{
GradVarName
(
"Input"
),
GradVarName
(
"ValueTensor"
)});
}
}
}
else
{
}
else
{
if
(
ctx
.
HasInput
(
"StepsTensorList"
)
)
{
if
(
ctx
.
InputSize
(
"StepsTensorList"
)
>
0
)
{
return
KernelSignature
(
return
KernelSignature
(
"set_value_grad"
,
"set_value_grad"
,
{
GradVarName
(
"Out"
)},
{
GradVarName
(
"Out"
)},
...
@@ -785,8 +785,8 @@ KernelSignature SetValueGradOpArgumentMapping(
...
@@ -785,8 +785,8 @@ KernelSignature SetValueGradOpArgumentMapping(
}
}
}
}
}
else
{
}
else
{
if
(
ctx
.
HasInput
(
"EndsTensorList"
)
)
{
if
(
ctx
.
InputSize
(
"EndsTensorList"
)
>
0
)
{
if
(
ctx
.
HasInput
(
"StepsTensorList"
)
)
{
if
(
ctx
.
InputSize
(
"StepsTensorList"
)
>
0
)
{
return
KernelSignature
(
return
KernelSignature
(
"set_value_grad"
,
"set_value_grad"
,
{
GradVarName
(
"Out"
)},
{
GradVarName
(
"Out"
)},
...
@@ -810,7 +810,7 @@ KernelSignature SetValueGradOpArgumentMapping(
...
@@ -810,7 +810,7 @@ KernelSignature SetValueGradOpArgumentMapping(
{
GradVarName
(
"Input"
),
GradVarName
(
"ValueTensor"
)});
{
GradVarName
(
"Input"
),
GradVarName
(
"ValueTensor"
)});
}
}
}
else
{
}
else
{
if
(
ctx
.
HasInput
(
"StepsTensorList"
)
)
{
if
(
ctx
.
InputSize
(
"StepsTensorList"
)
>
0
)
{
return
KernelSignature
(
return
KernelSignature
(
"set_value_grad"
,
"set_value_grad"
,
{
GradVarName
(
"Out"
)},
{
GradVarName
(
"Out"
)},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录