triton-model-analyzer 1.48.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. model_analyzer/__init__.py +15 -0
  2. model_analyzer/analyzer.py +448 -0
  3. model_analyzer/cli/__init__.py +15 -0
  4. model_analyzer/cli/cli.py +193 -0
  5. model_analyzer/config/__init__.py +15 -0
  6. model_analyzer/config/generate/__init__.py +15 -0
  7. model_analyzer/config/generate/automatic_model_config_generator.py +164 -0
  8. model_analyzer/config/generate/base_model_config_generator.py +352 -0
  9. model_analyzer/config/generate/brute_plus_binary_parameter_search_run_config_generator.py +164 -0
  10. model_analyzer/config/generate/brute_run_config_generator.py +154 -0
  11. model_analyzer/config/generate/concurrency_sweeper.py +75 -0
  12. model_analyzer/config/generate/config_generator_interface.py +52 -0
  13. model_analyzer/config/generate/coordinate.py +143 -0
  14. model_analyzer/config/generate/coordinate_data.py +86 -0
  15. model_analyzer/config/generate/generator_utils.py +116 -0
  16. model_analyzer/config/generate/manual_model_config_generator.py +187 -0
  17. model_analyzer/config/generate/model_config_generator_factory.py +92 -0
  18. model_analyzer/config/generate/model_profile_spec.py +74 -0
  19. model_analyzer/config/generate/model_run_config_generator.py +154 -0
  20. model_analyzer/config/generate/model_variant_name_manager.py +150 -0
  21. model_analyzer/config/generate/neighborhood.py +536 -0
  22. model_analyzer/config/generate/optuna_plus_concurrency_sweep_run_config_generator.py +141 -0
  23. model_analyzer/config/generate/optuna_run_config_generator.py +838 -0
  24. model_analyzer/config/generate/perf_analyzer_config_generator.py +312 -0
  25. model_analyzer/config/generate/quick_plus_concurrency_sweep_run_config_generator.py +130 -0
  26. model_analyzer/config/generate/quick_run_config_generator.py +753 -0
  27. model_analyzer/config/generate/run_config_generator_factory.py +329 -0
  28. model_analyzer/config/generate/search_config.py +112 -0
  29. model_analyzer/config/generate/search_dimension.py +73 -0
  30. model_analyzer/config/generate/search_dimensions.py +85 -0
  31. model_analyzer/config/generate/search_parameter.py +49 -0
  32. model_analyzer/config/generate/search_parameters.py +388 -0
  33. model_analyzer/config/input/__init__.py +15 -0
  34. model_analyzer/config/input/config_command.py +483 -0
  35. model_analyzer/config/input/config_command_profile.py +1747 -0
  36. model_analyzer/config/input/config_command_report.py +267 -0
  37. model_analyzer/config/input/config_defaults.py +236 -0
  38. model_analyzer/config/input/config_enum.py +83 -0
  39. model_analyzer/config/input/config_field.py +216 -0
  40. model_analyzer/config/input/config_list_generic.py +112 -0
  41. model_analyzer/config/input/config_list_numeric.py +151 -0
  42. model_analyzer/config/input/config_list_string.py +111 -0
  43. model_analyzer/config/input/config_none.py +71 -0
  44. model_analyzer/config/input/config_object.py +129 -0
  45. model_analyzer/config/input/config_primitive.py +81 -0
  46. model_analyzer/config/input/config_status.py +75 -0
  47. model_analyzer/config/input/config_sweep.py +83 -0
  48. model_analyzer/config/input/config_union.py +113 -0
  49. model_analyzer/config/input/config_utils.py +128 -0
  50. model_analyzer/config/input/config_value.py +243 -0
  51. model_analyzer/config/input/objects/__init__.py +15 -0
  52. model_analyzer/config/input/objects/config_model_profile_spec.py +325 -0
  53. model_analyzer/config/input/objects/config_model_report_spec.py +173 -0
  54. model_analyzer/config/input/objects/config_plot.py +198 -0
  55. model_analyzer/config/input/objects/config_protobuf_utils.py +101 -0
  56. model_analyzer/config/input/yaml_config_validator.py +82 -0
  57. model_analyzer/config/run/__init__.py +15 -0
  58. model_analyzer/config/run/model_run_config.py +313 -0
  59. model_analyzer/config/run/run_config.py +168 -0
  60. model_analyzer/constants.py +76 -0
  61. model_analyzer/device/__init__.py +15 -0
  62. model_analyzer/device/device.py +24 -0
  63. model_analyzer/device/gpu_device.py +87 -0
  64. model_analyzer/device/gpu_device_factory.py +248 -0
  65. model_analyzer/entrypoint.py +307 -0
  66. model_analyzer/log_formatter.py +65 -0
  67. model_analyzer/model_analyzer_exceptions.py +24 -0
  68. model_analyzer/model_manager.py +255 -0
  69. model_analyzer/monitor/__init__.py +15 -0
  70. model_analyzer/monitor/cpu_monitor.py +69 -0
  71. model_analyzer/monitor/dcgm/DcgmDiag.py +191 -0
  72. model_analyzer/monitor/dcgm/DcgmFieldGroup.py +83 -0
  73. model_analyzer/monitor/dcgm/DcgmGroup.py +815 -0
  74. model_analyzer/monitor/dcgm/DcgmHandle.py +141 -0
  75. model_analyzer/monitor/dcgm/DcgmJsonReader.py +69 -0
  76. model_analyzer/monitor/dcgm/DcgmReader.py +623 -0
  77. model_analyzer/monitor/dcgm/DcgmStatus.py +57 -0
  78. model_analyzer/monitor/dcgm/DcgmSystem.py +412 -0
  79. model_analyzer/monitor/dcgm/__init__.py +15 -0
  80. model_analyzer/monitor/dcgm/common/__init__.py +13 -0
  81. model_analyzer/monitor/dcgm/common/dcgm_client_cli_parser.py +194 -0
  82. model_analyzer/monitor/dcgm/common/dcgm_client_main.py +86 -0
  83. model_analyzer/monitor/dcgm/dcgm_agent.py +887 -0
  84. model_analyzer/monitor/dcgm/dcgm_collectd_plugin.py +369 -0
  85. model_analyzer/monitor/dcgm/dcgm_errors.py +395 -0
  86. model_analyzer/monitor/dcgm/dcgm_field_helpers.py +546 -0
  87. model_analyzer/monitor/dcgm/dcgm_fields.py +815 -0
  88. model_analyzer/monitor/dcgm/dcgm_fields_collectd.py +671 -0
  89. model_analyzer/monitor/dcgm/dcgm_fields_internal.py +29 -0
  90. model_analyzer/monitor/dcgm/dcgm_fluentd.py +45 -0
  91. model_analyzer/monitor/dcgm/dcgm_monitor.py +138 -0
  92. model_analyzer/monitor/dcgm/dcgm_prometheus.py +326 -0
  93. model_analyzer/monitor/dcgm/dcgm_structs.py +2357 -0
  94. model_analyzer/monitor/dcgm/dcgm_telegraf.py +65 -0
  95. model_analyzer/monitor/dcgm/dcgm_value.py +151 -0
  96. model_analyzer/monitor/dcgm/dcgmvalue.py +155 -0
  97. model_analyzer/monitor/dcgm/denylist_recommendations.py +573 -0
  98. model_analyzer/monitor/dcgm/pydcgm.py +47 -0
  99. model_analyzer/monitor/monitor.py +143 -0
  100. model_analyzer/monitor/remote_monitor.py +137 -0
  101. model_analyzer/output/__init__.py +15 -0
  102. model_analyzer/output/file_writer.py +63 -0
  103. model_analyzer/output/output_writer.py +42 -0
  104. model_analyzer/perf_analyzer/__init__.py +15 -0
  105. model_analyzer/perf_analyzer/genai_perf_config.py +206 -0
  106. model_analyzer/perf_analyzer/perf_analyzer.py +882 -0
  107. model_analyzer/perf_analyzer/perf_config.py +479 -0
  108. model_analyzer/plots/__init__.py +15 -0
  109. model_analyzer/plots/detailed_plot.py +266 -0
  110. model_analyzer/plots/plot_manager.py +224 -0
  111. model_analyzer/plots/simple_plot.py +213 -0
  112. model_analyzer/record/__init__.py +15 -0
  113. model_analyzer/record/gpu_record.py +68 -0
  114. model_analyzer/record/metrics_manager.py +887 -0
  115. model_analyzer/record/record.py +280 -0
  116. model_analyzer/record/record_aggregator.py +256 -0
  117. model_analyzer/record/types/__init__.py +15 -0
  118. model_analyzer/record/types/cpu_available_ram.py +93 -0
  119. model_analyzer/record/types/cpu_used_ram.py +93 -0
  120. model_analyzer/record/types/gpu_free_memory.py +96 -0
  121. model_analyzer/record/types/gpu_power_usage.py +107 -0
  122. model_analyzer/record/types/gpu_total_memory.py +96 -0
  123. model_analyzer/record/types/gpu_used_memory.py +96 -0
  124. model_analyzer/record/types/gpu_utilization.py +108 -0
  125. model_analyzer/record/types/inter_token_latency_avg.py +60 -0
  126. model_analyzer/record/types/inter_token_latency_base.py +74 -0
  127. model_analyzer/record/types/inter_token_latency_max.py +60 -0
  128. model_analyzer/record/types/inter_token_latency_min.py +60 -0
  129. model_analyzer/record/types/inter_token_latency_p25.py +60 -0
  130. model_analyzer/record/types/inter_token_latency_p50.py +60 -0
  131. model_analyzer/record/types/inter_token_latency_p75.py +60 -0
  132. model_analyzer/record/types/inter_token_latency_p90.py +60 -0
  133. model_analyzer/record/types/inter_token_latency_p95.py +60 -0
  134. model_analyzer/record/types/inter_token_latency_p99.py +60 -0
  135. model_analyzer/record/types/output_token_throughput.py +105 -0
  136. model_analyzer/record/types/perf_client_response_wait.py +97 -0
  137. model_analyzer/record/types/perf_client_send_recv.py +97 -0
  138. model_analyzer/record/types/perf_latency.py +111 -0
  139. model_analyzer/record/types/perf_latency_avg.py +60 -0
  140. model_analyzer/record/types/perf_latency_base.py +74 -0
  141. model_analyzer/record/types/perf_latency_p90.py +60 -0
  142. model_analyzer/record/types/perf_latency_p95.py +60 -0
  143. model_analyzer/record/types/perf_latency_p99.py +60 -0
  144. model_analyzer/record/types/perf_server_compute_infer.py +97 -0
  145. model_analyzer/record/types/perf_server_compute_input.py +97 -0
  146. model_analyzer/record/types/perf_server_compute_output.py +97 -0
  147. model_analyzer/record/types/perf_server_queue.py +97 -0
  148. model_analyzer/record/types/perf_throughput.py +105 -0
  149. model_analyzer/record/types/time_to_first_token_avg.py +60 -0
  150. model_analyzer/record/types/time_to_first_token_base.py +74 -0
  151. model_analyzer/record/types/time_to_first_token_max.py +60 -0
  152. model_analyzer/record/types/time_to_first_token_min.py +60 -0
  153. model_analyzer/record/types/time_to_first_token_p25.py +60 -0
  154. model_analyzer/record/types/time_to_first_token_p50.py +60 -0
  155. model_analyzer/record/types/time_to_first_token_p75.py +60 -0
  156. model_analyzer/record/types/time_to_first_token_p90.py +60 -0
  157. model_analyzer/record/types/time_to_first_token_p95.py +60 -0
  158. model_analyzer/record/types/time_to_first_token_p99.py +60 -0
  159. model_analyzer/reports/__init__.py +15 -0
  160. model_analyzer/reports/html_report.py +195 -0
  161. model_analyzer/reports/pdf_report.py +50 -0
  162. model_analyzer/reports/report.py +86 -0
  163. model_analyzer/reports/report_factory.py +62 -0
  164. model_analyzer/reports/report_manager.py +1376 -0
  165. model_analyzer/reports/report_utils.py +42 -0
  166. model_analyzer/result/__init__.py +15 -0
  167. model_analyzer/result/constraint_manager.py +150 -0
  168. model_analyzer/result/model_config_measurement.py +354 -0
  169. model_analyzer/result/model_constraints.py +105 -0
  170. model_analyzer/result/parameter_search.py +246 -0
  171. model_analyzer/result/result_manager.py +430 -0
  172. model_analyzer/result/result_statistics.py +159 -0
  173. model_analyzer/result/result_table.py +217 -0
  174. model_analyzer/result/result_table_manager.py +646 -0
  175. model_analyzer/result/result_utils.py +42 -0
  176. model_analyzer/result/results.py +277 -0
  177. model_analyzer/result/run_config_measurement.py +658 -0
  178. model_analyzer/result/run_config_result.py +210 -0
  179. model_analyzer/result/run_config_result_comparator.py +110 -0
  180. model_analyzer/result/sorted_results.py +151 -0
  181. model_analyzer/state/__init__.py +15 -0
  182. model_analyzer/state/analyzer_state.py +76 -0
  183. model_analyzer/state/analyzer_state_manager.py +215 -0
  184. model_analyzer/triton/__init__.py +15 -0
  185. model_analyzer/triton/client/__init__.py +15 -0
  186. model_analyzer/triton/client/client.py +234 -0
  187. model_analyzer/triton/client/client_factory.py +57 -0
  188. model_analyzer/triton/client/grpc_client.py +104 -0
  189. model_analyzer/triton/client/http_client.py +107 -0
  190. model_analyzer/triton/model/__init__.py +15 -0
  191. model_analyzer/triton/model/model_config.py +556 -0
  192. model_analyzer/triton/model/model_config_variant.py +29 -0
  193. model_analyzer/triton/server/__init__.py +15 -0
  194. model_analyzer/triton/server/server.py +76 -0
  195. model_analyzer/triton/server/server_config.py +269 -0
  196. model_analyzer/triton/server/server_docker.py +229 -0
  197. model_analyzer/triton/server/server_factory.py +306 -0
  198. model_analyzer/triton/server/server_local.py +158 -0
  199. triton_model_analyzer-1.48.0.dist-info/METADATA +52 -0
  200. triton_model_analyzer-1.48.0.dist-info/RECORD +204 -0
  201. triton_model_analyzer-1.48.0.dist-info/WHEEL +5 -0
  202. triton_model_analyzer-1.48.0.dist-info/entry_points.txt +2 -0
  203. triton_model_analyzer-1.48.0.dist-info/licenses/LICENSE +67 -0
  204. triton_model_analyzer-1.48.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,216 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ from typing import Any
18
+
19
+ from model_analyzer.constants import CONFIG_PARSER_FAILURE
20
+ from model_analyzer.model_analyzer_exceptions import TritonModelAnalyzerException
21
+
22
+
23
+ class ConfigField:
24
+ def __init__(
25
+ self,
26
+ name=None,
27
+ flags=None,
28
+ choices=None,
29
+ description=None,
30
+ default_value=None,
31
+ field_type=None,
32
+ parser_args=None,
33
+ ):
34
+ """
35
+ Create a configuration field.
36
+
37
+ Parameters
38
+ ----------
39
+ name : str
40
+ Configuration name.
41
+ flags : list
42
+ List of the flags to be used for the CLI.
43
+ choices : list or None
44
+ List of the choices to be used.
45
+ description : str
46
+ Description of the config.
47
+ default_value : object
48
+ Default value used for the config field.
49
+ field_type : ConfigValue
50
+ type of the field
51
+ parser_args : dict
52
+ Additionally arguments to be passed to ArgumentParser.
53
+ """
54
+
55
+ self._description = description
56
+ self._default_value = default_value
57
+ self._name = name
58
+ self._field_type = field_type
59
+ self._used_field_idx = 0
60
+ self._flags = flags
61
+ self._choices = choices
62
+ self._parser_args = {} if parser_args is None else parser_args
63
+ self._is_set_by_config = False
64
+
65
+ def choices(self):
66
+ """
67
+ List of choices that are allowed
68
+ """
69
+
70
+ return self._choices
71
+
72
+ def parser_args(self):
73
+ """
74
+ Get the additional arguments to be passed to ArgumentParser.
75
+
76
+ Returns
77
+ -------
78
+ dict or None
79
+ A dictionary where the keys are arguments and the values are
80
+ the argument values
81
+ """
82
+
83
+ return self._parser_args
84
+
85
+ def description(self):
86
+ """
87
+ Get the field description.
88
+
89
+ Returns
90
+ -------
91
+ str or None
92
+ Description of the config field
93
+ """
94
+
95
+ return self._description
96
+
97
+ def field_type(self):
98
+ """
99
+ Get the field type.
100
+
101
+ Returns
102
+ -------
103
+ ConfigValue
104
+ Type of the config field
105
+ """
106
+
107
+ return self._field_type
108
+
109
+ def cli_type(self):
110
+ """
111
+ Get the equivalent CLI type of the field.
112
+
113
+ Returns
114
+ -------
115
+ type
116
+ CLI type of the field.
117
+ """
118
+
119
+ return self._field_type.cli_type()
120
+
121
+ def name(self):
122
+ """
123
+ Get the name of the config field.
124
+
125
+ Returns
126
+ -------
127
+ str
128
+ Name of the config field
129
+ """
130
+
131
+ return self._name
132
+
133
+ def default_value(self):
134
+ """
135
+ Get the value for this config field.
136
+
137
+ Returns
138
+ -------
139
+ object
140
+ The default value of the config field
141
+ """
142
+
143
+ return self._default_value
144
+
145
+ def flags(self):
146
+ """
147
+ Get the CLI flags.
148
+
149
+ Returns
150
+ -------
151
+ list
152
+ A list of the CLI flags used
153
+ """
154
+
155
+ return self._flags
156
+
157
+ def set_value(self, value: Any, is_set_by_config: bool = False) -> None:
158
+ """
159
+ Set the value for the config field.
160
+ """
161
+
162
+ config_status = self._field_type.set_value(value)
163
+
164
+ if config_status.status() == CONFIG_PARSER_FAILURE:
165
+ raise TritonModelAnalyzerException(
166
+ f'Failed to set the value for field "{self._name}". Error: {config_status.message()}'
167
+ )
168
+
169
+ self._is_set_by_config = is_set_by_config
170
+
171
+ def set_default_value(self, default_value):
172
+ """
173
+ Set the default value for a config field.
174
+
175
+ Parameters
176
+ ----------
177
+ default_value : object
178
+ New default value
179
+ """
180
+
181
+ self._default_value = default_value
182
+
183
+ self._is_set_by_config = False
184
+
185
+ def value(self):
186
+ """
187
+ Get the value for the config field.
188
+
189
+ Returns
190
+ -------
191
+ object
192
+ The value of the config field.
193
+ """
194
+
195
+ return self._field_type.value()
196
+
197
+ def required(self):
198
+ """
199
+ Get the required field value
200
+
201
+ Returns
202
+ -------
203
+ bool
204
+ Whether the config field is required or not.
205
+ """
206
+
207
+ return self._field_type.required()
208
+
209
+ def set_name(self, name):
210
+ self._field_type.set_name(name)
211
+
212
+ def is_set_by_user(self) -> bool:
213
+ """
214
+ Returns true if the user set the field
215
+ """
216
+ return self._is_set_by_config
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ from copy import deepcopy
18
+
19
+ from model_analyzer.constants import CONFIG_PARSER_FAILURE, CONFIG_PARSER_SUCCESS
20
+
21
+ from .config_status import ConfigStatus
22
+ from .config_value import ConfigValue
23
+
24
+
25
+ class ConfigListGeneric(ConfigValue):
26
+ """
27
+ A generic list.
28
+ """
29
+
30
+ def __init__(
31
+ self,
32
+ type_,
33
+ preprocess=None,
34
+ required=False,
35
+ validator=None,
36
+ output_mapper=None,
37
+ name=None,
38
+ ):
39
+ """
40
+ Create a new list of numeric values.
41
+
42
+ Parameters
43
+ ----------
44
+ type_ : ConfigValue
45
+ The type of elements in the list
46
+ preprocess : callable
47
+ Function be called before setting new values.
48
+ required : bool
49
+ Whether a given config is required or not.
50
+ validator : callable or None
51
+ A validator for the final value of the field.
52
+ output_mapper: callable
53
+ This callable unifies the output value of this field.
54
+ name : str
55
+ Fully qualified name for this field.
56
+ """
57
+
58
+ # default validator
59
+ if validator is None:
60
+
61
+ def validator(x):
62
+ if type(x) is list:
63
+ return ConfigStatus(CONFIG_PARSER_SUCCESS)
64
+
65
+ return ConfigStatus(
66
+ CONFIG_PARSER_FAILURE,
67
+ f'The value for field "{self.name()}" should be a list'
68
+ " and the length must be larger than zero.",
69
+ )
70
+
71
+ super().__init__(preprocess, required, validator, output_mapper, name)
72
+
73
+ # type_ should be instance of ConfigValue
74
+ assert isinstance(type_, ConfigValue)
75
+
76
+ self._type = type_
77
+ self._cli_type = str
78
+ self._value = []
79
+
80
+ def set_value(self, value):
81
+ """
82
+ Set the value for this field.
83
+
84
+ Parameters
85
+ ----------
86
+ value : object
87
+ The value for this field.
88
+ """
89
+
90
+ type_ = self._type
91
+
92
+ new_value = []
93
+ if type(value) is list:
94
+ for item in value:
95
+ list_item = deepcopy(type_)
96
+ config_status = list_item.set_value(item)
97
+ if config_status.status() == CONFIG_PARSER_SUCCESS:
98
+ new_value.append(list_item)
99
+ else:
100
+ return config_status
101
+ else:
102
+ return ConfigStatus(
103
+ status=CONFIG_PARSER_FAILURE,
104
+ message=f'Value for field "{self.name()}" must be a list, value is "{value}".',
105
+ config_object=self,
106
+ )
107
+
108
+ return super().set_value(new_value)
109
+
110
+ def set_name(self, name):
111
+ super().set_name(name)
112
+ self._type.set_name(name)
@@ -0,0 +1,151 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ from model_analyzer.constants import CONFIG_PARSER_FAILURE, CONFIG_PARSER_SUCCESS
18
+
19
+ from .config_status import ConfigStatus
20
+ from .config_value import ConfigValue
21
+
22
+
23
+ class ConfigListNumeric(ConfigValue):
24
+ """
25
+ A list of numeric values.
26
+ """
27
+
28
+ def __init__(
29
+ self,
30
+ type_,
31
+ preprocess=None,
32
+ required=False,
33
+ validator=None,
34
+ output_mapper=None,
35
+ name=None,
36
+ ):
37
+ """
38
+ Create a new list of numeric values.
39
+
40
+ Parameters
41
+ ----------
42
+ type_ : type
43
+ The type of elements in the list
44
+ preprocess : callable
45
+ Function be called before setting new values.
46
+ required : bool
47
+ Whether a given config is required or not.
48
+ validator : callable or None
49
+ A validator for the final value of the field.
50
+ output_mapper: callable or None
51
+ This callable unifies the output value of this field.
52
+ name : str
53
+ Fully qualified name for this field.
54
+ """
55
+
56
+ # default validator
57
+ if validator is None:
58
+
59
+ def validator(x):
60
+ if type(x) is list:
61
+ return ConfigStatus(CONFIG_PARSER_SUCCESS)
62
+
63
+ return ConfigStatus(
64
+ CONFIG_PARSER_FAILURE,
65
+ f'The value for field "{self.name()}" should be a list'
66
+ " and the length must be larger than zero.",
67
+ )
68
+
69
+ super().__init__(preprocess, required, validator, output_mapper, name)
70
+ self._type = type_
71
+ self._cli_type = str
72
+ self._value = []
73
+
74
+ def _process_list(self, value):
75
+ """
76
+ A function to process the case where value is
77
+ a list.
78
+ """
79
+
80
+ type_ = self._type
81
+ new_value = []
82
+
83
+ for item in value:
84
+ item = type_(item)
85
+ new_value.append(item)
86
+
87
+ return new_value
88
+
89
+ def set_value(self, value):
90
+ """
91
+ Set the value for this field.
92
+
93
+ Parameters
94
+ ----------
95
+ value : object
96
+ The value for this field. It can be comma delimited list, or an
97
+ array, or a range
98
+ """
99
+
100
+ type_ = self._type
101
+ new_value = []
102
+
103
+ try:
104
+ if self._is_string(value):
105
+ self._value = []
106
+ value = value.split(",")
107
+
108
+ if self._is_list(value):
109
+ new_value = self._process_list(value)
110
+
111
+ elif self._is_dict(value):
112
+ two_key_condition = (
113
+ len(value) == 2 and "start" in value and "stop" in value
114
+ )
115
+ three_key_condition = (
116
+ len(value) == 3
117
+ and "start" in value
118
+ and "stop" in value
119
+ and "step" in value
120
+ )
121
+ if two_key_condition or three_key_condition:
122
+ step = 1
123
+ start = int(value["start"])
124
+ stop = int(value["stop"])
125
+ if start > stop:
126
+ return ConfigStatus(
127
+ CONFIG_PARSER_FAILURE,
128
+ f'When a dictionary is used for field "{self.name()}",'
129
+ ' "start" should be less than "stop".'
130
+ f" Current value is {value}.",
131
+ config_object=self,
132
+ )
133
+
134
+ if "step" in value:
135
+ step = int(value["step"])
136
+ new_value = list(range(start, stop + 1, step))
137
+ else:
138
+ return ConfigStatus(
139
+ CONFIG_PARSER_FAILURE,
140
+ f'If a dictionary is used for field "{self.name()}", it'
141
+ ' should only contain "start" and "stop" key with an'
142
+ f' optional "step" key. Currently, contains {list(value)}.',
143
+ config_object=self,
144
+ )
145
+ else:
146
+ new_value = [type_(value)]
147
+ except ValueError as e:
148
+ message = f'Failed to set the value for field "{self.name()}". Error: {e}.'
149
+ return ConfigStatus(CONFIG_PARSER_FAILURE, message, self)
150
+
151
+ return super().set_value(new_value)
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ from model_analyzer.constants import CONFIG_PARSER_FAILURE, CONFIG_PARSER_SUCCESS
18
+
19
+ from .config_status import ConfigStatus
20
+ from .config_value import ConfigValue
21
+
22
+
23
+ class ConfigListString(ConfigValue):
24
+ """
25
+ A list of string values.
26
+ """
27
+
28
+ def __init__(
29
+ self,
30
+ preprocess=None,
31
+ required=False,
32
+ validator=None,
33
+ output_mapper=None,
34
+ name=None,
35
+ ):
36
+ """
37
+ Instantiate a new ConfigListString
38
+
39
+ preprocess : callable
40
+ Function be called before setting new values.
41
+ required : bool
42
+ Whether a given config is required or not.
43
+ validator : callable or None
44
+ A validator for the value of the field.
45
+ output_mapper: callable or None
46
+ This callable unifies the output value of this field.
47
+ name : str
48
+ Fully qualified name for this field.
49
+ """
50
+
51
+ # default validator
52
+ if validator is None:
53
+
54
+ def validator(x):
55
+ if type(x) is list:
56
+ return ConfigStatus(CONFIG_PARSER_SUCCESS)
57
+
58
+ return ConfigStatus(
59
+ CONFIG_PARSER_FAILURE,
60
+ f'The value for field "{self.name()}" should be a list'
61
+ " and the length must be larger than zero.",
62
+ )
63
+
64
+ super().__init__(preprocess, required, validator, output_mapper, name)
65
+ self._type = self._cli_type = str
66
+ self._value = []
67
+
68
+ def set_value(self, value):
69
+ """
70
+ Set the value for this field.
71
+
72
+ Parameters
73
+ ----------
74
+ value : object
75
+ The value for this field. It can be a string of comma-delimited
76
+ items or a list.
77
+
78
+ Returns
79
+ -------
80
+ int
81
+ 1 on success, and 0 on failure
82
+ """
83
+
84
+ new_value = []
85
+ if self._is_string(value):
86
+ value = value.split(",")
87
+ for item in value:
88
+ new_value.append(self._type(item))
89
+ elif self._is_list(value):
90
+ for item in value:
91
+ if not self._is_primitive(item):
92
+ return ConfigStatus(
93
+ CONFIG_PARSER_FAILURE,
94
+ "The value for each item in the list should"
95
+ f' be a primitive value not "{item}" for field '
96
+ f'"{self.name()}".',
97
+ self,
98
+ )
99
+ new_value.append(self._type(item))
100
+ else:
101
+ if self._is_dict(value):
102
+ return ConfigStatus(
103
+ CONFIG_PARSER_FAILURE,
104
+ f'The value for field "{self.name()}" should not be'
105
+ " a dictionary, current "
106
+ f'value is "{value}".',
107
+ self,
108
+ )
109
+ new_value = [self._type(value)]
110
+
111
+ return super().set_value(new_value)
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ from model_analyzer.constants import CONFIG_PARSER_FAILURE
18
+
19
+ from .config_status import ConfigStatus
20
+ from .config_value import ConfigValue
21
+
22
+
23
+ class ConfigNone(ConfigValue):
24
+ """
25
+ A wrapper class for the primitive datatypes.
26
+ """
27
+
28
+ def __init__(
29
+ self,
30
+ preprocess=None,
31
+ required=False,
32
+ validator=None,
33
+ output_mapper=None,
34
+ name=None,
35
+ ):
36
+ """
37
+ Parameters
38
+ ----------
39
+ preprocess : callable
40
+ Function be called before setting new values.
41
+ required : bool
42
+ Whether a given config is required or not.
43
+ validator : callable or None
44
+ A validator for the value of the field.
45
+ output_mapper: callable or None
46
+ This callable unifies the output value of this field.
47
+ name : str
48
+ Fully qualified name for this field.
49
+ """
50
+
51
+ super().__init__(preprocess, required, validator, output_mapper, name)
52
+
53
+ self._type = self._cli_type = type(None)
54
+ self._value = None
55
+
56
+ def set_value(self, value):
57
+ """
58
+ Set the value for this field.
59
+
60
+ value : object
61
+ The value for this field.
62
+ """
63
+
64
+ if value is None:
65
+ return super().set_value(value)
66
+ else:
67
+ return ConfigStatus(
68
+ CONFIG_PARSER_FAILURE,
69
+ f'Value "{value}" for field "{self.name()}" should be None',
70
+ self,
71
+ )