4747np_dtype_string = np .dtype (object )
4848from typing import List , Tuple
4949
50+
51+ _color_blue = "\033 [94m"
5052_color_green = "\033 [32m"
5153_color_magenta = "\033 [35m"
5254_color_red = "\033 [31m"
@@ -1322,6 +1324,9 @@ def create_libtorch_pt2_modelfile(
13221324 ):
13231325 return
13241326
1327+ torch_output0_dtype = np_to_torch_dtype (output0_dtype )
1328+ torch_output1_dtype = np_to_torch_dtype (output1_dtype )
1329+
13251330 model_name = tu .get_model_name (
13261331 "libtorch_pt2" ,
13271332 input_dtype ,
@@ -1342,17 +1347,19 @@ def create_libtorch_pt2_modelfile(
13421347 pass # ignore existing dir
13431348
13441349 class AddSubNet (nn .Module ):
1345- def __init__ (self , swap ):
1350+ def __init__ (self , output0_dtype , output1_dtype , swap ):
1351+ self .output0_dtype = output0_dtype
1352+ self .output1_dtype = output1_dtype
13461353 self .swap = swap
13471354 super (AddSubNet , self ).__init__ ()
13481355
13491356 def forward (self , INPUT0 , INPUT1 ):
13501357 op0 = (INPUT0 - INPUT1 ) if self .swap else (INPUT0 + INPUT1 )
13511358 op1 = (INPUT0 + INPUT1 ) if self .swap else (INPUT0 - INPUT1 )
1352- return op0 , op1
1359+ return op0 . to ( self . output0_dtype ) , op1 . to ( self . output1_dtype )
13531360
13541361 device = torch .device ("cuda" if torch .cuda .is_available () else "cpu" )
1355- model = AddSubNet (swap )
1362+ model = AddSubNet (torch_output0_dtype , torch_output1_dtype , swap )
13561363 model .to (device )
13571364
13581365 input0 = torch .randn (* input_shape , device = device )
@@ -1387,6 +1394,9 @@ def create_torch_aoti_modelfile(
13871394 ):
13881395 return
13891396
1397+ torch_output0_dtype = np_to_torch_dtype (output0_dtype )
1398+ torch_output1_dtype = np_to_torch_dtype (output1_dtype )
1399+
13901400 model_name = tu .get_model_name (
13911401 "torch_aoti" ,
13921402 input_dtype ,
@@ -1406,17 +1416,19 @@ def create_torch_aoti_modelfile(
14061416 pass # ignore existing dir
14071417
14081418 class AddSubNet (nn .Module ):
1409- def __init__ (self , swap ):
1419+ def __init__ (self , output0_dtype , output1_dtype , swap ):
1420+ self .output0_dtype = output0_dtype
1421+ self .output1_dtype = output1_dtype
14101422 self .swap = swap
14111423 super (AddSubNet , self ).__init__ ()
14121424
14131425 def forward (self , INPUT0 , INPUT1 ):
14141426 op0 = (INPUT0 - INPUT1 ) if self .swap else (INPUT0 + INPUT1 )
14151427 op1 = (INPUT0 + INPUT1 ) if self .swap else (INPUT0 - INPUT1 )
1416- return op0 , op1
1428+ return op0 . to ( self . output0_dtype ) , op1 . to ( self . output1_dtype )
14171429
14181430 device = torch .device ("cuda" if torch .cuda .is_available () else "cpu" )
1419- model = AddSubNet (swap )
1431+ model = AddSubNet (torch_output0_dtype , torch_output1_dtype , swap )
14201432 model .to (device )
14211433
14221434 input0 = torch .randn (* input_shape , device = device )
@@ -1655,7 +1667,7 @@ def create_libtorch_pt2_modelconfig(
16551667 dims: [ { tu .shape_to_dims_str (output1_shape )} ]
16561668 }}
16571669]
1658- instance_group [{{ kind: " { "KIND_GPU" if torch .cuda .is_available () else "KIND_CPU" } " }}]
1670+ instance_group [{{ kind: { "KIND_GPU" if torch .cuda .is_available () else "KIND_CPU" } }}]
16591671"""
16601672
16611673 try :
@@ -1987,6 +1999,7 @@ def create_models(
19871999 output0_label_cnt ,
19882000 version_policy = None ,
19892001):
2002+ print (f"{ _color_blue } Creating models in { models_dir } { _color_reset } " )
19902003 model_version = 1
19912004 if FLAGS .tensorrt :
19922005 print (f"{ _color_magenta } TensorRT model generation requested{ _color_reset } " )
@@ -2266,18 +2279,6 @@ def create_models(
22662279 output1_dtype ,
22672280 )
22682281
2269- if FLAGS .torchvision_aoti :
2270- print (f"{ _color_magenta } TorchVision AOTI model generation requested{ _color_reset } " )
2271- if create_torchvision_aoti_modelfile (
2272- models_dir ,
2273- 1 ,
2274- model_version ,
2275- ):
2276- create_torchvision_aoti_modelconfig (
2277- models_dir ,
2278- 1 ,
2279- )
2280-
22812282 if FLAGS .openvino :
22822283 print (f"{ _color_magenta } OpenVINO model generation requested{ _color_reset } " )
22832284 # max-batch 8
@@ -2692,24 +2693,6 @@ def create_fixed_models(
26922693 FLAGS .models_dir , 0 , 3 , (16 ,), (16 ,), (16 ,), vt , vt , vt , swap = True
26932694 )
26942695
2695- if FLAGS .torch_aoti :
2696- for vt in [np .float32 , np .int32 , np .int16 , np .int8 ]:
2697- create_torch_aoti_modelfile (
2698- FLAGS .models_dir , 8 , 2 , (16 ,), (16 ,), (16 ,), vt , vt , vt , swap = True
2699- )
2700- create_torch_aoti_modelfile (
2701- FLAGS .models_dir , 8 , 3 , (16 ,), (16 ,), (16 ,), vt , vt , vt , swap = True
2702- )
2703- create_torch_aoti_modelfile (
2704- FLAGS .models_dir , 0 , 2 , (16 ,), (16 ,), (16 ,), vt , vt , vt , swap = True
2705- )
2706- create_torch_aoti_modelfile (
2707- FLAGS .models_dir , 0 , 3 , (16 ,), (16 ,), (16 ,), vt , vt , vt , swap = True
2708- )
2709-
2710- if FLAGS .torchvision_aoti :
2711- create_torchvision_aoti_modelfile (FLAGS .models_dir , 1 , 1 )
2712-
27132696 if FLAGS .openvino :
27142697 for vt in [np .float16 , np .float32 , np .int8 , np .int16 , np .int32 ]:
27152698 create_openvino_modelfile (
@@ -2925,3 +2908,15 @@ def create_fixed_models(
29252908 # to fixed size model is not safe but doable
29262909 for model_shape in [(- 1 ,), (- 1 , - 1 ), (- 1 , - 1 , - 1 )]:
29272910 emu .create_nop_modelconfig (FLAGS .models_dir , model_shape , model_dtype )
2911+
2912+ if FLAGS .torchvision_aoti :
2913+ print (f"{ _color_blue } TorchVision AOTI model generation requested{ _color_reset } " )
2914+ if create_torchvision_aoti_modelfile (
2915+ FLAGS .models_dir ,
2916+ 1 ,
2917+ 1 ,
2918+ ):
2919+ create_torchvision_aoti_modelconfig (
2920+ FLAGS .models_dir ,
2921+ 1 ,
2922+ )
0 commit comments