Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
01888482
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看板
未验证
提交
01888482
编写于
9月 13, 2022
作者:
J
JingZhuangzhuang
提交者:
GitHub
9月 13, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add softmax infer kernel (#45955)
* add softmax infer kernel
上级
945b286b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
88 addition
and
25 deletion
+88
-25
paddle/fluid/framework/ir/is_test_pass.cc
paddle/fluid/framework/ir/is_test_pass.cc
+12
-11
paddle/phi/kernels/cpu/gumbel_softmax_kernel.cc
paddle/phi/kernels/cpu/gumbel_softmax_kernel.cc
+7
-0
paddle/phi/kernels/gpu/gumbel_softmax_kernel.cu
paddle/phi/kernels/gpu/gumbel_softmax_kernel.cu
+7
-0
paddle/phi/kernels/gumbel_softmax_kernel.h
paddle/phi/kernels/gumbel_softmax_kernel.h
+8
-0
paddle/phi/kernels/impl/gumbel_softmax_kernel_impl.h
paddle/phi/kernels/impl/gumbel_softmax_kernel_impl.h
+36
-14
paddle/phi/ops/compat/gumbel_softmax_sig.cc
paddle/phi/ops/compat/gumbel_softmax_sig.cc
+18
-0
未找到文件。
paddle/fluid/framework/ir/is_test_pass.cc
浏览文件 @
01888482
...
...
@@ -25,17 +25,18 @@ class Graph;
void
IsTestPass
::
ApplyImpl
(
ir
::
Graph
*
graph
)
const
{
VLOG
(
3
)
<<
"Sets is_test attrbiute to true and if it is missing, inserts it "
"for activations and pooling."
;
auto
op_list
=
{
"pool2d"
,
"sigmoid"
,
"logsigmoid"
,
"softshrink"
,
"exp"
,
"brelu"
,
"pow"
,
"leaky_relu"
,
"stanh"
,
"relu"
,
"tanh"
,
"tanh_shrink"
,
"sqrt"
,
"abs"
,
"ceil"
,
"elu"
,
"floor"
,
"cos"
,
"sin"
,
"round"
,
"reciprocal"
,
"hard_shrink"
,
"hard_sigmoid"
,
"relu6"
,
"soft_relu"
,
"swish"
,
"thresholded_relu"
,
"log"
,
"square"
,
"softplus"
,
"softsign"
,
"silu"
,
"mish"
};
auto
op_list
=
{
"pool2d"
,
"sigmoid"
,
"logsigmoid"
,
"softshrink"
,
"exp"
,
"brelu"
,
"pow"
,
"leaky_relu"
,
"stanh"
,
"relu"
,
"tanh"
,
"tanh_shrink"
,
"sqrt"
,
"abs"
,
"ceil"
,
"elu"
,
"floor"
,
"cos"
,
"sin"
,
"round"
,
"reciprocal"
,
"hard_shrink"
,
"hard_sigmoid"
,
"relu6"
,
"soft_relu"
,
"swish"
,
"thresholded_relu"
,
"log"
,
"square"
,
"softplus"
,
"softsign"
,
"silu"
,
"mish"
,
"gumbel_softmax"
};
for
(
const
Node
*
n
:
graph
->
Nodes
())
{
if
(
n
->
IsOp
())
{
auto
*
op
=
n
->
Op
();
...
...
paddle/phi/kernels/cpu/gumbel_softmax_kernel.cc
浏览文件 @
01888482
...
...
@@ -119,3 +119,10 @@ struct OneHotGenerator<CPUContext, T> {
PD_REGISTER_KERNEL
(
gumbel_softmax
,
CPU
,
ALL_LAYOUT
,
phi
::
GumbelSoftmaxKernel
,
float
,
double
)
{}
PD_REGISTER_KERNEL
(
gumbel_softmax_infer
,
CPU
,
ALL_LAYOUT
,
phi
::
GumbelSoftmaxInferKernel
,
float
,
double
)
{}
paddle/phi/kernels/gpu/gumbel_softmax_kernel.cu
浏览文件 @
01888482
...
...
@@ -170,3 +170,10 @@ struct GumbleNoiseGenerator<GPUContext, T> {
PD_REGISTER_KERNEL
(
gumbel_softmax
,
GPU
,
ALL_LAYOUT
,
phi
::
GumbelSoftmaxKernel
,
float
,
double
)
{}
PD_REGISTER_KERNEL
(
gumbel_softmax_infer
,
GPU
,
ALL_LAYOUT
,
phi
::
GumbelSoftmaxInferKernel
,
float
,
double
)
{}
paddle/phi/kernels/gumbel_softmax_kernel.h
浏览文件 @
01888482
...
...
@@ -25,4 +25,12 @@ void GumbelSoftmaxKernel(const Context& dev_ctx,
int
axis
,
DenseTensor
*
out
);
template
<
typename
T
,
typename
Context
>
void
GumbelSoftmaxInferKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
float
temperature
,
bool
hard
,
int
axis
,
DenseTensor
*
out
);
}
// namespace phi
paddle/phi/kernels/impl/gumbel_softmax_kernel_impl.h
浏览文件 @
01888482
...
...
@@ -43,12 +43,13 @@ template <typename Context, typename T>
struct
OneHotGenerator
;
template
<
typename
T
,
typename
Context
>
void
GumbelSoftmaxKernel
(
const
Context
&
ctx
,
const
DenseTensor
&
x
,
float
temperature
,
bool
hard
,
int
axis
,
DenseTensor
*
out
)
{
void
GumbelSoftmaxKernelHelper
(
const
Context
&
ctx
,
const
DenseTensor
&
x
,
float
temperature
,
bool
hard
,
int
axis
,
DenseTensor
*
out
,
bool
is_test
)
{
const
int
rank
=
x
.
dims
().
size
();
axis
=
funcs
::
CanonicalAxis
(
axis
,
rank
);
int
axis_dim
=
x
.
dims
()[
axis
];
...
...
@@ -80,18 +81,39 @@ void GumbelSoftmaxKernel(const Context& ctx,
size_to_axis
,
size_from_axis
,
temperature
);
#ifdef PADDLE_ON_INFERENCE
paddle
::
operators
::
math
::
SoftmaxFunctor
<
Context
,
T
,
true
>
()(
ctx
,
axis_dim
,
&
x_noise_2d
,
&
out_2d
);
#else
paddle
::
operators
::
math
::
SoftmaxFunctor
<
Context
,
T
,
false
>
()(
ctx
,
axis_dim
,
&
x_noise_2d
,
&
out_2d
);
#endif
if
(
is_test
)
{
paddle
::
operators
::
math
::
SoftmaxFunctor
<
Context
,
T
,
true
>
()(
ctx
,
axis_dim
,
&
x_noise_2d
,
&
out_2d
);
}
else
{
paddle
::
operators
::
math
::
SoftmaxFunctor
<
Context
,
T
,
false
>
()(
ctx
,
axis_dim
,
&
x_noise_2d
,
&
out_2d
);
}
if
(
hard
)
{
OneHotGenerator
<
Context
,
T
>::
Transform
(
ctx
,
x
,
out
,
axis
);
}
}
template
<
typename
T
,
typename
Context
>
void
GumbelSoftmaxKernel
(
const
Context
&
ctx
,
const
DenseTensor
&
x
,
float
temperature
,
bool
hard
,
int
axis
,
DenseTensor
*
out
)
{
GumbelSoftmaxKernelHelper
<
T
,
Context
>
(
ctx
,
x
,
temperature
,
hard
,
axis
,
out
,
false
);
}
template
<
typename
T
,
typename
Context
>
void
GumbelSoftmaxInferKernel
(
const
Context
&
ctx
,
const
DenseTensor
&
x
,
float
temperature
,
bool
hard
,
int
axis
,
DenseTensor
*
out
)
{
GumbelSoftmaxKernelHelper
<
T
,
Context
>
(
ctx
,
x
,
temperature
,
hard
,
axis
,
out
,
true
);
}
}
// namespace phi
paddle/phi/ops/compat/gumbel_softmax_sig.cc
浏览文件 @
01888482
...
...
@@ -16,6 +16,23 @@ limitations under the License. */
namespace
phi
{
KernelSignature
GumbelSoftmaxOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
bool
is_test
=
false
;
if
(
ctx
.
HasAttr
(
"is_test"
))
{
is_test
=
paddle
::
any_cast
<
bool
>
(
ctx
.
Attr
(
"is_test"
));
}
if
(
is_test
)
{
return
KernelSignature
(
"gumbel_softmax_infer"
,
{
"X"
},
{
"temperature"
,
"hard"
,
"axis"
},
{
"Out"
});
}
else
{
return
KernelSignature
(
"gumbel_softmax"
,
{
"X"
},
{
"temperature"
,
"hard"
,
"axis"
},
{
"Out"
});
}
}
KernelSignature
GumbelSoftmaxGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
...
...
@@ -24,5 +41,6 @@ KernelSignature GumbelSoftmaxGradOpArgumentMapping(
}
// namespace phi
PD_REGISTER_ARG_MAPPING_FN
(
gumbel_softmax
,
phi
::
GumbelSoftmaxOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
gumbel_softmax_grad
,
phi
::
GumbelSoftmaxGradOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录