Need a tool to analyze a pte file and list all required backends and ops
🚀 The feature, motivation and pitch
Do we have this kind of tool in devtools? I can't find a handy API from https://docs.pytorch.org/executorch/stable/devtools-overview.html
Alternatives
No response
Additional context
No response
RFC (Optional)
No response
Hi, I am exploring the loaded PTE program and want to extract the operator list and corresponding backends.
Currently, the Python bindings do not expose the internal operators directly.
One idea I have is to enable ETDump and perform a single forward invocation, then parse the ETDump output to obtain operator names and backends.
I wanted to check whether this approach aligns with the intended usage, or if there is a more straightforward/recommended way to access this information.
@kirklandsign I'd like to take this. I couldn't find an existing tool that does this for a .pte file: gen_oplist.py --model_file_path extracts the kernel operators for selective build but not the delegates, get_delegation_info() in devtools/backend_debug reports delegation on the lowered graph at export time rather than on a .pte, and devtools/pte_tool/diff_pte.py only compares two files.
I have a small prototype, devtools/pte_tool/inspect_pte.py, next to diff_pte.py. It reads the program flatbuffer directly, so unlike the ETDump approach suggested above (thanks @yujiaoliang :) ), it doesn't need to run the model. For each method, it lists the kernel operators the runtime needs to register and the backends it needs to link, with call counts:
$ python -m executorch.devtools.pte_tool.inspect_pte model.pte
model.pte (5,520 bytes, program version 0)
Backends: XnnpackBackend
Operators: 2
Method "forward":
Backends (1, 2 delegate calls):
XnnpackBackend x2
Operators (2, 2 kernel calls):
aten::mean.out x1
aten::topk.values x1
--json prints the same data for scripts. Ops that run inside a delegate aren't listed, since they're part of the delegate's opaque payload; only the backend ID is known. On the models I tried, the operator set matches what selective build extracts.
Does this look like what you had in mind? If so, I'll open a PR with tests. I can also adjust the name, location, or output format if needed.