MCPcopy
hub / github.com/huggingface/transformers / format_args_docstring

Function format_args_docstring

src/transformers/utils/auto_docstring.py:2834–2852  ·  view source on GitHub ↗

Replaces placeholders such as {image_processor_class} in the docstring with the actual values, deducted from the model name and the auto modules.

(docstring: str, model_name: str)

Source from the content-addressed store, hash-verified

2832
2833
2834def format_args_docstring(docstring: str, model_name: str) -> str:
2835 """
2836 Replaces placeholders such as {image_processor_class} in the docstring with the actual values,
2837 deducted from the model name and the auto modules.
2838 """
2839 # first check if there are any placeholders in the docstring, if not return it as is
2840 placeholders = set(_re_placeholders.findall(docstring))
2841 if not placeholders:
2842 return docstring
2843
2844 # get the placeholders dictionary for the given model name
2845 placeholders_dict = get_placeholders_dict(placeholders, model_name)
2846 # replace the placeholders in the docstring with the values from the placeholders_dict
2847 for placeholder, value in placeholders_dict.items():
2848 if isinstance(value, dict) and placeholder == "image_processor_class":
2849 value = value.get("torchvision", value.get("pil", None))
2850 if placeholder is not None:
2851 docstring = docstring.replace(f"{{{placeholder}}}", value)
2852 return docstring
2853
2854
2855def get_args_doc_from_source(args_classes: object | list[object]) -> dict:

Callers 2

auto_method_docstringFunction · 0.85
auto_class_docstringFunction · 0.85

Calls 3

get_placeholders_dictFunction · 0.85
itemsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected