Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
d41a9373
P
Paddle
项目概览
机器未来
/
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看板
未验证
提交
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,
const
auto
&
coo_values
=
x
.
non_zero_elements
();
const
IntT
*
batchs_ptr
=
coo_indices
.
data
<
IntT
>
();
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
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,
const
auto
&
coo_values
=
x
.
non_zero_elements
();
const
IntT
*
batchs_ptr
=
coo_indices
.
data
<
IntT
>
();
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
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):
def
test_batch_csr
(
self
):
with
_test_eager_guard
():
shape
=
[
3
,
3
,
3
]
def
verify
(
x
,
crows
,
cols
,
values
):
x
=
paddle
.
to_tensor
(
x
)
csr
=
x
.
to_sparse_csr
()
assert
np
.
allclose
(
crows
,
csr
.
crows
().
numpy
())
assert
np
.
allclose
(
cols
,
csr
.
cols
().
numpy
())
assert
np
.
allclose
(
values
,
csr
.
values
().
numpy
())
dense
=
csr
.
to_dense
()
assert
np
.
allclose
(
x
.
numpy
(),
dense
.
numpy
())
x
=
[
[[
1.0
,
0
,
0
],
[
0
,
2.0
,
0
],
[
0
,
0
,
3.0
]],
[[
0
,
0
,
0
],
[
0
,
0
,
0
],
[
0
,
0
,
0
]],
[[
1.0
,
0
,
0
],
[
0
,
2.0
,
0
],
[
0
,
0
,
3.0
]],
]
crows
=
[[
0
,
1
,
2
,
3
,
0
,
0
,
0
,
0
,
0
,
1
,
2
,
3
]]
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
)
x
=
[
[[
0
,
0
,
0
],
[
0
,
0
,
0
],
[
0
,
0
,
0
]],
[[
1.0
,
0
,
0
],
[
0
,
2.0
,
0
],
[
0
,
0
,
3.0
]],
[[
1.0
,
0
,
0
],
[
0
,
2.0
,
0
],
[
0
,
0
,
3.0
]],
]
crows
=
[[
0
,
0
,
0
,
0
,
0
,
1
,
2
,
3
,
0
,
1
,
2
,
3
]]
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
)
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
)
def
verify
(
dense_x
):
sparse_x
=
dense_x
.
to_sparse_csr
()
out
=
sparse_x
.
to_dense
()
assert
np
.
allclose
(
out
.
numpy
(),
dense_x
.
numpy
())
shape
=
np
.
random
.
randint
(
low
=
1
,
high
=
10
,
size
=
3
)
shape
=
list
(
shape
)
dense_x
=
paddle
.
randn
(
shape
)
dense_x
=
paddle
.
nn
.
functional
.
dropout
(
dense_x
,
p
=
0.5
)
verify
(
dense_x
)
#test batchs=1
shape
[
0
]
=
1
dense_x
=
paddle
.
randn
(
shape
)
dense_x
=
paddle
.
nn
.
functional
.
dropout
(
dense_x
,
p
=
0.5
)
verify
(
dense_x
)
shape
=
np
.
random
.
randint
(
low
=
2
,
high
=
10
,
size
=
3
)
shape
=
list
(
shape
)
dense_x
=
paddle
.
randn
(
shape
)
#set the 0th batch to zero
dense_x
[
0
]
=
0
verify
(
dense_x
)
dense_x
=
paddle
.
randn
(
shape
)
#set the 1th batch to zero
dense_x
[
1
]
=
0
verify
(
dense_x
)
dense_x
=
paddle
.
randn
(
shape
)
#set the 2th batch to zero
dense_x
[
2
]
=
0
verify
(
dense_x
)
class
TestCooError
(
unittest
.
TestCase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录