Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b6eb37f5
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看板
未验证
提交
b6eb37f5
编写于
8月 21, 2020
作者:
S
ShenLiang
提交者:
GitHub
8月 21, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add error message for cholesky (#26444)
* add error message
上级
138ecf24
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
66 addition
and
11 deletion
+66
-11
paddle/fluid/operators/cholesky_op.cu
paddle/fluid/operators/cholesky_op.cu
+14
-1
paddle/fluid/operators/cholesky_op.h
paddle/fluid/operators/cholesky_op.h
+12
-10
python/paddle/fluid/tests/unittests/test_cholesky_op.py
python/paddle/fluid/tests/unittests/test_cholesky_op.py
+40
-0
未找到文件。
paddle/fluid/operators/cholesky_op.cu
浏览文件 @
b6eb37f5
...
...
@@ -63,7 +63,6 @@ class CholeskyGPUKernel : public framework::OpKernel<T> {
for_range
(
matrix_band_part_functor
);
}
// TODO(guosheng): Add callback to check info
auto
info
=
memory
::
Alloc
(
dev_ctx
,
sizeof
(
int
)
*
batch_count
);
auto
*
info_ptr
=
reinterpret_cast
<
int
*>
(
info
->
ptr
());
...
...
@@ -96,6 +95,20 @@ class CholeskyGPUKernel : public framework::OpKernel<T> {
#if CUDA_VERSION >= 9020 && !defined(_WIN32)
}
#endif
// check the info
std
::
vector
<
int
>
error_info
;
// only for checking positive matrix
error_info
.
resize
(
batch_count
);
memory
::
Copy
(
platform
::
CPUPlace
(),
error_info
.
data
(),
BOOST_GET_CONST
(
platform
::
CUDAPlace
,
dev_ctx
.
GetPlace
()),
info_ptr
,
sizeof
(
int
)
*
batch_count
,
dev_ctx
.
stream
());
for
(
int
i
=
0
;
i
<
batch_count
;
++
i
)
{
PADDLE_ENFORCE_EQ
(
error_info
[
i
],
0
,
platform
::
errors
::
PreconditionNotMet
(
"For batch [%d]: U(%d, %d) is zero, singular U."
,
i
,
error_info
[
i
],
error_info
[
i
]));
}
}
void
Potrf
(
const
platform
::
CUDADeviceContext
&
dev_ctx
,
cublasFillMode_t
uplo
,
...
...
paddle/fluid/operators/cholesky_op.h
浏览文件 @
b6eb37f5
...
...
@@ -59,22 +59,24 @@ class CholeskyCPUKernel : public framework::OpKernel<T> {
Eigen
::
Matrix
<
T
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>
,
Eigen
::
UpLoType
::
Upper
>
llt_decomposition
(
input
);
PADDLE_ENFORCE_EQ
(
llt_decomposition
.
info
(),
Eigen
::
Success
,
PADDLE_ENFORCE_EQ
(
llt_decomposition
.
info
(),
Eigen
::
Success
,
platform
::
errors
::
InvalidArgument
(
"Cholesky decomposition was not successful. The input matrice "
"might not be not be positive definite."
));
"Cholesky decomposition was not successful. The "
"%d-th input matrice "
"might not be not be positive definite."
,
i
));
output
=
llt_decomposition
.
matrixU
();
}
else
{
Eigen
::
LLT
<
Eigen
::
Matrix
<
T
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>
,
Eigen
::
UpLoType
::
Lower
>
llt_decomposition
(
input
);
PADDLE_ENFORCE_EQ
(
llt_decomposition
.
info
(),
Eigen
::
Success
,
PADDLE_ENFORCE_EQ
(
llt_decomposition
.
info
(),
Eigen
::
Success
,
platform
::
errors
::
InvalidArgument
(
"Cholesky decomposition was not successful. The input matrice "
"might not be not be positive definite."
));
"Cholesky decomposition was not successful. The "
"%d-th input matrice "
"might not be not be positive definite."
,
i
));
output
=
llt_decomposition
.
matrixL
();
}
}
...
...
python/paddle/fluid/tests/unittests/test_cholesky_op.py
浏览文件 @
b6eb37f5
...
...
@@ -100,5 +100,45 @@ class TestDygraph(unittest.TestCase):
out
=
paddle
.
cholesky
(
x
,
upper
=
False
)
class
TestCholeskySingularAPI
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
places
=
[
fluid
.
CPUPlace
()]
if
core
.
is_compiled_with_cuda
():
self
.
places
.
append
(
fluid
.
CUDAPlace
(
0
))
def
check_static_result
(
self
,
place
,
with_out
=
False
):
with
fluid
.
program_guard
(
fluid
.
Program
(),
fluid
.
Program
()):
input
=
fluid
.
data
(
name
=
"input"
,
shape
=
[
4
,
4
],
dtype
=
"float64"
)
result
=
paddle
.
cholesky
(
input
)
input_np
=
np
.
zeros
([
4
,
4
]).
astype
(
"float64"
)
exe
=
fluid
.
Executor
(
place
)
try
:
fetches
=
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
{
"input"
:
input_np
},
fetch_list
=
[
result
])
except
fluid
.
core
.
EnforceNotMet
as
ex
:
print
(
"The mat is singular"
)
pass
def
test_static
(
self
):
for
place
in
self
.
places
:
self
.
check_static_result
(
place
=
place
)
def
test_dygraph
(
self
):
for
place
in
self
.
places
:
with
fluid
.
dygraph
.
guard
(
place
):
input_np
=
np
.
array
([[[
1
,
2
,
3
],
[
4
,
5
,
6
],
[
7
,
8
,
9
]],
[[
10
,
11
,
12
],
[
13
,
14
,
15
],
[
16
,
17
,
18
]]]).
astype
(
"float64"
)
input
=
fluid
.
dygraph
.
to_variable
(
input_np
)
try
:
result
=
paddle
.
cholesky
(
input
)
except
fluid
.
core
.
EnforceNotMet
as
ex
:
print
(
"The mat is singular"
)
pass
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录