Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
186f5e0f
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看板
未验证
提交
186f5e0f
编写于
5月 08, 2023
作者:
J
JYChen
提交者:
GitHub
5月 08, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
hack 1-D tensor to Scalar (#53552)
上级
e9882514
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
1 deletion
+24
-1
python/paddle/distributed/auto_parallel/operators/dist_slice.py
.../paddle/distributed/auto_parallel/operators/dist_slice.py
+15
-1
python/paddle/fluid/variable_index.py
python/paddle/fluid/variable_index.py
+9
-0
未找到文件。
python/paddle/distributed/auto_parallel/operators/dist_slice.py
浏览文件 @
186f5e0f
...
...
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
paddle
from
..utils
import
compute_compatible_dim_mapping
,
is_dim_shard
from
.common
import
(
DistributedOperatorImpl
,
...
...
@@ -70,7 +72,14 @@ class DistributedSliceImpl(DistributedOperatorImpl):
if
i
not
in
decrease_axis
:
ref_indices
.
append
(
i
)
if
ref_indices
==
[]:
assert
len
(
out_dims_mapping
)
==
0
# NOTE(zoooo0820): When all axes are decreased, the output will be 1-D
# with FLAGS_set_to_1d=True.
if
paddle
.
get_flags
(
'FLAGS_set_to_1d'
)[
'FLAGS_set_to_1d'
]:
assert
len
(
out_dims_mapping
)
==
1
if
is_dim_shard
(
out_dims_mapping
[
0
]):
return
False
else
:
assert
len
(
out_dims_mapping
)
==
0
else
:
for
i
in
range
(
len
(
out_dims_mapping
)):
ref_index
=
ref_indices
[
i
]
...
...
@@ -140,6 +149,11 @@ class DistributedSliceImpl(DistributedOperatorImpl):
ref_indices
.
append
(
i
)
if
ref_dims_mapping
==
[]:
# NOTE(zoooo0820): When all axes are decreased, the output will be 1-D
# with FLAGS_set_to_1d=True.
if
paddle
.
get_flags
(
'FLAGS_set_to_1d'
)[
'FLAGS_set_to_1d'
]:
ref_dims_mapping
=
[
-
1
]
assert
ref_dims_mapping
[
0
]
==
out_dims_mapping
[
0
]
assert
len
(
ref_dims_mapping
)
==
len
(
out_dims_mapping
)
changed
=
False
else
:
...
...
python/paddle/fluid/variable_index.py
浏览文件 @
186f5e0f
...
...
@@ -284,6 +284,15 @@ def is_integer_or_scalar_tensor(ele):
if
isinstance
(
ele
,
int
):
return
True
elif
isinstance
(
ele
,
Variable
):
# NOTE(zoooo0820): For compatibility, if FLAGS_set_to_1d is set to True,
# 1-D tensor is still treated as a scalar, which means basic indexing.
# This will be removed in future.
if
paddle
.
get_flags
(
'FLAGS_set_to_1d'
)[
'FLAGS_set_to_1d'
]:
if
len
(
ele
.
shape
)
==
1
and
ele
.
shape
[
0
]
==
1
:
warnings
.
warn
(
"1-D Tensor will be treat as advanced indexing in future version. Currently, 1-D Tensor means a scalar, not vector, and please modify it to 0-D Tensor. If advanced indexing is needed, please use `export FLAGS_set_to_1d=False` to set the flag."
)
return
True
if
len
(
ele
.
shape
)
==
0
:
return
True
return
False
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录