Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
曾经的那一瞬间
Tensorflow
提交
9c805809
T
Tensorflow
项目概览
曾经的那一瞬间
/
Tensorflow
10 个月 前同步成功
通知
10
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Tensorflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9c805809
编写于
7月 19, 2023
作者:
J
Justin Szaday
提交者:
TensorFlower Gardener
7月 19, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use inferred vs. actual shapes for multi-device output layouts.
PiperOrigin-RevId: 549417829
上级
52f0eeac
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
37 addition
and
14 deletion
+37
-14
tensorflow/dtensor/cc/dtensor_device.cc
tensorflow/dtensor/cc/dtensor_device.cc
+6
-1
tensorflow/dtensor/cc/dtensor_device_util.cc
tensorflow/dtensor/cc/dtensor_device_util.cc
+15
-10
tensorflow/dtensor/cc/dtensor_device_util.h
tensorflow/dtensor/cc/dtensor_device_util.h
+9
-0
tensorflow/dtensor/cc/tensor_layout.cc
tensorflow/dtensor/cc/tensor_layout.cc
+6
-2
tensorflow/dtensor/cc/tensor_layout.h
tensorflow/dtensor/cc/tensor_layout.h
+1
-1
未找到文件。
tensorflow/dtensor/cc/dtensor_device.cc
浏览文件 @
9c805809
...
...
@@ -1840,6 +1840,10 @@ void DTensorDevice::ExecuteMultiDeviceOperation(
for
(
int
i
=
0
;
i
<
num_output_layouts
;
i
++
)
{
const
Layout
&
output_layout
=
function
.
output_layouts
[
i
];
const
int
num_devices
=
function
.
num_local_outputs
[
i
];
ASSIGN_OR_RETURN_C_STATUS
(
const
std
::
vector
<
int64_t
>
local_output_shape
,
GetTensorShapeAsVector
(
function
.
local_output_shapes
[
output_offset
]),
status
);
std
::
vector
<
TensorHandlePtr
>
layout_outputs
;
for
(
int
j
=
0
;
j
<
num_devices
;
j
++
)
{
const
int
output_idx
=
output_offset
+
j
;
...
...
@@ -1848,7 +1852,8 @@ void DTensorDevice::ExecuteMultiDeviceOperation(
output_offset
+=
num_devices
;
ASSIGN_OR_RETURN_C_STATUS
(
auto
local_output
,
CreateTensorWithLayout
(
std
::
move
(
layout_outputs
),
output_layout
),
CreateTensorWithLayout
(
std
::
move
(
layout_outputs
),
output_layout
,
local_output_shape
),
status
);
outputs
[
i
]
=
std
::
move
(
local_output
);
}
...
...
tensorflow/dtensor/cc/dtensor_device_util.cc
浏览文件 @
9c805809
...
...
@@ -288,21 +288,26 @@ StatusOr<Layout> GetLayoutThroughIdentityOps(Node* op, int output_index) {
char
TensorWithLayoutTf
::
ID
=
0
;
StatusOr
<
std
::
vector
<
int64_t
>>
GetTensorShapeAsVector
(
const
tensorflow
::
PartialTensorShape
&
shape
)
{
const
int
dims
=
shape
.
dims
();
if
(
dims
<
0
)
{
return
absl
::
InvalidArgumentError
(
"Unavailable tensor shape!"
);
}
std
::
vector
<
int64_t
>
result
;
result
.
reserve
(
dims
);
for
(
const
TensorShapeDim
&
dim
:
shape
)
{
result
.
emplace_back
(
dim
.
size
);
}
return
result
;
}
StatusOr
<
std
::
vector
<
int64_t
>>
GetTensorShapeAsVector
(
TFE_TensorHandle
*
tensor
)
{
tensorflow
::
PartialTensorShape
shape
;
const
Status
status
=
tensorflow
::
unwrap
(
tensor
)
->
Shape
(
&
shape
);
if
(
status
.
ok
())
{
const
int
dims
=
shape
.
dims
();
if
(
dims
<
0
)
{
return
absl
::
InvalidArgumentError
(
"Unavailable tensor shape!"
);
}
std
::
vector
<
int64_t
>
result
;
result
.
reserve
(
dims
);
for
(
const
TensorShapeDim
&
dim
:
shape
)
{
result
.
emplace_back
(
dim
.
size
);
}
return
result
;
return
GetTensorShapeAsVector
(
shape
);
}
else
{
return
status
;
}
...
...
tensorflow/dtensor/cc/dtensor_device_util.h
浏览文件 @
9c805809
...
...
@@ -431,6 +431,11 @@ std::unique_ptr<TensorWithLayoutTf> CreateDummyTensorWithLayout(
const
std
::
vector
<
int64_t
>&
local_shape
,
TF_DataType
dtype
,
const
Layout
&
layout
);
// Creates a DTensor from one or more tensor handles and a compatible
// layout. Optionally accepts a `shape` argument that overrides the
// actual shape of the underlying tensors; this argument should be
// provided when there's a possibility of the inferred shape from
// differing from the actual shape (like when it is dynamic).
StatusOr
<
std
::
unique_ptr
<
TensorWithLayoutTf
>>
CreateTensorWithLayout
(
std
::
vector
<
TensorHandlePtr
>&&
tensor
,
const
Layout
&
layout
,
std
::
optional
<
std
::
vector
<
int64_t
>>&&
shape
=
std
::
nullopt
);
...
...
@@ -568,6 +573,10 @@ class ExecutableManager : public tsl::core::WeakRefCounted {
}
stats_
;
};
// Returns the shape of a given tensor.
StatusOr
<
std
::
vector
<
int64_t
>>
GetTensorShapeAsVector
(
const
tensorflow
::
PartialTensorShape
&
shape
);
// Returns the shape of a given tensor.
StatusOr
<
std
::
vector
<
int64_t
>>
GetTensorShapeAsVector
(
TFE_TensorHandle
*
tensor
);
...
...
tensorflow/dtensor/cc/tensor_layout.cc
浏览文件 @
9c805809
...
...
@@ -170,7 +170,7 @@ bool IsDynamicSize(int64_t size) {
return
mlir
::
ShapedType
::
isDynamic
(
size
)
||
size
==
-
1
;
}
bool
IsDynamicShape
(
const
std
::
vector
<
int64_t
>&
shape
)
{
bool
IsDynamicShape
(
absl
::
Span
<
const
int64_t
>
shape
)
{
for
(
int64_t
size
:
shape
)
{
if
(
IsDynamicSize
(
size
))
return
true
;
}
...
...
@@ -1129,7 +1129,11 @@ std::vector<int64_t> Layout::GlobalShapeFromLocalShape(
absl
::
Span
<
const
int64_t
>
local_shape
,
const
std
::
vector
<
std
::
vector
<
int64_t
>>*
local_shapes
)
const
{
if
(
IsSingleDevice
()
||
IsFullyReplicated
())
{
return
std
::
vector
<
int64_t
>
(
local_shape
.
begin
(),
local_shape
.
end
());
if
(
IsDynamicShape
(
local_shape
)
&&
local_shapes
)
{
return
local_shapes
->
at
(
0
);
}
else
{
return
std
::
vector
<
int64_t
>
(
local_shape
.
begin
(),
local_shape
.
end
());
}
}
std
::
vector
<
int64_t
>
stride_for_dim
;
...
...
tensorflow/dtensor/cc/tensor_layout.h
浏览文件 @
9c805809
...
...
@@ -50,7 +50,7 @@ bool IsDynamicSize(int64_t size);
// Returns true if `shape` is a dynamic shape based on either MLIR and TF
// standards.
bool
IsDynamicShape
(
const
std
::
vector
<
int64_t
>&
shape
);
bool
IsDynamicShape
(
absl
::
Span
<
const
int64_t
>
shape
);
// The location of a device in a mesh.
//
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录