@@ -177,56 +177,9 @@ def check_model_table(overwrite=False):
177177 )
178178
179179
180- def has_onnx (model_type ):
181- """
182- Returns whether `model_type` is supported by ONNX (by checking if there is an ONNX config) or not.
183- """
184- config_mapping = transformers_module .models .auto .configuration_auto .CONFIG_MAPPING
185- if model_type not in config_mapping :
186- return False
187- config = config_mapping [model_type ]
188- config_module = config .__module__
189- module = transformers_module
190- for part in config_module .split ("." )[1 :]:
191- module = getattr (module , part )
192- config_name = config .__name__
193- onnx_config_name = config_name .replace ("ConfigMixin" , "OnnxConfigMixin" )
194- return hasattr (module , onnx_config_name )
195-
196-
197- def get_onnx_model_list ():
198- """
199- Return the list of models supporting ONNX.
200- """
201- config_mapping = transformers_module .models .auto .configuration_auto .CONFIG_MAPPING
202- model_names = config_mapping = transformers_module .models .auto .configuration_auto .MODEL_NAMES_MAPPING
203- onnx_model_types = [model_type for model_type in config_mapping .keys () if has_onnx (model_type )]
204- onnx_model_names = [model_names [model_type ] for model_type in onnx_model_types ]
205- onnx_model_names .sort (key = lambda x : x .upper ())
206- return "\n " .join ([f"- { name } " for name in onnx_model_names ]) + "\n "
207-
208-
209- def check_onnx_model_list (overwrite = False ):
210- """Check the model list in the serialization.mdx is consistent with the state of the lib and maybe `overwrite`."""
211- current_list , start_index , end_index , lines = _find_text_in_file (
212- filename = os .path .join (PATH_TO_DOCS , "serialization.mdx" ),
213- start_prompt = "<!--This table is automatically generated by `make fix-copies`, do not fill manually!-->" ,
214- end_prompt = "In the next two sections, we'll show you how to:" ,
215- )
216- new_list = get_onnx_model_list ()
217-
218- if current_list != new_list :
219- if overwrite :
220- with open (os .path .join (PATH_TO_DOCS , "serialization.mdx" ), "w" , encoding = "utf-8" , newline = "\n " ) as f :
221- f .writelines (lines [:start_index ] + [new_list ] + lines [end_index :])
222- else :
223- raise ValueError ("The list of ONNX-supported models needs an update. Run `make fix-copies` to fix this." )
224-
225-
226180if __name__ == "__main__" :
227181 parser = argparse .ArgumentParser ()
228182 parser .add_argument ("--fix_and_overwrite" , action = "store_true" , help = "Whether to fix inconsistencies." )
229183 args = parser .parse_args ()
230184
231185 check_model_table (args .fix_and_overwrite )
232- check_onnx_model_list (args .fix_and_overwrite )
0 commit comments