Skip to content

Commit 2cfad5b

Browse files
committed
[executorch][schema] Add 'EXTERNAL' to DataLocation in schema
Pull Request resolved: #7191 To indicate if a tensor is external to the PTE file or not. Currently, we can also use the existence of 'fqn' to determine if a tensor is external or not. I think it's better to have a specific location field as fqn may be required for cases besides external tensor storage. ghstack-source-id: 256953748 @exported-using-ghexport Differential Revision: [D66523171](https://our.internmc.facebook.com/intern/diff/D66523171/)
1 parent 63238ab commit 2cfad5b

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

exir/passes/replace_view_copy_with_view_pass.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def __init__(self, base: TensorSpec, shape: List[int]) -> None:
109109
"mem_obj_id",
110110
"mem_offset",
111111
"dtype", # property
112+
"extra_tensor_info", # property
112113
]
113114

114115
# Make sure _self_fields and _base_fields are disjoint

exir/schema.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ class ExtraTensorInfo:
5353
fully_qualified_name: Optional[str] = None
5454

5555

56+
class DataLocation(IntEnum):
57+
INLINE = 0
58+
SEGMENT = 1
59+
EXTERNAL = 2
60+
61+
5662
@dataclass
5763
class Tensor:
5864
scalar_type: ScalarType
@@ -223,11 +229,6 @@ class FrameList:
223229
items: List[Frame]
224230

225231

226-
class DataLocation(IntEnum):
227-
INLINE = 0
228-
SEGMENT = 1
229-
230-
231232
@dataclass
232233
class BackendDelegateDataReference:
233234
location: DataLocation

exir/tensor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import executorch.exir.schema as schema
1919
import torch
2020
from executorch.exir.error import internal_assert
21-
from executorch.exir.schema import ScalarType, TensorShapeDynamism
21+
from executorch.exir.schema import ExtraTensorInfo, ScalarType, TensorShapeDynamism
2222
from executorch.exir.sym_util import eval_shape
2323

2424

@@ -132,6 +132,7 @@ def __init__(
132132
is_sparse: bool = False,
133133
const: bool = False,
134134
requires_grad: bool = False,
135+
extra_tensor_info: Optional[ExtraTensorInfo] = None,
135136
) -> None:
136137
self.scalar_type = dtype
137138
self.const = const
@@ -146,6 +147,7 @@ def __init__(
146147
self.is_sparse = is_sparse
147148
self.init_mem_planning_fields()
148149
self.shape_dynamism: TensorShapeDynamism = determine_tensor_dynanism(self.shape)
150+
self.extra_tensor_info = extra_tensor_info
149151

150152
@property
151153
def allocated_memory(self) -> int:
@@ -346,6 +348,7 @@ def to_list(
346348
allocation_info=allocation_info,
347349
layout=layout_enum(spec.layout),
348350
shape_dynamism=spec.shape_dynamism,
351+
extra_tensor_info=spec.extra_tensor_info,
349352
)
350353
return flatbuffer_tensor
351354

schema/program.fbs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ enum TensorShapeDynamism : byte {
5353
DYNAMIC_UNBOUND = 2,
5454
}
5555

56+
// Indicates where a piece of data is stored.
57+
enum DataLocation : byte {
58+
// Stored directly in the flatbuffer.
59+
INLINE = 0,
60+
// Stored in a segment.
61+
SEGMENT = 1,
62+
// Stored outside of the flatbuffer.
63+
EXTERNAL = 2,
64+
}
5665

5766
// Table to put additional information about tensors in that is not applicable
5867
// to the vast majority of tensors in the vast majority of programs.
@@ -65,6 +74,12 @@ table ExtraTensorInfo {
6574

6675
// [Optional] The unique name of the tensor. e.g. 'mod.linear.weight'
6776
fully_qualified_name: string;
77+
78+
// [Optional] Specifies where the tensor is stored; either in a segment or external
79+
// location. If a constant tensor is stored externally, data_buffer_idx
80+
// is not relevant; use extra_tensor_info.fully_qualified_name to match up
81+
// the external tensor.
82+
location: DataLocation;
6883
}
6984

7085
table Tensor {
@@ -275,14 +290,6 @@ table FrameList {
275290
items: [Frame];
276291
}
277292

278-
// Indicates where a piece of data is stored.
279-
enum DataLocation : byte {
280-
// Stored directly in the flatbuffer.
281-
INLINE = 0,
282-
// Stored in a segment.
283-
SEGMENT = 1,
284-
}
285-
286293
// Indicates where the delegate data is stored
287294
table BackendDelegateDataReference {
288295
// Indicates which list to index into:

0 commit comments

Comments
 (0)