-
Notifications
You must be signed in to change notification settings - Fork 606
[executorch][flat_tensor] implement load into and dont hold onto the segment #8447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…segment 1. Implement load_into in FlatTensorDataMap 2. Do not persist 'data_ro' in the FlatTensorDataMap. From `get_data`, return the FreeableBuffer given by the data loader. TODO: add test for load_into. Differential Revision: [D69148652](https://our.internmc.facebook.com/intern/diff/D69148652/) [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/8447
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit ba31994 with merge base 75d4abc ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
…segment 1. Implement load_into in FlatTensorDataMap 2. Do not persist 'data_ro' in the FlatTensorDataMap. From `get_data`, return the FreeableBuffer given by the data loader. TODO: add test for load_into. Differential Revision: [D69148652](https://our.internmc.facebook.com/intern/diff/D69148652/) ghstack-source-id: 266205806 Pull Request resolved: #8447
This pull request was exported from Phabricator. Differential Revision: D69148652 |
For: #8393 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't have the context on flat_tensor to accept, here's some minor advice
if (!metadata_res.ok()) { | ||
return metadata_res.error(); | ||
} | ||
const auto metadata = metadata_res.get(); | ||
ET_CHECK_OR_RETURN_ERROR( | ||
metadata->segment_index() >= 0 && metadata->offset() >= 0, | ||
InvalidExternalData, | ||
"Invalid segment_index %d or offset %lu; malformed PTD file.", | ||
metadata->segment_index(), | ||
metadata->offset()) | ||
|
||
Result<const TensorLayout> tensor_layout = create_tensor_layout(metadata); | ||
if (!tensor_layout.ok()) { | ||
return tensor_layout.error(); | ||
} | ||
ET_CHECK_OR_RETURN_ERROR( | ||
size < tensor_layout.get().nbytes(), | ||
InvalidArgument, | ||
"Buffer size %zu is smaller than tensor size %zu", | ||
size, | ||
tensor_layout.get().nbytes()) | ||
|
||
const auto* s_data_segment = flat_tensor_->segments(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code is repeated and it's about 20 lines; I would extract a utility function here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
…d onto the segment" 1. Implement load_into in FlatTensorDataMap 2. Do not persist 'data_ro' in the FlatTensorDataMap. From `get_data`, return the FreeableBuffer given by the data loader. TODO: add test for load_into. Differential Revision: [D69148652](https://our.internmc.facebook.com/intern/diff/D69148652/) [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D69148652 |
…segment Pull Request resolved: #8447 1. Implement load_into in FlatTensorDataMap 2. Do not persist 'data_ro' in the FlatTensorDataMap. From `get_data`, return the FreeableBuffer given by the data loader. TODO: add test for load_into. ghstack-source-id: 267313796 Differential Revision: [D69148652](https://our.internmc.facebook.com/intern/diff/D69148652/)
…d onto the segment" 1. Implement load_into in FlatTensorDataMap 2. Do not persist 'data_ro' in the FlatTensorDataMap. From `get_data`, return the FreeableBuffer given by the data loader. TODO: add test for load_into. Differential Revision: [D69148652](https://our.internmc.facebook.com/intern/diff/D69148652/) [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D69148652 |
…segment Pull Request resolved: #8447 1. Implement load_into in FlatTensorDataMap 2. Do not persist 'data_ro' in the FlatTensorDataMap. From `get_data`, return the FreeableBuffer given by the data loader. TODO: add test for load_into. ghstack-source-id: 267448245 Differential Revision: [D69148652](https://our.internmc.facebook.com/intern/diff/D69148652/)
…d onto the segment" 1. Implement load_into in FlatTensorDataMap 2. Do not persist 'data_ro' in the FlatTensorDataMap. From `get_data`, return the FreeableBuffer given by the data loader. TODO: add test for load_into. Differential Revision: [D69148652](https://our.internmc.facebook.com/intern/diff/D69148652/) [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D69148652 |
…segment Pull Request resolved: #8447 1. Implement load_into in FlatTensorDataMap 2. Do not persist 'data_ro' in the FlatTensorDataMap. From `get_data`, return the FreeableBuffer given by the data loader. TODO: add test for load_into. ghstack-source-id: 267467148 Differential Revision: [D69148652](https://our.internmc.facebook.com/intern/diff/D69148652/)
99dfe7e
into
gh/lucylq/41/base
…segment (#8650) * [flat_tensor] Persist FreeableBuffers of external constants in method Pull Request resolved: #8437 ## Problem Currently, the FlatTensorDataMap persists tensors, and returns a FreeableBuffer with an empty free function. The NamedDataMap should not persist data, as most cases (eg. delegate) will want it to be freed. Ownership should be on the caller; `get_data` returns a FreeableBuffer that 'owns' the data. The FreeableBuffer in turn is owned by the caller. NOTE: this doesn't support the case where we want to share plain tensors between methods/pte files at runtime. A custom NDM could support that use-case. ## This diff: 1. Introduces a 'NamedData' struct to method.h. This holds a key and a FreeeableBuffer. 2. Iterate over all the flatbuffer tensors to count the constants tagged with EXTERNAL. NOTE: this will increase load time for all users. Potentially allocate chunks of 16 and use a linked list to store external constants, or store this number in PTE file (see D69618283). 3. Allocate space for num_external_constants using the method allocator. 4. Iterate over all flatbuffer tensors and use the named_data_map to resolve EXTERNAL tensors into the array of NamedData. 5. Pass the resolved external constants to tensor_parser, along with NDM (used for mutable external tensors). 6. Resolved external tensors are stored inside method. They are freed when the method is destructed. Some notes: https://docs.google.com/document/d/1_PBi4JgODuClUPD4PCUWrKNjyUH54zOUHGUJ3QHDNes/edit?tab=t.0#heading=h.blsvwraxss7g ghstack-source-id: 267364187 TODO: add test case when two fqns point to the same data buffer. Differential Revision: [D69477027](https://our.internmc.facebook.com/intern/diff/D69477027/) * [executorch][flat_tensor] implement load into and dont hold onto the segment Pull Request resolved: #8447 1. Implement load_into in FlatTensorDataMap 2. Do not persist 'data_ro' in the FlatTensorDataMap. From `get_data`, return the FreeableBuffer given by the data loader. TODO: add test for load_into. ghstack-source-id: 267467148 Differential Revision: [D69148652](https://our.internmc.facebook.com/intern/diff/D69148652/) --------- Co-authored-by: lucylq <lfq@meta.com>
Stack from ghstack (oldest at bottom):
get_data
, return the FreeableBuffer given by the data loader.TODO: add test for load_into.
Differential Revision: D69148652