Skip to content

Commit be9711f

Browse files
committed
Move tensor layout into exir
TensorLayout is used by the data_serializer.py abstract class, which is part of //executorch/exir:lib https://www.internalfb.com/code/fbsource/[721dbb621c0b8c460715e5c49bc9c12757e8ccc8]/fbcode/executorch/exir/_serialize/data_serializer.py?lines=6 Shouldn't add extension/flat_tensor:flat_tensor_schema as a dependency to executorch/exir:lib. Note the C++ equivalent is in runtime/core, so I think this makes sense. Differential Revision: [D83504588](https://our.internmc.facebook.com/intern/diff/D83504588/) [ghstack-poisoned]
1 parent 049c9fc commit be9711f

File tree

9 files changed

+41
-11
lines changed

9 files changed

+41
-11
lines changed

exir/TARGETS

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ runtime.python_library(
7979
],
8080
)
8181

82+
runtime.python_library(
83+
name = "tensor_layout",
84+
srcs = [
85+
"tensor_layout.py",
86+
],
87+
deps = [
88+
":scalar_type",
89+
]
90+
)
91+
8292
runtime.python_library(
8393
name = "memory",
8494
srcs = [

exir/_serialize/TARGETS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@ runtime.python_library(
6565
deps = [
6666
"//executorch/exir:schema",
6767
"//executorch/exir:tensor",
68+
"//executorch/exir:tensor_layout",
6869
],
6970
)

exir/_serialize/_serialize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
DataEntry,
1717
DataPayload,
1818
DataSerializer,
19-
TensorLayout,
2019
)
2120

2221
from executorch.exir.capture._config import ExecutorchBackendConfig
2322
from executorch.exir.emit import EmitterOutput
2423
from executorch.exir.schema import Tensor, TensorDataLocation
24+
from executorch.exir.tensor_layout import TensorLayout
2525

2626

2727
def serialize_for_executorch(

exir/_serialize/data_serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Dict, Optional, Sequence
44

55
from executorch.exir._serialize._cord import Cord
6-
from executorch.extension.flat_tensor.serialize.flat_tensor_schema import TensorLayout
6+
from executorch.exir.tensor_layout import TensorLayout
77

88

99
@dataclass

exir/tensor_layout.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# pyre-unsafe
8+
9+
from dataclasses import dataclass
10+
from typing import List
11+
12+
from executorch.exir.scalar_type import ScalarType
13+
14+
15+
# Note: keep this in sync with the TensorLayout definition in
16+
# executorch/extension/flat_tensor/serialize/flat_tensor.fbs
17+
@dataclass
18+
class TensorLayout:
19+
scalar_type: ScalarType
20+
sizes: List[int]
21+
dim_order: List[int]

extension/flat_tensor/serialize/TARGETS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ runtime.python_library(
1313
visibility = [
1414
"//executorch/...",
1515
],
16+
deps = [
17+
"//executorch/exir:tensor_layout",
18+
]
1619
)
1720

1821
runtime.python_library(

extension/flat_tensor/serialize/flat_tensor.fbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace flat_tensor_flatbuffer;
77
file_identifier "FT01";
88
file_extension "ptd";
99

10+
// Note: keep this in sync with the python definition in
11+
// executorch/exir/tensor_layout.py
1012
table TensorLayout {
1113
scalar_type: executorch_flatbuffer.ScalarType;
1214

extension/flat_tensor/serialize/flat_tensor_schema.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,11 @@
99
from dataclasses import dataclass
1010
from typing import List, Optional
1111

12-
from executorch.exir.scalar_type import ScalarType
12+
from executorch.exir.tensor_layout import TensorLayout
1313

1414
# Note: check executorch/extension/data_format/flat_tensor.fbs for explanations of these fields.
1515

1616

17-
@dataclass
18-
class TensorLayout:
19-
scalar_type: ScalarType
20-
sizes: List[int]
21-
dim_order: List[int]
22-
23-
2417
@dataclass
2518
class DataSegment:
2619
offset: int

extension/flat_tensor/test/test_serialize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from executorch.exir._serialize.padding import aligned_size
2323

2424
from executorch.exir.schema import ScalarType
25-
from executorch.extension.flat_tensor.serialize.flat_tensor_schema import TensorLayout
25+
from executorch.exir.tensor_layout import TensorLayout
2626

2727
from executorch.extension.flat_tensor.serialize.serialize import (
2828
_deserialize_to_flat_tensor,

0 commit comments

Comments
 (0)