1919#
2020import sys
2121import configparser
22- import json
2322import os
2423import fnmatch
2524import psutil
4241 has_git = False
4342 pass
4443
44+
4545class GitOps :
4646
4747 def __init__ (self , repopath = './' ):
4848 self .repopath = repopath
4949 if has_git is True :
5050 try :
5151 self .repo = Repo (repopath )
52- except :
52+ except Exception :
5353 print ('no repo, init one' )
5454 self .repo = Repo .init (repopath )
5555 self .repo .git .add (A = True )
@@ -70,7 +70,7 @@ def find_commit_with_keyword(self, keyword, search_commits_depth=5):
7070 return ret
7171 try :
7272 repo = Repo (self .repopath )
73- except :
73+ except Exception :
7474 print ('no repo, init one' )
7575 repo = Repo .init (self .repopath )
7676 repo .git .add (A = True )
@@ -126,6 +126,7 @@ def dump_platform_info(self):
126126 self .cpu_socket_count = cpu_info .sockets
127127 self .svmem = svmem
128128
129+
129130class CommonUtils :
130131
131132 def __init__ (self ):
@@ -150,9 +151,10 @@ def found_files_in_folders(self, pattern, paths):
150151 foundpaths += paths
151152 return foundfiles , foundpaths
152153
154+
153155class GeneralConfigFile :
154156 def __init__ (self , ai_root ):
155- self .root = ai_root
157+ self .root = ai_root
156158 self .framework = ''
157159 self .device = ''
158160 # Empty for CPU
@@ -196,7 +198,6 @@ def __init__(self, ai_root):
196198 disabled = False ,
197199 )
198200
199-
200201 def toggle_events (self ):
201202 def on_hardware_change (change ):
202203 if change .new == 'GPU' :
@@ -238,16 +239,22 @@ def on_intel_oneapi_change(change):
238239 if change .new == 'No' :
239240 # Intel® oneAPI Base Toolkit is not installed
240241 print ("Intel® oneAPI Base Toolkit is not installed." )
241- print ("Follow instructions at [Intel® oneAPI Base Toolkit Download page](https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html?operatingsystem=linux) to setup the package manager repository." )
242+ print (
243+ "Follow instructions at [Intel® oneAPI Base Toolkit Download page]"
244+ "(https://www.intel.com/content/www/us/en/developer/tools/oneapi"
245+ "/base-toolkit-download.html?operatingsystem=linux) "
246+ "to setup the package manager repository."
247+ )
242248 print ("Once Intel® oneAPI Base Toolkit is installed on the machine, please re-run this cell" )
243249 return
244250
245-
246251 self .hardware_dropdown .observe (on_hardware_change , names = 'value' )
247252 self .framework_dropdown .observe (on_framework_change , names = 'value' )
248253 self .intel_oneapi_dropdown .observe (on_intel_oneapi_change , names = 'value' )
249254
250- if (self .hardware_dropdown .value and self .framework_dropdown .value and (self .hardware_dropdown .value == 'CPU' or (self .hardware_dropdown .value == 'GPU' and self .gpu_series_dropdown .value ))):
255+ if (self .hardware_dropdown .value and self .framework_dropdown .value and
256+ (self .hardware_dropdown .value == 'CPU' or
257+ (self .hardware_dropdown .value == 'GPU' and self .gpu_series_dropdown .value ))):
251258 self .success = True
252259 display (self .hardware_dropdown )
253260 display (self .framework_dropdown )
@@ -267,7 +274,7 @@ def __init__(self, confpath, AIpath):
267274 self .device = ''
268275 self .precision = ''
269276 self .test_mode = ''
270- #self.ai_type = ''
277+ # self.ai_type = ''
271278 self .custom_args = ''
272279 self .json_fname = ''
273280 self .json_fname = 'stock_'
@@ -372,7 +379,7 @@ def read_config(self, model_name):
372379 for key , value in model_data .items ():
373380 if key == 'name' :
374381 configs ['name' ] = value
375- #elif key == 'ai-type':
382+ # elif key == 'ai-type':
376383 # configs['ai-type'] = value
377384 elif key == 'model-name' :
378385 configs ['model-name' ] = value
@@ -398,7 +405,10 @@ def read_config(self, model_name):
398405 wget = sub_entry ['wget' ]
399406 if model_name .split ()[0 ] not in configs :
400407 configs [model_name .split ()[0 ]] = []
401- configs [model_name .split ()[0 ]].append ({'precision' : precision , 'test_mode' : test_mode , 'script' : scripts , 'wget' : wget })
408+ configs [model_name .split ()[0 ]].append ({'precision' : precision ,
409+ 'test_mode' : test_mode ,
410+ 'script' : scripts ,
411+ 'wget' : wget })
402412
403413 return configs
404414
@@ -489,7 +499,7 @@ def model_selection(self):
489499
490500 for index , section in enumerate (sections ):
491501 model_name = section .get ('model-name' , 'Unknown' )
492- #ai_type = section.get('ai-type', 'Unknown')
502+ # ai_type = section.get('ai-type', 'Unknown')
493503 framework = section .get ('framework' , 'Unknown' )
494504 mode = section .get ('mode' , 'Unknown' )
495505 device = section .get ('device' , 'Unknown' )
@@ -498,7 +508,8 @@ def model_selection(self):
498508 print ("Supported Models: " )
499509 display (models_table )
500510
501- model_index = int (input ('Input an index number of a model: ' )) if 'MODEL_1_INDEX' not in os .environ else int (os .environ ['MODEL_1_INDEX' ])
511+ model_index = int (input ('Input an index number of a model: ' )) \
512+ if 'MODEL_1_INDEX' not in os .environ else int (os .environ ['MODEL_1_INDEX' ])
502513
503514 if not 0 <= model_index < len (sections ):
504515 raise Exception ("Invalid choice for model index" )
@@ -513,14 +524,16 @@ def device_specific(self, model_section, device, yaml_file, framework):
513524 # Set initial properties
514525 self .model_name = model_section ['name' ]
515526 self .framework = model_section ['framework' ]
516- self .mode = model_section ['mode' ][int (input ('0 for training and 1 for inference: ' ))] if len (model_section ['mode' ]) > 1 else model_section ['mode' ][0 ]
527+ self .mode = model_section ['mode' ][int (input ('0 for training and 1 for inference: ' ))] \
528+ if len (model_section ['mode' ]) > 1 else model_section ['mode' ][0 ]
517529
518530 # Load model-specific configuration
519531 model_specific_config = AIReferenceConfigFile (yaml_file , self .ai_root )
520532 model_specific_section = model_specific_config .read_supported_section ()[0 ]
521533
522534 # Determine the precision options key dynamically
523- precision_key = model_section .get ('model-name' , self .model_name .split ()[0 ]) # Use 'model-name' if available, else fallback
535+ # Use 'model-name' if available, else fallback
536+ precision_key = model_section .get ('model-name' , self .model_name .split ()[0 ])
524537
525538 # Get precision options
526539 model_precisions = model_specific_section .get (precision_key )
@@ -564,7 +577,9 @@ def device_specific(self, model_section, device, yaml_file, framework):
564577 # Non-TensorFlow-specific handling
565578 model_precision_test_mode = model_precision_section .get ('test_mode' , [])
566579 if not model_precision_test_mode :
567- raise ValueError (f"No test modes found for model '{ self .model_name } ' with precision '{ self .precision } '." )
580+ raise ValueError (
581+ f"No test modes found for model '{ self .model_name } ' with precision '{ self .precision } '."
582+ )
568583 print (f"Available Test Modes for { self .precision } :" )
569584 model_test_mode_table = PrettyTable (["Index" , "Test Mode" ])
570585 for index , test_mode in enumerate (model_precision_test_mode ):
@@ -578,7 +593,7 @@ def device_specific(self, model_section, device, yaml_file, framework):
578593 self .test_mode = model_precision_test_mode [model_precision_test_mode_index ]
579594
580595 # Print selected configuration
581- print (f"Selected { self .model_name } { self .framework } { self .precision } { self .script if framework == 'TensorFlow' else self .test_mode } " )
596+ print (f"Selected { self .model_name } { self .framework } { self .precision } "
597+ "{self.script if framework == 'TensorFlow' else self.test_mode}" )
582598
583599 return model_specific_section
584-
0 commit comments