Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
2aaed989
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
2aaed989
编写于
4月 13, 2023
作者:
C
chenxujun
提交者:
GitHub
4月 13, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add pixel_shuffle pixel_unshuffle fp16/bf16 (#52582)
上级
e64ce0bb
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
134 addition
and
7 deletion
+134
-7
paddle/phi/kernels/gpu/pixel_unshuffle_grad_kernel.cu
paddle/phi/kernels/gpu/pixel_unshuffle_grad_kernel.cu
+3
-1
paddle/phi/kernels/gpu/pixel_unshuffle_kernel.cu
paddle/phi/kernels/gpu/pixel_unshuffle_kernel.cu
+3
-1
python/paddle/fluid/tests/unittests/test_pixel_shuffle_op.py
python/paddle/fluid/tests/unittests/test_pixel_shuffle_op.py
+60
-2
python/paddle/fluid/tests/unittests/test_pixel_unshuffle.py
python/paddle/fluid/tests/unittests/test_pixel_unshuffle.py
+65
-2
python/paddle/nn/functional/vision.py
python/paddle/nn/functional/vision.py
+3
-1
未找到文件。
paddle/phi/kernels/gpu/pixel_unshuffle_grad_kernel.cu
浏览文件 @
2aaed989
...
...
@@ -23,4 +23,6 @@ PD_REGISTER_KERNEL(pixel_unshuffle_grad,
ALL_LAYOUT
,
phi
::
PixelUnshuffleGradKernel
,
float
,
double
)
{}
double
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
)
{}
paddle/phi/kernels/gpu/pixel_unshuffle_kernel.cu
浏览文件 @
2aaed989
...
...
@@ -23,4 +23,6 @@ PD_REGISTER_KERNEL(pixel_unshuffle,
ALL_LAYOUT
,
phi
::
PixelUnshuffleKernel
,
float
,
double
)
{}
double
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
)
{}
python/paddle/fluid/tests/unittests/test_pixel_shuffle_op.py
浏览文件 @
2aaed989
...
...
@@ -15,7 +15,7 @@
import
unittest
import
numpy
as
np
from
eager_op_test
import
OpTest
from
eager_op_test
import
OpTest
,
convert_float_to_uint16
import
paddle
import
paddle.nn.functional
as
F
...
...
@@ -64,6 +64,7 @@ class TestPixelShuffleOp(OpTest):
def
setUp
(
self
):
self
.
op_type
=
"pixel_shuffle"
self
.
python_api
=
paddle
.
nn
.
functional
.
pixel_shuffle
self
.
init_dtype
()
self
.
init_data_format
()
n
,
c
,
h
,
w
=
2
,
9
,
4
,
4
...
...
@@ -74,13 +75,16 @@ class TestPixelShuffleOp(OpTest):
up_factor
=
3
x
=
np
.
random
.
random
(
shape
).
astype
(
"float64"
)
x
=
np
.
random
.
random
(
shape
).
astype
(
self
.
dtype
)
npresult
=
pixel_shuffle_np
(
x
,
up_factor
,
self
.
format
)
self
.
inputs
=
{
'X'
:
x
}
self
.
outputs
=
{
'Out'
:
npresult
}
self
.
attrs
=
{
'upscale_factor'
:
up_factor
,
"data_format"
:
self
.
format
}
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float64
def
init_data_format
(
self
):
self
.
format
=
"NCHW"
...
...
@@ -99,6 +103,60 @@ class TestChannelLast(TestPixelShuffleOp):
self
.
format
=
"NHWC"
class
TestPixelShuffleFP16Op
(
TestPixelShuffleOp
):
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float16
@
unittest
.
skipIf
(
not
core
.
is_compiled_with_cuda
()
or
not
core
.
is_bfloat16_supported
(
core
.
CUDAPlace
(
0
)),
"core is not compiled with CUDA or not support bfloat16"
,
)
class
TestPixelShuffleBF16Op
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"pixel_shuffle"
self
.
python_api
=
paddle
.
nn
.
functional
.
pixel_shuffle
self
.
init_dtype
()
self
.
init_data_format
()
n
,
c
,
h
,
w
=
2
,
9
,
4
,
4
if
self
.
format
==
"NCHW"
:
shape
=
[
n
,
c
,
h
,
w
]
if
self
.
format
==
"NHWC"
:
shape
=
[
n
,
h
,
w
,
c
]
up_factor
=
3
x
=
np
.
random
.
random
(
shape
).
astype
(
self
.
np_dtype
)
npresult
=
pixel_shuffle_np
(
x
,
up_factor
,
self
.
format
)
self
.
inputs
=
{
'X'
:
x
}
self
.
outputs
=
{
'Out'
:
npresult
}
self
.
attrs
=
{
'upscale_factor'
:
up_factor
,
"data_format"
:
self
.
format
}
self
.
place
=
core
.
CUDAPlace
(
0
)
self
.
inputs
[
'X'
]
=
convert_float_to_uint16
(
self
.
inputs
[
'X'
])
self
.
outputs
[
'Out'
]
=
convert_float_to_uint16
(
self
.
outputs
[
'Out'
])
def
init_dtype
(
self
):
self
.
dtype
=
np
.
uint16
self
.
np_dtype
=
np
.
float32
def
init_data_format
(
self
):
self
.
format
=
"NCHW"
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad
(
self
):
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
,
)
class
TestPixelShuffleAPI
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
x_1_np
=
np
.
random
.
random
([
2
,
9
,
4
,
4
]).
astype
(
"float64"
)
...
...
python/paddle/fluid/tests/unittests/test_pixel_unshuffle.py
浏览文件 @
2aaed989
...
...
@@ -15,7 +15,7 @@
import
unittest
import
numpy
as
np
from
eager_op_test
import
OpTest
from
eager_op_test
import
OpTest
,
convert_float_to_uint16
import
paddle
import
paddle.nn.functional
as
F
...
...
@@ -82,6 +82,7 @@ class TestPixelUnshuffleOp(OpTest):
self
.
op_type
=
"pixel_unshuffle"
self
.
python_api
=
pixel_unshuffle_wrapper
self
.
init_dtype
()
self
.
init_data_format
()
n
,
c
,
h
,
w
=
2
,
1
,
12
,
12
...
...
@@ -92,7 +93,7 @@ class TestPixelUnshuffleOp(OpTest):
down_factor
=
3
x
=
np
.
random
.
random
(
shape
).
astype
(
"float64"
)
x
=
np
.
random
.
random
(
shape
).
astype
(
self
.
dtype
)
npresult
=
pixel_unshuffle_np
(
x
,
down_factor
,
self
.
format
)
self
.
inputs
=
{
"X"
:
x
}
...
...
@@ -102,6 +103,9 @@ class TestPixelUnshuffleOp(OpTest):
"data_format"
:
self
.
format
,
}
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float64
def
init_data_format
(
self
):
'''init_data_format'''
...
...
@@ -127,6 +131,65 @@ class TestChannelLast(TestPixelUnshuffleOp):
self
.
format
=
"NHWC"
class
TestPixelUnshuffleFP16Op
(
TestPixelUnshuffleOp
):
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float16
@
unittest
.
skipIf
(
not
core
.
is_compiled_with_cuda
()
or
not
core
.
is_bfloat16_supported
(
core
.
CUDAPlace
(
0
)),
"core is not compiled with CUDA or not support bfloat16"
,
)
class
TestPixelUnshuffleBP16Op
(
OpTest
):
'''TestPixelUnshuffleBP16Op'''
def
setUp
(
self
):
self
.
op_type
=
"pixel_unshuffle"
self
.
python_api
=
pixel_unshuffle_wrapper
self
.
init_dtype
()
self
.
init_data_format
()
n
,
c
,
h
,
w
=
2
,
1
,
12
,
12
if
self
.
format
==
"NCHW"
:
shape
=
[
n
,
c
,
h
,
w
]
if
self
.
format
==
"NHWC"
:
shape
=
[
n
,
h
,
w
,
c
]
down_factor
=
3
x
=
np
.
random
.
random
(
shape
).
astype
(
self
.
np_dtype
)
npresult
=
pixel_unshuffle_np
(
x
,
down_factor
,
self
.
format
)
self
.
inputs
=
{
"X"
:
x
}
self
.
outputs
=
{
"Out"
:
npresult
}
self
.
attrs
=
{
"downscale_factor"
:
down_factor
,
"data_format"
:
self
.
format
,
}
self
.
place
=
core
.
CUDAPlace
(
0
)
self
.
inputs
[
'X'
]
=
convert_float_to_uint16
(
self
.
inputs
[
'X'
])
self
.
outputs
[
'Out'
]
=
convert_float_to_uint16
(
self
.
outputs
[
'Out'
])
def
init_dtype
(
self
):
self
.
dtype
=
np
.
uint16
self
.
np_dtype
=
np
.
float32
def
init_data_format
(
self
):
self
.
format
=
"NCHW"
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad
(
self
):
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
,
)
class
TestPixelUnshuffleAPI
(
unittest
.
TestCase
):
'''TestPixelUnshuffleAPI'''
...
...
python/paddle/nn/functional/vision.py
浏览文件 @
2aaed989
...
...
@@ -443,7 +443,9 @@ def pixel_unshuffle(x, downscale_factor, data_format="NCHW", name=None):
)
helper
=
LayerHelper
(
"pixel_unshuffle"
,
**
locals
())
check_variable_and_dtype
(
x
,
'x'
,
[
'float32'
,
'float64'
],
'pixel_unshuffle'
)
check_variable_and_dtype
(
x
,
'x'
,
[
'float16'
,
'float32'
,
'float64'
,
'uint16'
],
'pixel_unshuffle'
)
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
x
.
dtype
)
helper
.
append_op
(
type
=
"pixel_unshuffle"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录