Skip to content

Commit a68cdae

Browse files
authored
Serialize PTD files with named data (#10359)
This PR was created by the merge bot to help merge the original PR into the main branch. ghstack PR number: #10327 by @lucylq ^ Please use this as the source of truth for the PR details, comments, and reviews ghstack PR base: https://github.com/pytorch/executorch/tree/gh/lucylq/62/base ghstack PR head: https://github.com/pytorch/executorch/tree/gh/lucylq/62/head Merge bot PR base: https://github.com/pytorch/executorch/tree/gh/lucylq/61/orig Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/lucylq/62/orig @diff-train-skip-merge
1 parent d33986c commit a68cdae

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

exir/_serialize/_serialize.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,34 @@ def serialize_for_executorch(
102102
)
103103

104104
for tag in all_external_tags:
105+
buffers = []
105106
fqn_to_tensor_entry: Dict[str, TensorEntry] = {}
106107
# pyre-ignore[16]: Undefined attribute: `Optional` has no attribute `get`.
107108
fqn_to_index = emitter_output.external_constant_map.get(tag, {})
108109
# Create a TensorEntry for each external tensor.
109110
for fqn, index in fqn_to_index.items():
110111
assert fqn in fqn_to_tensor_layout
111112
fqn_to_tensor_entry[fqn] = TensorEntry(
112-
buffer_index=index,
113+
buffer_index=len(buffers),
113114
layout=fqn_to_tensor_layout[fqn],
114115
)
116+
buffers.append(emitter_output.external_constant_buffer[index])
115117

116118
# Extract external data.
117119
key_to_data: Dict[str, DataEntry] = {}
118120
# pyre-ignore[16]: Undefined attribute: `Optional` has no attribute `get`.
119121
key_to_buffer_index = named_data.external_data.get(tag, {})
120122
for key, index in key_to_buffer_index.items():
121123
# pyre-ignore[16]: Undefined attribute: `Optional` has no attribute `buffers`.
122-
key_to_data[key] = DataEntry(index, named_data.buffers[index].alignment)
124+
key_to_data[key] = DataEntry(
125+
len(buffers), named_data.buffers[index].alignment
126+
)
127+
buffers.append(named_data.buffers[index].buffer)
123128

124129
# Serialize into PTD file.
125130
ptd_files[tag] = data_serializer.serialize(
126131
DataPayload(
127-
buffers=emitter_output.external_constant_buffer,
132+
buffers=buffers,
128133
fqn_to_tensor=fqn_to_tensor_entry,
129134
key_to_data=key_to_data,
130135
)

0 commit comments

Comments
 (0)