@@ -53,6 +53,7 @@ def __init__(
5353 providers = providers ,
5454 provider_options = provider_options ,
5555 )
56+ self .device = "cuda" if "CUDAExecutionProvider" in self .sess .get_providers () else "cpu"
5657
5758 # setting onnxruntime session info
5859 self .model_path = model_path
@@ -62,9 +63,7 @@ def __init__(
6263
6364 input_infos , output_infos = self ._init_io_infos (model_path , input_initializer )
6465
65- io_binding , x_ortvalues , y_ortvalues = self ._setup_io_binding (
66- input_infos , output_infos
67- )
66+ io_binding , x_ortvalues , y_ortvalues = self ._setup_io_binding (input_infos , output_infos )
6867 self .io_binding = io_binding
6968 self .x_ortvalues = x_ortvalues
7069 self .y_ortvalues = y_ortvalues
@@ -121,14 +120,10 @@ def _setup_io_binding(self, input_infos, output_infos):
121120 y_ortvalues = {}
122121 for k , v in input_infos .items ():
123122 m = np .zeros (** v )
124- x_ortvalues [k ] = ort .OrtValue .ortvalue_from_numpy (
125- m , device_type = "cuda" , device_id = self .device_id
126- )
123+ x_ortvalues [k ] = ort .OrtValue .ortvalue_from_numpy (m , device_type = self .device , device_id = self .device_id )
127124 for k , v in output_infos .items ():
128125 m = np .zeros (** v )
129- y_ortvalues [k ] = ort .OrtValue .ortvalue_from_numpy (
130- m , device_type = "cuda" , device_id = self .device_id
131- )
126+ y_ortvalues [k ] = ort .OrtValue .ortvalue_from_numpy (m , device_type = self .device , device_id = self .device_id )
132127
133128 io_binding = self .sess .io_binding ()
134129 for k , v in x_ortvalues .items ():
@@ -158,11 +153,7 @@ def format_nested_dict(dict_data, indent=0):
158153 if isinstance (value , dict ):
159154 info .append (f"{ prefix } { key } :" )
160155 info .append (format_nested_dict (value , indent + 1 ))
161- elif (
162- isinstance (value , str )
163- and value .startswith ("{" )
164- and value .endswith ("}" )
165- ):
156+ elif isinstance (value , str ) and value .startswith ("{" ) and value .endswith ("}" ):
166157 try :
167158 nested_dict = eval (value )
168159 if isinstance (nested_dict , dict ):
@@ -179,9 +170,7 @@ def format_nested_dict(dict_data, indent=0):
179170 title = "DOCSAID X ONNXRUNTIME"
180171 divider_length = 50
181172 divider = f"+{ '-' * divider_length } +"
182- styled_title = colored .stylize (
183- title , [colored .fg ("blue" ), colored .attr ("bold" )]
184- )
173+ styled_title = colored .stylize (title , [colored .fg ("blue" ), colored .attr ("bold" )])
185174
186175 def center_text (text , width ):
187176 """Center text within a fixed width, handling ANSI escape codes."""
0 commit comments