Skip to content

Commit 40dd643

Browse files
committed
fix(profile): generate plots using run-scoped PA config to preserve single-run behavior
- Cache objectives, GenAIPerfConfig, and PerfAnalyzerConfig in Profile.__init__ to keep a consistent run context across profiling and plotting - Update profile() to reuse cached configs instead of reconstructing them - Use PerfAnalyzerConfig.get_artifact_directory() and get_profile_export_file() in create_plots() to avoid global output paths that caused repeated handling across runs - Improves determinism and prevents unintended multi-run plot generation - Refs TMA-1911 Signed-off-by: Rythsman <[email protected]>
1 parent 681dfa1 commit 40dd643

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

genai-perf/genai_perf/subcommand/profile.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,44 +58,41 @@ class Profile(Subcommand):
5858

5959
def __init__(self, config: ConfigCommand, extra_args: Optional[List[str]]) -> None:
6060
super().__init__(config, extra_args)
61+
self._objectives = self._create_objectives_based_on_stimulus()
62+
self._genai_perf_config = self._create_genai_perf_config(self._objectives)
63+
self._perf_analyzer_config = self._create_perf_analyzer_config(self._objectives)
6164

6265
def profile(self) -> None:
6366
"""
6467
Profiles the model based on the user's stimulus
6568
"""
66-
objectives = self._create_objectives_based_on_stimulus()
67-
genai_perf_config = self._create_genai_perf_config(objectives)
68-
perf_analyzer_config = self._create_perf_analyzer_config(objectives)
6969

70-
if self._is_config_present_in_results(genai_perf_config, perf_analyzer_config):
70+
if self._is_config_present_in_results(self._genai_perf_config, self._perf_analyzer_config):
7171
self._found_config_in_checkpoint(
72-
genai_perf_config, perf_analyzer_config, objectives
72+
self._genai_perf_config, self._perf_analyzer_config, self._objectives
7373
)
7474
else:
7575
# Pre-amble
7676
self._create_tokenizer()
77-
self._create_artifact_directory(perf_analyzer_config)
78-
self._create_plot_directory(perf_analyzer_config)
79-
self._generate_inputs(perf_analyzer_config)
77+
self._create_artifact_directory(self._perf_analyzer_config)
78+
self._create_plot_directory(self._perf_analyzer_config)
79+
self._generate_inputs(self._perf_analyzer_config)
8080

8181
# Profile using Perf Analyzer
82-
self._run_perf_analyzer(perf_analyzer_config)
82+
self._run_perf_analyzer(self._perf_analyzer_config)
8383

8484
# Post-amble
85-
self._set_data_parser(perf_analyzer_config)
85+
self._set_data_parser(self._perf_analyzer_config)
8686
self._add_results_to_checkpoint(
87-
genai_perf_config, perf_analyzer_config, objectives
87+
self._genai_perf_config, self._perf_analyzer_config, self._objectives
8888
)
89-
self._add_output_to_artifact_directory(perf_analyzer_config, objectives)
89+
self._add_output_to_artifact_directory(self._perf_analyzer_config, self._objectives)
9090

9191
def create_plots(self) -> None:
9292
# TMA-1911: support plots CLI option
93-
# Create the same config objects as in profile() to get consistent paths
94-
objectives = self._create_objectives_based_on_stimulus()
95-
perf_analyzer_config = self._create_perf_analyzer_config(objectives)
96-
plot_dir = perf_analyzer_config.get_artifact_directory() / "plots"
93+
plot_dir = self._perf_analyzer_config.get_artifact_directory() / "plots"
9794
PlotConfigParser.create_init_yaml_config(
98-
filenames=[perf_analyzer_config.get_profile_export_file()],
95+
filenames=[self._perf_analyzer_config.get_profile_export_file()], # single run
9996
output_dir=plot_dir,
10097
)
10198
config_parser = PlotConfigParser(plot_dir / "config.yaml")

0 commit comments

Comments
 (0)