Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
50de8a4f
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
未验证
提交
50de8a4f
编写于
7月 26, 2022
作者:
zhouweiwei2014
提交者:
GitHub
7月 26, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix behavior of device_id=None in Tensor.cuda (#44515)
* fix behavior of device_id=None in Tensor.cuda * fix CI
上级
98f8fa4c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
23 addition
and
17 deletion
+23
-17
paddle/phi/kernels/sparse/gpu/fused_attention_grad_kernel.cu
paddle/phi/kernels/sparse/gpu/fused_attention_grad_kernel.cu
+1
-1
paddle/phi/kernels/sparse/gpu/fused_attention_kernel.cu
paddle/phi/kernels/sparse/gpu/fused_attention_kernel.cu
+1
-1
python/paddle/fluid/dygraph/varbase_patch_methods.py
python/paddle/fluid/dygraph/varbase_patch_methods.py
+11
-6
python/paddle/fluid/tests/unittests/test_var_base.py
python/paddle/fluid/tests/unittests/test_var_base.py
+10
-9
未找到文件。
paddle/phi/kernels/sparse/gpu/fused_attention_grad_kernel.cu
浏览文件 @
50de8a4f
...
...
@@ -75,7 +75,7 @@ void FusedAttentionCsrGradKernel(const Context& dev_ctx,
#if CUDA_VERSION >= 11070
/* Step1: Forward: softmax{CSR} * value{Dense} -> out{Dense}, reuse */
SparseCsrTensor
dsoftmax
;
CsrDenseMatmul
GradKernel
<
T
,
Context
>
(
MatmulCsrDense
GradKernel
<
T
,
Context
>
(
dev_ctx
,
softmax
,
value
,
dout
,
&
dsoftmax
,
dvalue
);
/* Step2: Calculate grad of sdd_result, manualy not reuse */
...
...
paddle/phi/kernels/sparse/gpu/fused_attention_kernel.cu
浏览文件 @
50de8a4f
...
...
@@ -263,7 +263,7 @@ void FusedAttentionCsrKernel(
/* Step3: DSD Matmul, reuse */
softmax
->
set_dims
(
phi
::
make_ddim
({
q_dim
[
0
],
q_dim
[
1
],
q_dim
[
2
],
q_dim
[
2
]}));
CsrDenseMatmul
Kernel
<
T
,
Context
>
(
dev_ctx
,
*
softmax
,
value
,
out
);
MatmulCsrDense
Kernel
<
T
,
Context
>
(
dev_ctx
,
*
softmax
,
value
,
out
);
#else
PADDLE_THROW
(
phi
::
errors
::
Unimplemented
(
"forward of 'sparse.nn.functional.attention' "
...
...
python/paddle/fluid/dygraph/varbase_patch_methods.py
浏览文件 @
50de8a4f
...
...
@@ -866,15 +866,20 @@ def monkey_patch_varbase():
return
res
@
framework
.
dygraph_only
def
cuda
(
self
,
device_id
=
0
,
blocking
=
True
):
def
cuda
(
self
,
device_id
=
None
,
blocking
=
True
):
if
device_id
is
None
:
device_id
=
0
if
not
isinstance
(
device_id
,
int
):
raise
ValueError
(
"
\'
device_id
\'
must be a positive integer"
)
if
self
.
place
.
is_gpu_place
():
res_place
=
framework
.
_current_expected_place
()
if
not
isinstance
(
res_place
,
core
.
CUDAPlace
):
res_place
=
core
.
CUDAPlace
(
0
)
elif
isinstance
(
device_id
,
int
):
res_place
=
core
.
CUDAPlace
(
device_id
)
else
:
raise
ValueError
(
"device_id must be int|None"
)
if
self
.
place
.
_equals
(
res_place
):
return
self
else
:
res
=
self
.
_copy_to
(
core
.
CUDAPlace
(
device_id
)
,
True
)
res
=
self
.
_copy_to
(
res_place
,
True
)
res
.
stop_gradient
=
self
.
stop_gradient
res
.
persistable
=
self
.
persistable
return
res
...
...
python/paddle/fluid/tests/unittests/test_var_base.py
浏览文件 @
50de8a4f
...
...
@@ -34,7 +34,7 @@ class TestVarBase(unittest.TestCase):
def
func_test_to_tensor
(
self
):
def
_test
_place
(
place
):
def
check_with
_place
(
place
):
with
fluid
.
dygraph
.
guard
():
paddle
.
set_default_dtype
(
'float32'
)
# set_default_dtype should not take effect on int
...
...
@@ -79,6 +79,7 @@ class TestVarBase(unittest.TestCase):
y
=
x
.
pin_memory
()
self
.
assertEqual
(
y
.
place
.
__repr__
(),
"Place(gpu_pinned)"
)
y
=
x
.
cuda
()
self
.
assertEqual
(
y
.
place
.
__repr__
(),
"Place(gpu:0)"
)
y
=
x
.
cuda
(
None
)
self
.
assertEqual
(
y
.
place
.
__repr__
(),
"Place(gpu:0)"
)
y
=
x
.
cuda
(
device_id
=
0
)
...
...
@@ -266,16 +267,16 @@ class TestVarBase(unittest.TestCase):
with
self
.
assertRaises
(
ValueError
):
paddle
.
to_tensor
([[
1
],
[
2
,
3
]],
place
=
1
)
_test
_place
(
core
.
CPUPlace
())
_test
_place
(
"cpu"
)
check_with
_place
(
core
.
CPUPlace
())
check_with
_place
(
"cpu"
)
if
core
.
is_compiled_with_cuda
():
_test
_place
(
core
.
CUDAPinnedPlace
())
_test
_place
(
"gpu_pinned"
)
_test
_place
(
core
.
CUDAPlace
(
0
))
_test
_place
(
"gpu:0"
)
check_with
_place
(
core
.
CUDAPinnedPlace
())
check_with
_place
(
"gpu_pinned"
)
check_with
_place
(
core
.
CUDAPlace
(
0
))
check_with
_place
(
"gpu:0"
)
if
core
.
is_compiled_with_npu
():
_test
_place
(
core
.
NPUPlace
(
0
))
_test
_place
(
"npu:0"
)
check_with
_place
(
core
.
NPUPlace
(
0
))
check_with
_place
(
"npu:0"
)
def
test_to_tensor
(
self
):
with
_test_eager_guard
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录