Skip to content

Commit

Permalink
Deprecate models script - correctly set the model name for the doc fi…
Browse files Browse the repository at this point in the history
…le (#30785)

* Correctly set the moel name for the doc file

* Fix up
  • Loading branch information
amyeroberts authored May 15, 2024
1 parent 5ca085b commit 58faa7b
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions utils/deprecate_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,13 @@ def insert_tip_to_model_doc(model_doc_path, tip_message):

def get_model_doc_path(model: str) -> Tuple[Optional[str], Optional[str]]:
# Possible variants of the model name in the model doc path
model_doc_paths = [
REPO_PATH / f"docs/source/en/model_doc/{model}.md",
# Try replacing _ with - in the model name
REPO_PATH / f"docs/source/en/model_doc/{model.replace('_', '-')}.md",
# Try replacing _ with "" in the model name
REPO_PATH / f"docs/source/en/model_doc/{model.replace('_', '')}.md",
]
model_names = [model, model.replace("_", "-"), model.replace("_", "")]

model_doc_paths = [REPO_PATH / f"docs/source/en/model_doc/{model_name}.md" for model_name in model_names]

for model_doc_path in model_doc_paths:
for model_doc_path, model_name in zip(model_doc_paths, model_names):
if os.path.exists(model_doc_path):
return model_doc_path, model
return model_doc_path, model_name

return None, None

Expand Down Expand Up @@ -186,6 +182,7 @@ def remove_model_references_from_file(filename, models, condition):
models (List[str]): The models to remove
condition (Callable): A function that takes the line and model and returns True if the line should be removed
"""
filename = REPO_PATH / filename
with open(filename, "r") as f:
init_file = f.read()

Expand Down

0 comments on commit 58faa7b

Please sign in to comment.