Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
b0ca369b
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
b0ca369b
编写于
4月 07, 2022
作者:
0
0x45f
提交者:
GitHub
4月 07, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add fill_constant_batch_size YAML and UT (#41474)
上级
ad4193fe
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
99 addition
and
0 deletion
+99
-0
python/paddle/fluid/layers/tensor.py
python/paddle/fluid/layers/tensor.py
+12
-0
python/paddle/fluid/tests/unittests/test_fill_constant_batch_size_like.py
...uid/tests/unittests/test_fill_constant_batch_size_like.py
+75
-0
python/paddle/utils/code_gen/api.yaml
python/paddle/utils/code_gen/api.yaml
+12
-0
未找到文件。
python/paddle/fluid/layers/tensor.py
浏览文件 @
b0ca369b
...
...
@@ -846,6 +846,18 @@ def fill_constant_batch_size_like(input,
input=like, shape=[1], value=0, dtype='int64') #like=[[10, 10]] data=[0]
"""
if
in_dygraph_mode
():
if
not
isinstance
(
dtype
,
core
.
VarDesc
.
VarType
):
dtype
=
convert_np_dtype_to_dtype_
(
dtype
)
place
=
_current_expected_place
()
if
force_cpu
:
place
=
core
.
CPUPlace
()
out
=
_C_ops
.
final_state_full_batch_size_like
(
input
,
shape
,
dtype
,
value
,
input_dim_idx
,
output_dim_idx
,
place
)
out
.
stop_gradient
=
True
return
out
helper
=
LayerHelper
(
"fill_constant_batch_size_like"
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
dtype
)
attrs
=
{
...
...
python/paddle/fluid/tests/unittests/test_fill_constant_batch_size_like.py
0 → 100644
浏览文件 @
b0ca369b
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
print_function
import
paddle
import
paddle.fluid.core
as
core
from
paddle.static
import
program_guard
,
Program
import
paddle.compat
as
cpt
import
unittest
import
numpy
as
np
from
op_test
import
OpTest
from
paddle.fluid.framework
import
convert_np_dtype_to_dtype_
paddle
.
enable_static
()
def
fill_constant_batch_size_like
(
input
,
shape
,
value
,
data_type
,
input_dim_idx
=
0
,
output_dim_idx
=
0
,
force_cpu
=
False
):
return
paddle
.
fluid
.
layers
.
fill_constant_batch_size_like
(
input
,
shape
,
data_type
,
value
,
input_dim_idx
,
output_dim_idx
,
force_cpu
)
class
TestFillConstatnBatchSizeLike1
(
OpTest
):
# test basic
def
setUp
(
self
):
self
.
op_type
=
"fill_constant_batch_size_like"
self
.
python_api
=
fill_constant_batch_size_like
self
.
init_data
()
input
=
np
.
zeros
(
self
.
shape
)
out
=
np
.
full_like
(
input
,
self
.
value
,
self
.
dtype
)
self
.
inputs
=
{
'Input'
:
input
}
self
.
outputs
=
{
'Out'
:
out
}
self
.
attrs
=
{
'shape'
:
self
.
shape
,
'dtype'
:
convert_np_dtype_to_dtype_
(
self
.
dtype
),
'value'
:
self
.
value
,
'input_dim_idx'
:
self
.
input_dim_idx
,
'output_dim_idx'
:
self
.
output_dim_idx
,
'force_cpu'
:
self
.
force_cpu
}
def
init_data
(
self
):
self
.
shape
=
[
10
,
10
]
self
.
dtype
=
np
.
float32
self
.
value
=
100
self
.
input_dim_idx
=
0
self
.
output_dim_idx
=
0
self
.
force_cpu
=
False
def
test_check_output
(
self
):
self
.
check_output
(
check_eager
=
True
)
if
__name__
==
"__main__"
:
unittest
.
main
()
python/paddle/utils/code_gen/api.yaml
浏览文件 @
b0ca369b
...
...
@@ -718,6 +718,18 @@
data_type
:
dtype
backend
:
place
-
api
:
full_batch_size_like
args
:
(Tensor input, int[] shape, DataType dtype, Scalar value, int input_dim_idx, int output_dim_idx, Place place=CPUPlace())
output
:
Tensor
infer_meta
:
func
:
FullBatchSizeLikeInferMeta
param
:
[
input
,
shape
,
value
,
dtype
,
input_dim_idx
,
output_dim_idx
]
kernel
:
func
:
full_batch_size_like
param
:
[
input
,
shape
,
value
,
dtype
,
input_dim_idx
,
output_dim_idx
]
data_type
:
dtype
backend
:
place
-
api
:
full_like
args
:
(Tensor x, Scalar value, DataType dtype = DataType::UNDEFINED, Place place = {})
output
:
Tensor
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录