diff --git a/graph_net/torch/sym_dim_reifiers/naive_cv_sym_dim_reifier.py b/graph_net/torch/sym_dim_reifiers/naive_cv_sym_dim_reifier.py index bf5924c38..69d3dba0b 100644 --- a/graph_net/torch/sym_dim_reifiers/naive_cv_sym_dim_reifier.py +++ b/graph_net/torch/sym_dim_reifiers/naive_cv_sym_dim_reifier.py @@ -16,7 +16,14 @@ def match(self) -> bool: if self.dyn_dim_cstrs is None: return False sym_shapes_str = self.dyn_dim_cstrs.serialize_symbolic_input_shapes_to_str() - return sym_shapes_str in self._get_map_cv_sym_shapes_str2reifier() + if sym_shapes_str == "[]": + return False + elif sym_shapes_str not in self._get_map_cv_sym_shapes_str2reifier(): + print( + f"[CV SymDim Reify] No reifier matched symbolic shapes:{sym_shapes_str} \nPlease add a reify rule to _get_map_cv_sym_shapes_str2reifier()" + ) + return False + return True def reify(self): assert self.match() @@ -40,6 +47,15 @@ def _get_map_cv_sym_shapes_str2reifier(cls): "[(S0,80,S1),(S0,)]": cls.reify_nemo_asr_s0_s1, "[(S0,3,512,1024)]": cls.reify_semantic_seg_s0, "[(S0,3,640,640)]": cls.reify_yolo_s0, + "[(S0,)]": cls.reify_s0, + "[(S0,S1,S2)]": cls.reify_s0_s1_s2, + "[(S0,S1,S2,S2)]": cls.reify_s0_s1_s2, + "[(S0,3,S1,S2,S2)]": cls.reify_s0_s1_s2, + "[(S0,S1,S1,384)]": cls.reify_s0_s1_384, + "[(S0,S1),(S0,S1,2560)]": cls.reify_s0_s1_2560, + "[(S0,S1,256),(S0,S1,256)]": cls.reify_s0_s1_256, + "[(S0,S1),(S0,S1,3072)]": cls.reify_s0_s1_128_1024, + "[(S0,S1),(S0,S1,1024),(S0,S1,1024)]": cls.reify_s0_s1_128_1024, } return cls.g_cv_sym_shapes_str2reifier @@ -184,3 +200,89 @@ def reify_yolo_s0(self): return { S0: [[1], [2], [4], [8], [12], [16], [24], [32], [64]], } + + def reify_s0(self): + S0 = (sympy.Symbol("S0"),) + return { + S0: [[1], [2], [4], [8], [16], [32], [48], [64], [128]], + } + + def reify_s0_s1_s2(self): + S0S1S2 = (sympy.Symbol("S0"), sympy.Symbol("S1"), sympy.Symbol("S2")) + return { + S0S1S2: [ + [1, 8, 8], + [1, 8, 16], + [1, 16, 16], + [2, 16, 16], + [1, 16, 32], + [2, 16, 32], + [4, 16, 32], + [1, 32, 32], + [2, 32, 32], + ], + } + + def reify_s0_s1_384(self): + S0S1 = (sympy.Symbol("S0"), sympy.Symbol("S1")) + return { + S0S1: [ + [1, 64], + [1, 128], + [1, 192], + [1, 224], + [1, 256], + [4, 224], + [8, 224], + [32, 224], + [64, 224], + ], + } + + def reify_s0_s1_2560(self): + S0S1 = (sympy.Symbol("S0"), sympy.Symbol("S1")) + return { + S0S1: [ + [1, 16], + [1, 32], + [2, 32], + [1, 64], + [2, 64], + [1, 128], + [2, 128], + [1, 256], + [2, 256], + ], + } + + def reify_s0_s1_256(self): + S0S1 = (sympy.Symbol("S0"), sympy.Symbol("S1")) + return { + S0S1: [ + [1, 8], + [1, 16], + [2, 16], + [1, 32], + [2, 32], + [4, 32], + [1, 64], + [2, 64], + [4, 64], + ], + } + + def reify_s0_s1_128_1024(self): + S0S1 = (sympy.Symbol("S0"), sympy.Symbol("S1")) + return { + S0S1: [ + [1, 8], + [1, 16], + [2, 16], + [1, 32], + [2, 32], + [4, 32], + [1, 64], + [2, 64], + [4, 64], + ], + } diff --git a/graph_net/torch/sym_dim_reifiers/naive_nlp_sym_dim_reifier.py b/graph_net/torch/sym_dim_reifiers/naive_nlp_sym_dim_reifier.py index 53fbd8369..c3f3fb535 100644 --- a/graph_net/torch/sym_dim_reifiers/naive_nlp_sym_dim_reifier.py +++ b/graph_net/torch/sym_dim_reifiers/naive_nlp_sym_dim_reifier.py @@ -16,7 +16,14 @@ def match(self) -> bool: if self.dyn_dim_cstrs is None: return False sym_shapes_str = self.dyn_dim_cstrs.serialize_symbolic_input_shapes_to_str() - return sym_shapes_str in self._get_map_nlp_sym_shapes_str2reifier() + if sym_shapes_str == "[]": + return False + elif sym_shapes_str not in self._get_map_nlp_sym_shapes_str2reifier(): + print( + f"[NLP SymDim Reify] No reifier matched symbolic shapes:{sym_shapes_str} \nPlease add a reify rule to _get_map_nlp_sym_shapes_str2reifier()" + ) + return False + return True def reify(self): assert self.match() diff --git a/samples/timm/sequencer2d_l.in1k/graph_net.json b/samples/timm/sequencer2d_l.in1k/graph_net.json index a7d5814e5..e8d543f0d 100644 --- a/samples/timm/sequencer2d_l.in1k/graph_net.json +++ b/samples/timm/sequencer2d_l.in1k/graph_net.json @@ -4,5 +4,6 @@ "num_nodes_required": 1, "dynamic": true, "source": "timm", - "heuristic_tag": "computer_vision" + "heuristic_tag": "computer_vision", + "symbolic_dimension_reifier": "naive_cv_sym_dim_reifier" } \ No newline at end of file diff --git a/samples/torchgeometric/MetaPath2Vec/graph_net.json b/samples/torchgeometric/MetaPath2Vec/graph_net.json index e78a5d0b6..3b631515c 100644 --- a/samples/torchgeometric/MetaPath2Vec/graph_net.json +++ b/samples/torchgeometric/MetaPath2Vec/graph_net.json @@ -1 +1,10 @@ -{"framework": "torch", "num_devices_required": 1, "num_nodes_required": 1, "dynamic": false, "source": "torchgeometric", "heuristic_tag": "other", "dimension_generalization_passes": []} \ No newline at end of file +{ + "framework": "torch", + "num_devices_required": 1, + "num_nodes_required": 1, + "dynamic": false, + "source": "torchgeometric", + "heuristic_tag": "other", + "dimension_generalization_passes": [], + "symbolic_dimension_reifier": "naive_cv_sym_dim_reifier" +} \ No newline at end of file diff --git a/samples/torchgeometric/Node2Vec/graph_net.json b/samples/torchgeometric/Node2Vec/graph_net.json index e78a5d0b6..3b631515c 100644 --- a/samples/torchgeometric/Node2Vec/graph_net.json +++ b/samples/torchgeometric/Node2Vec/graph_net.json @@ -1 +1,10 @@ -{"framework": "torch", "num_devices_required": 1, "num_nodes_required": 1, "dynamic": false, "source": "torchgeometric", "heuristic_tag": "other", "dimension_generalization_passes": []} \ No newline at end of file +{ + "framework": "torch", + "num_devices_required": 1, + "num_nodes_required": 1, + "dynamic": false, + "source": "torchgeometric", + "heuristic_tag": "other", + "dimension_generalization_passes": [], + "symbolic_dimension_reifier": "naive_cv_sym_dim_reifier" +} \ No newline at end of file diff --git a/samples/torchvision/googlenet/graph_net.json b/samples/torchvision/googlenet/graph_net.json index 657e4a00a..30c083e44 100644 --- a/samples/torchvision/googlenet/graph_net.json +++ b/samples/torchvision/googlenet/graph_net.json @@ -1 +1,9 @@ -{"framework": "torch", "num_devices_required": 1, "num_nodes_required": 1, "source": "torchvision", "heuristic_tag": "computer_vision", "dimension_generalization_passes": []} \ No newline at end of file +{ + "framework": "torch", + "num_devices_required": 1, + "num_nodes_required": 1, + "source": "torchvision", + "heuristic_tag": "computer_vision", + "dimension_generalization_passes": [], + "symbolic_dimension_reifier": "naive_cv_sym_dim_reifier" +} \ No newline at end of file diff --git a/samples/torchvision/inception_v3/graph_net.json b/samples/torchvision/inception_v3/graph_net.json index 657e4a00a..30c083e44 100644 --- a/samples/torchvision/inception_v3/graph_net.json +++ b/samples/torchvision/inception_v3/graph_net.json @@ -1 +1,9 @@ -{"framework": "torch", "num_devices_required": 1, "num_nodes_required": 1, "source": "torchvision", "heuristic_tag": "computer_vision", "dimension_generalization_passes": []} \ No newline at end of file +{ + "framework": "torch", + "num_devices_required": 1, + "num_nodes_required": 1, + "source": "torchvision", + "heuristic_tag": "computer_vision", + "dimension_generalization_passes": [], + "symbolic_dimension_reifier": "naive_cv_sym_dim_reifier" +} \ No newline at end of file diff --git a/samples/torchvision/r3d_18/graph_net.json b/samples/torchvision/r3d_18/graph_net.json index 657e4a00a..30c083e44 100644 --- a/samples/torchvision/r3d_18/graph_net.json +++ b/samples/torchvision/r3d_18/graph_net.json @@ -1 +1,9 @@ -{"framework": "torch", "num_devices_required": 1, "num_nodes_required": 1, "source": "torchvision", "heuristic_tag": "computer_vision", "dimension_generalization_passes": []} \ No newline at end of file +{ + "framework": "torch", + "num_devices_required": 1, + "num_nodes_required": 1, + "source": "torchvision", + "heuristic_tag": "computer_vision", + "dimension_generalization_passes": [], + "symbolic_dimension_reifier": "naive_cv_sym_dim_reifier" +} \ No newline at end of file diff --git a/samples/transformers-auto-model/IDEA-Research_grounding-dino-tiny/graph_net.json b/samples/transformers-auto-model/IDEA-Research_grounding-dino-tiny/graph_net.json index 8513c8ec8..1bbcf4278 100644 --- a/samples/transformers-auto-model/IDEA-Research_grounding-dino-tiny/graph_net.json +++ b/samples/transformers-auto-model/IDEA-Research_grounding-dino-tiny/graph_net.json @@ -16,5 +16,6 @@ "license:apache-2.0", "region:us" ], - "heuristic_tag": "other" + "heuristic_tag": "other", + "symbolic_dimension_reifier": "naive_cv_sym_dim_reifier" } \ No newline at end of file diff --git a/samples/transformers-auto-model/UAE-Large-V1/graph_net.json b/samples/transformers-auto-model/UAE-Large-V1/graph_net.json index 4ac37987d..f51258f59 100644 --- a/samples/transformers-auto-model/UAE-Large-V1/graph_net.json +++ b/samples/transformers-auto-model/UAE-Large-V1/graph_net.json @@ -26,5 +26,6 @@ "endpoints_compatible", "region:us" ], - "heuristic_tag": "other" + "heuristic_tag": "other", + "symbolic_dimension_reifier": "naive_cv_sym_dim_reifier" } \ No newline at end of file diff --git a/samples/transformers-auto-model/allegro_plt5-large/graph_net.json b/samples/transformers-auto-model/allegro_plt5-large/graph_net.json index 93f225a94..9dbcb58e5 100644 --- a/samples/transformers-auto-model/allegro_plt5-large/graph_net.json +++ b/samples/transformers-auto-model/allegro_plt5-large/graph_net.json @@ -35,5 +35,6 @@ "non_batch_call_function_full_plus_one_pass", "non_batch_call_function_zeros_pass", "non_batch_call_function_arange_plus_one_pass" - ] + ], + "symbolic_dimension_reifier": "naive_cv_sym_dim_reifier" } \ No newline at end of file diff --git a/samples/transformers-auto-model/google-t5_t5-large/graph_net.json b/samples/transformers-auto-model/google-t5_t5-large/graph_net.json index 09dbb9fd1..a7d05999c 100644 --- a/samples/transformers-auto-model/google-t5_t5-large/graph_net.json +++ b/samples/transformers-auto-model/google-t5_t5-large/graph_net.json @@ -47,5 +47,6 @@ "non_batch_call_function_full_plus_one_pass", "non_batch_call_function_zeros_pass", "non_batch_call_function_arange_plus_one_pass" - ] + ], + "symbolic_dimension_reifier": "naive_cv_sym_dim_reifier" } \ No newline at end of file diff --git a/samples/transformers-auto-model/larryvrh_mt5-translation-ja_zh/graph_net.json b/samples/transformers-auto-model/larryvrh_mt5-translation-ja_zh/graph_net.json index dacf577c6..56795bf91 100644 --- a/samples/transformers-auto-model/larryvrh_mt5-translation-ja_zh/graph_net.json +++ b/samples/transformers-auto-model/larryvrh_mt5-translation-ja_zh/graph_net.json @@ -31,5 +31,6 @@ "non_batch_call_function_full_plus_one_pass", "non_batch_call_function_zeros_pass", "non_batch_call_function_arange_plus_one_pass" - ] + ], + "symbolic_dimension_reifier": "naive_cv_sym_dim_reifier" } \ No newline at end of file diff --git a/samples/transformers-auto-model/microsoft/Phi-3-mini-4k-instruct/graph_net.json b/samples/transformers-auto-model/microsoft/Phi-3-mini-4k-instruct/graph_net.json index f4b43d9f7..19f5eeef3 100644 --- a/samples/transformers-auto-model/microsoft/Phi-3-mini-4k-instruct/graph_net.json +++ b/samples/transformers-auto-model/microsoft/Phi-3-mini-4k-instruct/graph_net.json @@ -35,5 +35,6 @@ "non_batch_call_function_full_plus_one_pass", "non_batch_call_function_zeros_pass", "non_batch_call_function_arange_plus_one_pass" - ] + ], + "symbolic_dimension_reifier": "naive_cv_sym_dim_reifier" } \ No newline at end of file diff --git a/samples/transformers-auto-model/microsoft/phi-2/graph_net.json b/samples/transformers-auto-model/microsoft/phi-2/graph_net.json index 05b767a70..cf380faad 100644 --- a/samples/transformers-auto-model/microsoft/phi-2/graph_net.json +++ b/samples/transformers-auto-model/microsoft/phi-2/graph_net.json @@ -32,5 +32,6 @@ "non_batch_call_function_full_plus_one_pass", "non_batch_call_function_zeros_pass", "non_batch_call_function_arange_plus_one_pass" - ] + ], + "symbolic_dimension_reifier": "naive_cv_sym_dim_reifier" } \ No newline at end of file diff --git a/samples/transformers-auto-model/sheshkar_cmon2/graph_net.json b/samples/transformers-auto-model/sheshkar_cmon2/graph_net.json index 26ba96c87..9595fe175 100644 --- a/samples/transformers-auto-model/sheshkar_cmon2/graph_net.json +++ b/samples/transformers-auto-model/sheshkar_cmon2/graph_net.json @@ -16,5 +16,6 @@ "endpoints_compatible", "region:us" ], - "heuristic_tag": "other" + "heuristic_tag": "other", + "symbolic_dimension_reifier": "naive_cv_sym_dim_reifier" } \ No newline at end of file