31
31
ModelAnalysis ,
32
32
NodeInferenceResult ,
33
33
)
34
- from sparsezoo .analyze .cli import analyze_options , analyze_performance_options
34
+ from sparsezoo .analyze .cli import (
35
+ DEEPSPARSE_ENGINE ,
36
+ analyze_options ,
37
+ analyze_performance_options ,
38
+ )
35
39
36
40
37
41
_LOGGER = logging .getLogger (__name__ )
@@ -74,21 +78,11 @@ def main(
74
78
)
75
79
76
80
_LOGGER .info ("Starting Analysis ..." )
77
- analysis = ModelAnalysis .create (model_path )
78
- _LOGGER .info ("Analysis complete, collating results..." )
79
- scenario = BenchmarkScenario (
80
- batch_size = batch_size_throughput ,
81
- num_cores = None ,
82
- engine = benchmark_engine ,
83
- )
84
- performance_summary = run_benchmark_and_analysis (
85
- onnx_model = model_to_path (model_path ),
86
- scenario = scenario ,
87
- )
81
+ analysis = analyze (model_path , batch_size_throughput , benchmark_engine )
82
+
88
83
by_types : bool = convert_to_bool (by_types )
89
84
by_layers : bool = convert_to_bool (by_layers )
90
85
91
- analysis .benchmark_results = [performance_summary ]
92
86
summary = analysis .summary (
93
87
by_types = by_types ,
94
88
by_layers = by_layers ,
@@ -103,13 +97,9 @@ def main(
103
97
104
98
print ("Comparison Analysis:" )
105
99
for model_to_compare in compare :
106
- compare_model_analysis = ModelAnalysis .create (model_to_compare )
107
- _LOGGER .info (f"Running Performance Analysis on { model_to_compare } " )
108
- performance_summary = run_benchmark_and_analysis (
109
- onnx_model = model_to_path (model_to_compare ),
110
- scenario = scenario ,
100
+ compare_model_analysis = analyze (
101
+ model_to_compare , batch_size_throughput , benchmark_engine
111
102
)
112
- compare_model_analysis .benchmark_results = [performance_summary ]
113
103
summary_comparison_model = compare_model_analysis .summary (
114
104
by_types = by_types ,
115
105
by_layers = by_layers ,
@@ -124,6 +114,34 @@ def main(
124
114
analysis .yaml (file_path = save )
125
115
126
116
117
+ def analyze (
118
+ model_path ,
119
+ batch_size_throughput : int = 1 ,
120
+ benchmark_engine : str = DEEPSPARSE_ENGINE ,
121
+ ) -> ModelAnalysis :
122
+ """
123
+ :param model_path: Local filepath to an ONNX model, or a SparseZoo stub
124
+ :param batch_size_throughput: Batch size for throughput benchmark
125
+ :param benchmark_engine: Benchmark engine to use, can be 'deepsparse' or
126
+ 'onnxruntime', defaults to 'deepsparse'
127
+ :return: A `ModelAnalysis` object encapsulating the results of the analysis
128
+ """
129
+ analysis = ModelAnalysis .create (model_path )
130
+ _LOGGER .info ("Analysis complete, collating results..." )
131
+ scenario = BenchmarkScenario (
132
+ batch_size = batch_size_throughput ,
133
+ num_cores = None ,
134
+ engine = benchmark_engine ,
135
+ )
136
+ performance_summary = run_benchmark_and_analysis (
137
+ onnx_model = model_to_path (model_path ),
138
+ scenario = scenario ,
139
+ )
140
+
141
+ analysis .benchmark_results = [performance_summary ]
142
+ return analysis
143
+
144
+
127
145
def run_benchmark_and_analysis (
128
146
onnx_model : str ,
129
147
scenario : BenchmarkScenario ,
0 commit comments