Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wmsofts
Paddle
提交
d41a9373
P
Paddle
项目概览
wmsofts
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
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,发现更多精彩内容 >>
未验证
提交
d41a9373
编写于
6月 22, 2022
作者:
Z
zhangkaihuo
提交者:
GitHub
6月 22, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix batch csr (#43708)
上级
7673b39a
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
36 addition
and
46 deletion
+36
-46
paddle/phi/kernels/sparse/cpu/sparse_utils_kernel.cc
paddle/phi/kernels/sparse/cpu/sparse_utils_kernel.cc
+1
-1
paddle/phi/kernels/sparse/gpu/sparse_utils_kernel.cu
paddle/phi/kernels/sparse/gpu/sparse_utils_kernel.cu
+1
-1
python/paddle/fluid/tests/unittests/test_sparse_utils_op.py
python/paddle/fluid/tests/unittests/test_sparse_utils_op.py
+34
-44
未找到文件。
paddle/phi/kernels/sparse/cpu/sparse_utils_kernel.cc
浏览文件 @
d41a9373
...
@@ -198,7 +198,7 @@ void SparseCooToCsrCPUKernel(const CPUContext& dev_ctx,
...
@@ -198,7 +198,7 @@ void SparseCooToCsrCPUKernel(const CPUContext& dev_ctx,
const
auto
&
coo_values
=
x
.
non_zero_elements
();
const
auto
&
coo_values
=
x
.
non_zero_elements
();
const
IntT
*
batchs_ptr
=
coo_indices
.
data
<
IntT
>
();
const
IntT
*
batchs_ptr
=
coo_indices
.
data
<
IntT
>
();
const
IntT
*
coo_rows_data
=
const
IntT
*
coo_rows_data
=
batchs
==
1
?
batchs_ptr
:
batchs_ptr
+
non_zero_num
;
x_dims
.
size
()
==
2
?
batchs_ptr
:
batchs_ptr
+
non_zero_num
;
const
IntT
*
coo_cols_data
=
coo_rows_data
+
non_zero_num
;
const
IntT
*
coo_cols_data
=
coo_rows_data
+
non_zero_num
;
const
T
*
coo_values_data
=
coo_values
.
data
<
T
>
();
const
T
*
coo_values_data
=
coo_values
.
data
<
T
>
();
...
...
paddle/phi/kernels/sparse/gpu/sparse_utils_kernel.cu
浏览文件 @
d41a9373
...
@@ -371,7 +371,7 @@ void SparseCooToCsrGPUKernel(const GPUContext& dev_ctx,
...
@@ -371,7 +371,7 @@ void SparseCooToCsrGPUKernel(const GPUContext& dev_ctx,
const
auto
&
coo_values
=
x
.
non_zero_elements
();
const
auto
&
coo_values
=
x
.
non_zero_elements
();
const
IntT
*
batchs_ptr
=
coo_indices
.
data
<
IntT
>
();
const
IntT
*
batchs_ptr
=
coo_indices
.
data
<
IntT
>
();
const
IntT
*
coo_rows_data
=
const
IntT
*
coo_rows_data
=
batchs
==
1
?
batchs_ptr
:
batchs_ptr
+
non_zero_num
;
x_dims
.
size
()
==
2
?
batchs_ptr
:
batchs_ptr
+
non_zero_num
;
const
IntT
*
coo_cols_data
=
coo_rows_data
+
non_zero_num
;
const
IntT
*
coo_cols_data
=
coo_rows_data
+
non_zero_num
;
const
T
*
coo_values_data
=
coo_values
.
data
<
T
>
();
const
T
*
coo_values_data
=
coo_values
.
data
<
T
>
();
...
...
python/paddle/fluid/tests/unittests/test_sparse_utils_op.py
浏览文件 @
d41a9373
...
@@ -318,50 +318,40 @@ class TestSparseConvert(unittest.TestCase):
...
@@ -318,50 +318,40 @@ class TestSparseConvert(unittest.TestCase):
def
test_batch_csr
(
self
):
def
test_batch_csr
(
self
):
with
_test_eager_guard
():
with
_test_eager_guard
():
shape
=
[
3
,
3
,
3
]
def
verify
(
dense_x
):
def
verify
(
x
,
crows
,
cols
,
values
):
sparse_x
=
dense_x
.
to_sparse_csr
()
x
=
paddle
.
to_tensor
(
x
)
out
=
sparse_x
.
to_dense
()
csr
=
x
.
to_sparse_csr
()
assert
np
.
allclose
(
out
.
numpy
(),
dense_x
.
numpy
())
assert
np
.
allclose
(
crows
,
csr
.
crows
().
numpy
())
assert
np
.
allclose
(
cols
,
csr
.
cols
().
numpy
())
shape
=
np
.
random
.
randint
(
low
=
1
,
high
=
10
,
size
=
3
)
assert
np
.
allclose
(
values
,
csr
.
values
().
numpy
())
shape
=
list
(
shape
)
dense_x
=
paddle
.
randn
(
shape
)
dense
=
csr
.
to_dense
()
dense_x
=
paddle
.
nn
.
functional
.
dropout
(
dense_x
,
p
=
0.5
)
assert
np
.
allclose
(
x
.
numpy
(),
dense
.
numpy
())
verify
(
dense_x
)
x
=
[
#test batchs=1
[[
1.0
,
0
,
0
],
[
0
,
2.0
,
0
],
[
0
,
0
,
3.0
]],
shape
[
0
]
=
1
[[
0
,
0
,
0
],
[
0
,
0
,
0
],
[
0
,
0
,
0
]],
dense_x
=
paddle
.
randn
(
shape
)
[[
1.0
,
0
,
0
],
[
0
,
2.0
,
0
],
[
0
,
0
,
3.0
]],
dense_x
=
paddle
.
nn
.
functional
.
dropout
(
dense_x
,
p
=
0.5
)
]
verify
(
dense_x
)
crows
=
[[
0
,
1
,
2
,
3
,
0
,
0
,
0
,
0
,
0
,
1
,
2
,
3
]]
cols
=
[
0
,
1
,
2
,
0
,
1
,
2
]
shape
=
np
.
random
.
randint
(
low
=
2
,
high
=
10
,
size
=
3
)
values
=
[
1.0
,
2.0
,
3.0
,
1.0
,
2.0
,
3.0
]
shape
=
list
(
shape
)
dense_x
=
paddle
.
randn
(
shape
)
verify
(
x
,
crows
,
cols
,
values
)
#set the 0th batch to zero
dense_x
[
0
]
=
0
x
=
[
verify
(
dense_x
)
[[
0
,
0
,
0
],
[
0
,
0
,
0
],
[
0
,
0
,
0
]],
[[
1.0
,
0
,
0
],
[
0
,
2.0
,
0
],
[
0
,
0
,
3.0
]],
dense_x
=
paddle
.
randn
(
shape
)
[[
1.0
,
0
,
0
],
[
0
,
2.0
,
0
],
[
0
,
0
,
3.0
]],
#set the 1th batch to zero
]
dense_x
[
1
]
=
0
crows
=
[[
0
,
0
,
0
,
0
,
0
,
1
,
2
,
3
,
0
,
1
,
2
,
3
]]
verify
(
dense_x
)
cols
=
[
0
,
1
,
2
,
0
,
1
,
2
]
values
=
[
1.0
,
2.0
,
3.0
,
1.0
,
2.0
,
3.0
]
dense_x
=
paddle
.
randn
(
shape
)
#set the 2th batch to zero
verify
(
x
,
crows
,
cols
,
values
)
dense_x
[
2
]
=
0
verify
(
dense_x
)
x
=
[
[[
1.0
,
0
,
0
],
[
0
,
2.0
,
0
],
[
0
,
0
,
3.0
]],
[[
1.0
,
0
,
0
],
[
0
,
2.0
,
0
],
[
0
,
0
,
3.0
]],
[[
0
,
0
,
0
],
[
0
,
0
,
0
],
[
0
,
0
,
0
]],
]
crows
=
[[
0
,
1
,
2
,
3
,
0
,
1
,
2
,
3
,
0
,
0
,
0
,
0
]]
cols
=
[
0
,
1
,
2
,
0
,
1
,
2
]
values
=
[
1.0
,
2.0
,
3.0
,
1.0
,
2.0
,
3.0
]
verify
(
x
,
crows
,
cols
,
values
)
class
TestCooError
(
unittest
.
TestCase
):
class
TestCooError
(
unittest
.
TestCase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录