Map model_type and doc pages names (#14944)
* Map model_type and doc pages names * Add script * Fix typo * Quality * Manual check for Auto Co-authored-by: Lysandre <lysandre.debut@reseau.eseo.fr>
This commit is contained in:
@@ -18,6 +18,7 @@ import inspect
|
||||
import os
|
||||
import re
|
||||
import warnings
|
||||
from difflib import get_close_matches
|
||||
from pathlib import Path
|
||||
|
||||
from transformers import is_flax_available, is_tf_available, is_torch_available
|
||||
@@ -596,6 +597,33 @@ def check_all_objects_are_documented():
|
||||
+ "\n - ".join(undocumented_objs)
|
||||
)
|
||||
check_docstrings_are_in_md()
|
||||
check_model_type_doc_match()
|
||||
|
||||
|
||||
def check_model_type_doc_match():
|
||||
"""Check all doc pages have a corresponding model type."""
|
||||
model_doc_folder = Path(PATH_TO_DOC) / "model_doc"
|
||||
model_docs = [m.stem for m in model_doc_folder.glob("*.mdx")]
|
||||
|
||||
model_types = list(transformers.models.auto.configuration_auto.MODEL_NAMES_MAPPING.keys())
|
||||
|
||||
errors = []
|
||||
for m in model_docs:
|
||||
if m not in model_types and m != "auto":
|
||||
close_matches = get_close_matches(m, model_types)
|
||||
error_message = f"{m} is not a proper model identifier."
|
||||
if len(close_matches) > 0:
|
||||
close_matches = "/".join(close_matches)
|
||||
error_message += f" Did you mean {close_matches}?"
|
||||
errors.append(error_message)
|
||||
|
||||
if len(errors) > 0:
|
||||
raise ValueError(
|
||||
"Some model doc pages do not match any existing model type:\n"
|
||||
+ "\n".join(errors)
|
||||
+ "\nYou can add any missing model type to the `MODEL_NAMES_MAPPING` constant in "
|
||||
"models/auto/configuration_auto.py."
|
||||
)
|
||||
|
||||
|
||||
# Re pattern to catch :obj:`xx`, :class:`xx`, :func:`xx` or :meth:`xx`.
|
||||
|
||||
Reference in New Issue
Block a user