Skip to content

Commit bf7b701

Browse files
lucylqfacebook-github-bot
authored andcommitted
Install snakeviz for cProfile flamegraph (pytorch#1915)
Summary: Pull Request resolved: pytorch#1915 fix ci test: https://github.com/pytorch/executorch/actions/runs/7848669862/job/21420323950 Reviewed By: mergennachin Differential Revision: D53620967 fbshipit-source-id: b4860566016fb05e28ec18f7aeaa751e71cec730
1 parent 28355e3 commit bf7b701

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

.ci/scripts/test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ run_portable_executor_runner() {
6060

6161
test_model() {
6262
if [[ "${MODEL_NAME}" == "llama2" ]]; then
63+
# Install requirements for export_llama
64+
bash examples/models/llama2/install_requirements.sh
6365
# Test export_llama script: python3 -m examples.models.llama2.export_llama
6466
"${PYTHON_EXECUTABLE}" -m examples.models.llama2.export_llama -c examples/models/llama2/params/demo_rand_params.pth -p examples/models/llama2/params/demo_config.json
6567
run_portable_executor_runner

examples/models/llama2/export_llama_lib.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from executorch.exir.passes.quant_fusion_pass import QuantFusionPass
2626
from executorch.exir.passes.sym_shape_eval_pass import ConstraintBasedSymShapeEvalPass
2727
from executorch.util.activation_memory_profiler import generate_memory_trace
28-
from executorch.util.python_profiler import CProfilerFlameGraph
2928
from torch._export import capture_pre_autograd_graph
3029
from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e
3130
from torch.ao.quantization.quantizer.composable_quantizer import ComposableQuantizer
@@ -266,8 +265,16 @@ def _get_quantization_options(args):
266265

267266
def export_llama(modelname, args) -> str:
268267
if args.profile_path is not None:
269-
with CProfilerFlameGraph(args.profile_path):
270-
return _export_llama(modelname, args)
268+
try:
269+
from executorch.util.python_profiler import CProfilerFlameGraph
270+
271+
with CProfilerFlameGraph(args.profile_path):
272+
return _export_llama(modelname, args)
273+
except ImportError:
274+
print(
275+
"Please run `pip install snakeviz` to install required dependencies for cProfiler flamegraph."
276+
)
277+
return ""
271278
else:
272279
return _export_llama(modelname, args)
273280

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and 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+
# Install snakeviz for cProfile flamegraph
9+
pip install snakeviz

0 commit comments

Comments
 (0)