1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ from model_analyzer .config .input .config_utils \
16+ import binary_path_validator , objective_list_output_mapper , file_path_validator , parent_path_validator
1517from .config_field import ConfigField
1618from .config_primitive import ConfigPrimitive
1719from .config_list_string import ConfigListString
5456from google .protobuf .descriptor import FieldDescriptor
5557
5658import numba
59+ from numba import cuda
5760import psutil
5861import logging
5962
@@ -64,6 +67,7 @@ class ConfigCommandProfile(ConfigCommand):
6467 """
6568 Model Analyzer config object.
6669 """
70+
6771 def _resolve_protobuf_field (self , field ):
6872 """
6973 Recursively resolve protobuf fields.
@@ -162,7 +166,8 @@ def _fill_config(self):
162166 'checkpoint_directory' ,
163167 flags = ['--checkpoint-directory' , '-s' ],
164168 default_value = DEFAULT_CHECKPOINT_DIRECTORY ,
165- field_type = ConfigPrimitive (str ),
169+ field_type = ConfigPrimitive (str ,
170+ validator = parent_path_validator ),
166171 description =
167172 "Full path to directory to which to read and write checkpoints and profile data."
168173 ))
@@ -198,8 +203,7 @@ def _fill_config(self):
198203 field_type = ConfigPrimitive (bool ),
199204 flags = ['--collect-cpu-metrics' ],
200205 default_value = DEFAULT_COLLECT_CPU_METRICS ,
201- description = 'Specify whether CPU metrics are collected or not' )
202- )
206+ description = 'Specify whether CPU metrics are collected or not' ))
203207 self ._add_config (
204208 ConfigField (
205209 'gpus' ,
@@ -223,16 +227,16 @@ def _add_repository_configs(self):
223227 self ._add_config (
224228 ConfigField ('model_repository' ,
225229 flags = ['--model-repository' , '-m' ],
226- field_type = ConfigPrimitive (str , required = True ),
230+ field_type = ConfigPrimitive (
231+ str , required = True , validator = file_path_validator ),
227232 description = 'Model repository location' ))
228233 self ._add_config (
229234 ConfigField (
230235 'output_model_repository_path' ,
231236 field_type = ConfigPrimitive (str ),
232237 default_value = DEFAULT_OUTPUT_MODEL_REPOSITORY ,
233238 flags = ['--output-model-repository-path' ],
234- description =
235- 'Output model repository path used by Model Analyzer.'
239+ description = 'Output model repository path used by Model Analyzer.'
236240 ' This is the directory that will contain all the generated model configurations'
237241 ))
238242 self ._add_config (
@@ -251,12 +255,10 @@ def _add_profile_models_configs(self):
251255 Adds configs specific to model specifications
252256 """
253257 triton_server_flags_scheme = ConfigObject (schema = {
254- k : ConfigPrimitive (str )
255- for k in TritonServerConfig .allowed_keys ()
258+ k : ConfigPrimitive (str ) for k in TritonServerConfig .allowed_keys ()
256259 })
257260 perf_analyzer_additive_keys = {
258- k : None
259- for k in PerfAnalyzerConfig .additive_keys ()
261+ k : None for k in PerfAnalyzerConfig .additive_keys ()
260262 }
261263 perf_analyzer_flags_scheme = ConfigObject (
262264 schema = {
@@ -291,16 +293,6 @@ def _add_profile_models_configs(self):
291293 'Allows setting environment variables for tritonserver server instances launched by Model Analyzer'
292294 ))
293295
294- def objective_list_output_mapper (objectives ):
295- # Takes a list of objectives and maps them
296- # into a dict
297- output_dict = {}
298- for objective in objectives :
299- value = ConfigPrimitive (type_ = int )
300- value .set_value (10 )
301- output_dict [objective ] = value
302- return output_dict
303-
304296 objectives_scheme = ConfigUnion ([
305297 ConfigObject (
306298 schema = {
@@ -312,33 +304,33 @@ def objective_list_output_mapper(objectives):
312304 constraints_scheme = ConfigObject (
313305 schema = {
314306 'perf_throughput' :
315- ConfigObject (schema = {
316- 'min' : ConfigPrimitive (int ),
317- }),
307+ ConfigObject (schema = {
308+ 'min' : ConfigPrimitive (int ),
309+ }),
318310 'perf_latency_avg' :
319- ConfigObject (schema = {
320- 'max' : ConfigPrimitive (int ),
321- }),
311+ ConfigObject (schema = {
312+ 'max' : ConfigPrimitive (int ),
313+ }),
322314 'perf_latency_p90' :
323- ConfigObject (schema = {
324- 'max' : ConfigPrimitive (int ),
325- }),
315+ ConfigObject (schema = {
316+ 'max' : ConfigPrimitive (int ),
317+ }),
326318 'perf_latency_p95' :
327- ConfigObject (schema = {
328- 'max' : ConfigPrimitive (int ),
329- }),
319+ ConfigObject (schema = {
320+ 'max' : ConfigPrimitive (int ),
321+ }),
330322 'perf_latency_p99' :
331- ConfigObject (schema = {
332- 'max' : ConfigPrimitive (int ),
333- }),
323+ ConfigObject (schema = {
324+ 'max' : ConfigPrimitive (int ),
325+ }),
334326 'perf_latency' :
335- ConfigObject (schema = {
336- 'max' : ConfigPrimitive (int ),
337- }),
327+ ConfigObject (schema = {
328+ 'max' : ConfigPrimitive (int ),
329+ }),
338330 'gpu_used_memory' :
339- ConfigObject (schema = {
340- 'max' : ConfigPrimitive (int ),
341- }),
331+ ConfigObject (schema = {
332+ 'max' : ConfigPrimitive (int ),
333+ }),
342334 })
343335 self ._add_config (
344336 ConfigField (
@@ -362,29 +354,31 @@ def objective_list_output_mapper(objectives):
362354 # Any key is allowed, but the keys must follow the pattern
363355 # below
364356 '*' :
365- ConfigObject (
366- schema = {
367- 'cpu_only' :
368- ConfigPrimitive (bool ),
369- 'parameters' :
370- ConfigObject (
371- schema = {
372- 'batch_sizes' : ConfigListNumeric (type_ = int ),
373- 'concurrency' : ConfigListNumeric (type_ = int )
374- }),
375- 'objectives' :
376- objectives_scheme ,
377- 'constraints' :
378- constraints_scheme ,
379- 'model_config_parameters' :
380- model_config_fields ,
381- 'perf_analyzer_flags' :
382- perf_analyzer_flags_scheme ,
383- 'triton_server_flags' :
384- triton_server_flags_scheme ,
385- 'triton_server_environment' :
386- triton_server_environment_scheme
387- })
357+ ConfigObject (
358+ schema = {
359+ 'cpu_only' :
360+ ConfigPrimitive (bool ),
361+ 'parameters' :
362+ ConfigObject (
363+ schema = {
364+ 'batch_sizes' :
365+ ConfigListNumeric (type_ = int ),
366+ 'concurrency' :
367+ ConfigListNumeric (type_ = int )
368+ }),
369+ 'objectives' :
370+ objectives_scheme ,
371+ 'constraints' :
372+ constraints_scheme ,
373+ 'model_config_parameters' :
374+ model_config_fields ,
375+ 'perf_analyzer_flags' :
376+ perf_analyzer_flags_scheme ,
377+ 'triton_server_flags' :
378+ triton_server_flags_scheme ,
379+ 'triton_server_environment' :
380+ triton_server_environment_scheme
381+ })
388382 },
389383 output_mapper = ConfigModelProfileSpec .
390384 model_object_to_config_model_profile_spec )
@@ -394,17 +388,15 @@ def objective_list_output_mapper(objectives):
394388 flags = ['--profile-models' ],
395389 field_type = ConfigUnion ([
396390 profile_model_scheme ,
397- ConfigListGeneric (
398- ConfigUnion ([
399- profile_model_scheme ,
400- ConfigPrimitive (
401- str ,
402- output_mapper = ConfigModelProfileSpec .
403- model_str_to_config_model_profile_spec )
404- ]),
405- required = True ,
406- output_mapper = ConfigModelProfileSpec .
407- model_mixed_to_config_model_profile_spec ),
391+ ConfigListGeneric (ConfigUnion ([
392+ profile_model_scheme ,
393+ ConfigPrimitive (str ,
394+ output_mapper = ConfigModelProfileSpec .
395+ model_str_to_config_model_profile_spec )
396+ ]),
397+ required = True ,
398+ output_mapper = ConfigModelProfileSpec .
399+ model_mixed_to_config_model_profile_spec ),
408400 ConfigListString (output_mapper = ConfigModelProfileSpec .
409401 model_list_to_config_model_profile_spec ),
410402 ],
@@ -417,8 +409,7 @@ def objective_list_output_mapper(objectives):
417409 field_type = ConfigListNumeric (int ),
418410 default_value = DEFAULT_BATCH_SIZES ,
419411 description =
420- 'Comma-delimited list of batch sizes to use for the profiling' )
421- )
412+ 'Comma-delimited list of batch sizes to use for the profiling' ))
422413 self ._add_config (
423414 ConfigField (
424415 'concurrency' ,
@@ -553,12 +544,14 @@ def _add_triton_configs(self):
553544 description = "Triton Server Metrics endpoint url. "
554545 "Will be ignored if server-launch-mode is not 'remote'" ))
555546 self ._add_config (
556- ConfigField ('triton_server_path' ,
557- field_type = ConfigPrimitive (str ),
558- flags = ['--triton-server-path' ],
559- default_value = DEFAULT_TRITON_SERVER_PATH ,
560- description =
561- 'The full path to the tritonserver binary executable' ))
547+ ConfigField (
548+ 'triton_server_path' ,
549+ field_type = ConfigPrimitive (str ,
550+ validator = binary_path_validator ),
551+ flags = ['--triton-server-path' ],
552+ default_value = DEFAULT_TRITON_SERVER_PATH ,
553+ description = 'The full path to the tritonserver binary executable'
554+ ))
562555 self ._add_config (
563556 ConfigField (
564557 'triton_output_path' ,
@@ -567,7 +560,7 @@ def _add_triton_configs(self):
567560 description =
568561 ('The full path to the file to which Triton server instance will '
569562 'append their log output. If not specified, they are not written.'
570- )))
563+ )))
571564 self ._add_config (
572565 ConfigField (
573566 'triton_docker_mounts' ,
@@ -576,7 +569,7 @@ def _add_triton_configs(self):
576569 description =
577570 ("A list of strings representing volumes to be mounted. "
578571 "The strings should have the format '<host path>:<container path>:<access mode>'."
579- )))
572+ )))
580573 self ._add_config (
581574 ConfigField (
582575 'triton_docker_labels' ,
@@ -587,7 +580,7 @@ def _add_triton_configs(self):
587580 self ._add_config (
588581 ConfigField (
589582 'triton_install_path' ,
590- field_type = ConfigPrimitive (str ),
583+ field_type = ConfigPrimitive (str , validator = file_path_validator ),
591584 default_value = DEFAULT_TRITON_INSTALL_PATH ,
592585 flags = ['--triton-install-path' ],
593586 description =
@@ -614,16 +607,15 @@ def _add_perf_analyzer_configs(self):
614607 default_value = psutil .cpu_count () *
615608 DEFAULT_PERF_ANALYZER_CPU_UTIL ,
616609 description =
617- "Maximum CPU utilization value allowed for the perf_analyzer." )
618- )
610+ "Maximum CPU utilization value allowed for the perf_analyzer." ))
619611 self ._add_config (
620- ConfigField (
621- 'perf_analyzer_path' ,
622- flags = [ '--perf-analyzer-path' ],
623- field_type = ConfigPrimitive ( str ),
624- default_value = DEFAULT_PERF_ANALYZER_PATH ,
625- description =
626- 'The full path to the perf_analyzer binary executable' ))
612+ ConfigField ('perf_analyzer_path' ,
613+ flags = [ '--perf-analyzer-path' ] ,
614+ field_type = ConfigPrimitive (
615+ str , validator = binary_path_validator ),
616+ default_value = DEFAULT_PERF_ANALYZER_PATH ,
617+ description =
618+ 'The full path to the perf_analyzer binary executable' ))
627619 self ._add_config (
628620 ConfigField (
629621 'perf_output' ,
@@ -716,7 +708,7 @@ def _autofill_values(self):
716708 """
717709
718710 cpu_only = False
719- if len (self .gpus ) == 0 or not numba . cuda .is_available ():
711+ if len (self .gpus ) == 0 or not cuda .is_available ():
720712 cpu_only = True
721713
722714 new_profile_models = {}
0 commit comments