Skip to content

Commit ffdf36f

Browse files
committed
Update on "[ExecuTorch][Weight Sharing][XNNPACK] Serialize constant tensors into named data map"
We serialize tensors into the named data map, and return the output in preprocess result. Allowing for XNNPACK to share tensors with the same name (instead of duplicating). A key change here is with fused tensors. For BN and Convolution Fusion, we fuse the conv weights and bias with the BN parameters creating new tensors. We then create get_attr nodes for these new parameters. Due to the graph.fx interpreter in export pass base, the new names we create for these new tensors are lost each time. As a result, at the end we introduce a new pass to preserve the names we created. This seems a little hacky for now, but is the only way to preserve the new fused names. Differential Revision: [D70315207](https://our.internmc.facebook.com/intern/diff/D70315207/) **NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D70315207/)! [ghstack-poisoned]
2 parents e8db57d + a02a65f commit ffdf36f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

backends/xnnpack/runtime/XNNCompiler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,12 @@ const uint8_t* getConstantDataPtr(
179179
ConstantDataOffsetPtr constant_data_offset = flatbuffer_graph->constant_data()->Get(buffer_idx);
180180
uint64_t offset = constant_data_offset->offset();
181181

182-
const std::string &data_name = constant_data_offset->named_key()->str();
182+
bool has_named_key = flatbuffers::IsFieldPresent(constant_data_offset, fb_xnnpack::ConstantDataOffset::VT_NAMED_KEY);
183183
// If there is no tensor name
184-
if (data_name.length() == 0) {
184+
if (!has_named_key) {
185185
return constant_data_ptr + offset;
186186
} else {
187+
const std::string &data_name = constant_data_offset->named_key()->str();
187188
Result<FreeableBuffer> buffer = named_data_map->get_data(data_name.c_str());
188189
if (!buffer.ok()) {
189190
ET_LOG(Error, "Failed to get constant data for key %s", data_name.c_str());

0 commit comments

Comments
 (0)