Open Olivia-liu opened 7 hours ago
The .pte file can have multiple segments and in them there could be multiple delegate blob segments, each represents a graph description (for the delegated subgraph) and constant tensor data. Users would be interested in knowing what’s being included in the delegate blobs. We should add hooks that delegate authors can potentially implement in order to return such information.
While exporting is in progress: The to_backend pass is where the delegate blobs are created by the partitioners. I propose adding a step in the partitioning process to construct a dict in which the delegate blob details are written to. And while exporting, we not only produce a .pte, but also a metadata.json of each delegate blob.
After exporting: If the .pte has already been created, and during to_backend no extra step was taken to get metadata.json for delegate blobs, users should still have a chance to inspect the delegate blobs. I propose for each partitioner to have a new .pte parsing function with which a metadata.json can be reverse-engineered from a delegate blob that this partitioner had created.
🚀 The feature, motivation and pitch
Problem
Currently, users who export models to ExecuTorch have no tool to inspect what contributes to the size of the resulting .pte file. This is a concern because the file must fit within the available memory on devices, which are often very limited.
Goal
Users can understand what contributes to the overall size of a PTE size using a commandline tool or python script/notebook.
RFC
Design
Overview
Have 3 entry points to inspect .pte file size:
size_distribution(exec_prog)
. Use at the end of the export script.pteinspect
, to Inspect the .pte file. Use in a terminal.size_distribution_from_pte(pte_file)
. Use in a python script or in a python notebook.In order to get detailed sizing information in the delegate blobs, allow delegates to implement hooks to decrypt the delegate blob. It’s optional for the delegate authors to implement. See the comments below for more discussion on this.
Details
Class
SizeDistribution
andsize_distribution, size_distribution_from_pte
util functionsSizeDistribution
is a recursive data class designed to hold size distribution information. It also comes withSizeDistribution.to_dataframe()
to get size distribution details in the format of a pandas dataframe.size_distribution
are convenient util functions to get aSizeDistribution
instance from anExecutorchProgramManager
instance or a .pte file.User Interface
Example output of
print(size_dists)
Print in human-readable scale units:
Example
df
when printed outImplementation
Command Line tool,
pteinspect
This is useful for users who don’t necessarily export the model themselves, and have a .pte and want to understand the size of it. Users can also call this from a bash script to do pte file analysis.
Example user flow:
where,
Alternatives Considered
Considered having an interactive commandline tool, but decided to move away from it because a commondline with arguments is more scriptable, and the style also matches more with ELF tools, which is widely used in the industry.
Also considered combining different pte tools (file inspection, file modification, etc.) into one tool. Decided to have separate tools for different features to match with ELF tools style, and also give users confidence that they wouldn’t accidentally modify the file when they only want to inspect it.
Release Plan
Milestone 1 (1 week): Define Python class and write Python APIs
Milestone 2 (1 week): Write the commandline tool