Skip to content

Commit 769d641

Browse files
leafs1Gasoonjia
andauthored
Add Model Profiling Automation Script (#13493)
### Summary Added profile_model.sh to automate the ExecutorTorch model profiling workflow. The script streamlines building executor_runner with profiling enabled, running model inference with ETDump collection, and generating CSV profiling reports. It accepts model and ETDump paths as arguments with sensible defaults, consolidating what was previously a multi-step manual process into a single executable script. ### Test plan Manually ran script on llama3.pte and confirmed csv and dump generation Co-authored-by: Gasoonjia <[email protected]>
1 parent 9e8674c commit 769d641

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dist/
2020
ethos-u-scratch/
2121
executorch.egg-info
2222
pip-out/
23+
build-profiling/
2324

2425
# Any exported models and profiling outputs
2526
*.bin
@@ -60,6 +61,7 @@ xcuserdata/
6061
/share/
6162
/version.py
6263
*.csv
64+
*_etdump
6365

6466
# Android
6567
*.aar
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# Copyright 2024-25 Arm Limited and/or its affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
import argparse
9+
10+
from executorch.devtools import Inspector
11+
12+
13+
def generate_csv(etdump_path, output):
14+
"""
15+
Generate a CSV file from ETDump profiling data.
16+
17+
Args:
18+
etdump_path (str): Path to the ETDump file generated by executor_runner
19+
output (str): Path for the output CSV file
20+
"""
21+
inspector = Inspector(etdump_path)
22+
df = inspector.to_dataframe()
23+
df.to_csv(output)
24+
25+
26+
def main():
27+
"""
28+
Main function to parse command line arguments and generate profiling CSV.
29+
30+
Usage:
31+
python generate_profiling_csv.py --etdump_path="my_etdump" --output="profiling.csv"
32+
33+
Example:
34+
python generate_profiling_csv.py --etdump_path="llama3_etdump" --output="op_profiling.csv"
35+
"""
36+
parser = argparse.ArgumentParser(
37+
description="Generate profiling CSV from a model's etdump"
38+
)
39+
parser.add_argument(
40+
"--etdump_path",
41+
type=str,
42+
default="./model.etdump",
43+
help="Path to the etdump file",
44+
required=False,
45+
)
46+
47+
parser.add_argument(
48+
"--output",
49+
type=str,
50+
default="./model_profiling.csv",
51+
help="Path to the output CSV file",
52+
required=False,
53+
)
54+
55+
args = parser.parse_args()
56+
print(f"Generating CSV from {args.etdump_path}")
57+
generate_csv(args.etdump_path, args.output)
58+
print(f"Saved CSV to {args.output}")
59+
60+
61+
if __name__ == "__main__":
62+
main()

devtools/scripts/profile_model.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# Copyright 2024-25 Arm Limited and/or its affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
#!/bin/bash
9+
10+
# ExecutorTorch Model Profiling Script
11+
#
12+
# This script automates the process of building executor_runner with profiling enabled,
13+
# running model inference with ETDump collection, and generating CSV profiling reports.
14+
#
15+
# Usage:
16+
# ./devtools/scripts/profile_model.sh [model_path] [etdump_path]
17+
#
18+
# Arguments:
19+
# model_path - Path to the .pte model file (default: "my_model")
20+
# etdump_path - Path for ETDump output file (default: "path_to_et_dump")
21+
#
22+
# Examples:
23+
# ./devtools/scripts/profile_model.sh
24+
# ./devtools/scripts/profile_model.sh llama3.pte llama3_etdump
25+
#
26+
# Note: This script must be run from the top-level executorch directory.
27+
28+
set -e
29+
30+
echo "Building executor_runner with profiling enabled..."
31+
32+
cmake --preset profiling -B build-profiling -DCMAKE_BUILD_TYPE=Release
33+
cmake --build build-profiling --target executor_runner
34+
35+
echo "Build completed successfully!"
36+
37+
MODEL_PATH=${1:-"my_model"}
38+
ETDUMP_PATH=${2:-"path_to_et_dump"}
39+
40+
echo "Running and profiling model: $MODEL_PATH"
41+
echo "ETDump output path: $ETDUMP_PATH"
42+
43+
./build-profiling/executor_runner --model_path="$MODEL_PATH" --etdump_path="$ETDUMP_PATH"
44+
45+
echo "Profiling run completed!"
46+
47+
echo "Generating profiling CSV..."
48+
python devtools/scripts/generate_profiling_csv.py --etdump_path="$ETDUMP_PATH" --output="op_profiling.csv"
49+
50+
echo "Profiling CSV generated: op_profiling.csv"
51+
echo "Profiling workflow completed successfully!"

0 commit comments

Comments
 (0)