Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
飞不过沧海
Paddle
提交
35d5db36
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,发现更多精彩内容 >>
未验证
提交
35d5db36
编写于
10月 18, 2022
作者:
zhouweiwei2014
提交者:
GitHub
10月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Zero-Dim] support 0D Tensor for reshape/create_parameters (#47074)
上级
3108ba11
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
32 addition
and
40 deletion
+32
-40
paddle/phi/infermeta/unary.cc
paddle/phi/infermeta/unary.cc
+1
-9
paddle/scripts/paddle_build.sh
paddle/scripts/paddle_build.sh
+5
-5
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+0
-12
python/paddle/fluid/tests/unittests/test_egr_python_api.py
python/paddle/fluid/tests/unittests/test_egr_python_api.py
+3
-5
python/paddle/fluid/tests/unittests/test_parameter.py
python/paddle/fluid/tests/unittests/test_parameter.py
+7
-1
python/paddle/fluid/tests/unittests/test_reshape_op.py
python/paddle/fluid/tests/unittests/test_reshape_op.py
+16
-8
未找到文件。
paddle/phi/infermeta/unary.cc
浏览文件 @
35d5db36
...
...
@@ -1460,11 +1460,6 @@ static phi::DDim ValidateShape(const std::vector<int64_t> shape,
void
InferMetaFromVecValue
(
const
MetaTensor
&
x
,
const
std
::
vector
<
int64_t
>&
shape
,
MetaTensor
*
out
)
{
PADDLE_ENFORCE_EQ
(
!
shape
.
empty
(),
true
,
phi
::
errors
::
InvalidArgument
(
"The parameter 'shape' in ReshapeOp must be set. "
"But received 'shape' is empty."
));
auto
x_dims
=
x
.
dims
();
auto
out_dims
=
ValidateShape
(
shape
,
x_dims
);
out
->
set_dims
(
out_dims
);
...
...
@@ -2833,6 +2828,7 @@ void RepeatInterleaveInferMeta(const MetaTensor& x,
out
->
share_lod
(
x
);
out
->
set_dtype
(
x
.
dtype
());
}
void
ReshapeInferMeta
(
const
MetaTensor
&
x
,
const
IntArray
&
shape
,
MetaTensor
*
out
,
...
...
@@ -2846,10 +2842,6 @@ void ReshapeInferMeta(const MetaTensor& x,
out
->
share_lod
(
x
);
return
;
}
PADDLE_ENFORCE_GT
(
shape_data
.
size
(),
0
,
phi
::
errors
::
InvalidArgument
(
"The shape's size in ReshapeOp can't be zero."
));
InferMetaFromVecValue
(
x
,
shape_data
,
out
);
}
...
...
paddle/scripts/paddle_build.sh
浏览文件 @
35d5db36
...
...
@@ -3257,12 +3257,14 @@ function build_document_preview() {
# origin name: example
function
exec_samplecode_test
()
{
if
[
-d
"
${
PADDLE_ROOT
}
/build/pr_whl"
]
;
then
pip
install
${
PADDLE_ROOT
}
/build/pr_whl/
*
.whl
pip
install
${
PADDLE_ROOT
}
/build/pr_whl/
*
.whl
--force-reinstall
else
pip
install
${
PADDLE_ROOT
}
/build/python/dist/
*
.whl
echo
"WARNING: PR wheel is not found. Use develop wheel !!!"
pip
install
${
PADDLE_ROOT
}
/build/python/dist/
*
.whl
--force-reinstall
fi
paddle version
python
-c
"import paddle;print(paddle.__version__);paddle.version.show()"
cd
${
PADDLE_ROOT
}
/tools
if
[
"
$1
"
=
"cpu"
]
;
then
python sampcd_processor.py cpu
;
example_error
=
$?
...
...
@@ -3473,7 +3475,6 @@ function main() {
;;
build_and_check_gpu
)
set
+e
set
+x
example_info_gpu
=
""
example_code_gpu
=
0
if
[
"
${
WITH_GPU
}
"
==
"ON"
]
;
then
...
...
@@ -3483,7 +3484,6 @@ function main() {
example_info
=
$(
exec_samplecode_test cpu
)
example_code
=
$?
summary_check_problems
$[
${
example_code_gpu
}
+
${
example_code
}
]
"
${
example_info_gpu
}
\n
${
example_info
}
"
set
-x
assert_api_spec_approvals
;;
check_whl_size
)
...
...
python/paddle/fluid/framework.py
浏览文件 @
35d5db36
...
...
@@ -6578,10 +6578,6 @@ class Parameter(Variable):
if
dtype
is
None
:
raise
ValueError
(
"The dtype of Parameter should not be None"
)
if
len
(
shape
)
==
0
:
raise
ValueError
(
"The dimensions of shape for Parameter must be greater than 0"
)
for
each
in
shape
:
if
each
<
0
:
raise
ValueError
(
...
...
@@ -6681,10 +6677,6 @@ class ParamBase(core.VarBase):
if
dtype
is
None
:
raise
ValueError
(
"The dtype of Parameter should not be None"
)
if
len
(
shape
)
==
0
:
raise
ValueError
(
"The dimensions of shape for Parameter must be greater than 0"
)
for
each
in
shape
:
if
each
<
0
:
raise
ValueError
(
...
...
@@ -6827,10 +6819,6 @@ class EagerParamBase(_core_eager_eagertensor):
if
dtype
is
None
:
raise
ValueError
(
"The dtype of Parameter should not be None"
)
if
len
(
shape
)
==
0
:
raise
ValueError
(
"The dimensions of shape for Parameter must be greater than 0"
)
for
each
in
shape
:
if
each
<
0
:
raise
ValueError
(
...
...
python/paddle/fluid/tests/unittests/test_egr_python_api.py
浏览文件 @
35d5db36
...
...
@@ -249,6 +249,9 @@ class EagerVariablePropertiesAndMethodsTestCase(unittest.TestCase):
self
.
assertTrue
(
egr_tensor12
.
place
.
_equals
(
paddle
.
fluid
.
CPUPlace
()))
np
.
testing
.
assert_array_equal
(
egr_tensor12
.
numpy
(),
x
)
zero_dim_param
=
EagerParamBase
(
shape
=
[],
dtype
=
"float32"
)
self
.
assertEqual
(
zero_dim_param
.
shape
,
[])
with
self
.
assertRaisesRegexp
(
ValueError
,
"The shape of Parameter should not be None"
):
eager_param
=
EagerParamBase
(
shape
=
None
,
dtype
=
"float32"
)
...
...
@@ -257,11 +260,6 @@ class EagerVariablePropertiesAndMethodsTestCase(unittest.TestCase):
ValueError
,
"The dtype of Parameter should not be None"
):
eager_param
=
EagerParamBase
(
shape
=
[
1
,
1
],
dtype
=
None
)
with
self
.
assertRaisesRegexp
(
ValueError
,
"The dimensions of shape for Parameter must be greater than 0"
):
eager_param
=
EagerParamBase
(
shape
=
[],
dtype
=
"float32"
)
with
self
.
assertRaisesRegexp
(
ValueError
,
"Each dimension of shape for Parameter must be greater than 0, but received /*"
...
...
python/paddle/fluid/tests/unittests/test_parameter.py
浏览文件 @
35d5db36
...
...
@@ -16,7 +16,7 @@ import unittest
import
copy
import
paddle
from
paddle.fluid.dygraph
import
guard
from
paddle.fluid.framework
import
default_main_program
,
Variable
,
_test_eager_guard
from
paddle.fluid.framework
import
default_main_program
,
Variable
,
_test_eager_guard
,
ParamBase
import
paddle.fluid.core
as
core
from
paddle.fluid.executor
import
Executor
import
paddle.fluid.io
as
io
...
...
@@ -48,6 +48,9 @@ class ParameterChecks(unittest.TestCase):
p
=
io
.
get_parameter_value_by_name
(
'fc.w'
,
exe
,
main_program
)
np
.
testing
.
assert_array_equal
(
p
,
np
.
ones
(
shape
)
*
val
)
zero_dim_param
=
b
.
create_parameter
(
name
=
'x'
,
shape
=
[],
dtype
=
'float32'
)
self
.
assertEqual
(
zero_dim_param
.
shape
,
())
def
func_parambase
(
self
):
with
guard
():
linear
=
paddle
.
nn
.
Linear
(
10
,
10
)
...
...
@@ -70,6 +73,9 @@ class ParameterChecks(unittest.TestCase):
pram_copy2
=
copy
.
deepcopy
(
param
,
memo
)
self
.
assertEqual
(
id
(
param_copy
),
id
(
pram_copy2
))
zero_dim_param
=
ParamBase
(
shape
=
[],
dtype
=
'float32'
)
self
.
assertEqual
(
zero_dim_param
.
shape
,
[])
def
test_parambase
(
self
):
with
_test_eager_guard
():
self
.
func_parambase
()
...
...
python/paddle/fluid/tests/unittests/test_reshape_op.py
浏览文件 @
35d5db36
...
...
@@ -57,17 +57,17 @@ class TestReshapeOp_ZeroDim1(OpTest):
class
TestReshapeOp_ZeroDim2
(
OpTest
):
def
init_data
(
self
):
self
.
ori_shape
=
(
1
)
self
.
new_shape
=
()
self
.
infered_shape
=
()
self
.
ori_shape
=
()
self
.
new_shape
=
(
-
1
)
self
.
infered_shape
=
(
1
)
class
TestReshapeOp_ZeroDim3
(
OpTest
):
def
init_data
(
self
):
self
.
ori_shape
=
()
self
.
new_shape
=
(
-
1
)
self
.
infered_shape
=
(
1
)
self
.
ori_shape
=
(
1
)
self
.
new_shape
=
()
self
.
infered_shape
=
()
class
TestReshapeBF16Op
(
OpTest
):
...
...
@@ -560,16 +560,24 @@ class TestReshapeAPI_ZeroDim(unittest.TestCase):
out
=
paddle
.
reshape
(
x
,
[
1
])
out
.
backward
()
self
.
assertEqual
(
out
.
shape
,
[
1
])
self
.
assertEqual
(
x
.
grad
.
shape
,
[])
self
.
assertEqual
(
out
.
shape
,
[
1
])
self
.
assertEqual
(
out
.
grad
.
shape
,
[
1
])
out
=
paddle
.
reshape
(
x
,
[
-
1
,
1
])
out
.
backward
()
self
.
assertEqual
(
out
.
shape
,
[
1
,
1
])
self
.
assertEqual
(
x
.
grad
.
shape
,
[])
self
.
assertEqual
(
out
.
shape
,
[
1
,
1
])
self
.
assertEqual
(
out
.
grad
.
shape
,
[
1
,
1
])
x
=
paddle
.
rand
([
1
])
x
.
stop_gradient
=
False
out
=
paddle
.
reshape
(
x
,
[])
out
.
backward
()
self
.
assertEqual
(
x
.
grad
.
shape
,
[
1
])
self
.
assertEqual
(
out
.
shape
,
[])
self
.
assertEqual
(
out
.
grad
.
shape
,
[])
paddle
.
enable_static
()
def
test_static
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录