diff --git a/docs/source/ko/_toctree.yml b/docs/source/ko/_toctree.yml
index a8eb0c556af9..e9a9a55be80d 100644
--- a/docs/source/ko/_toctree.yml
+++ b/docs/source/ko/_toctree.yml
@@ -369,6 +369,8 @@
title: ๐ค Transformers์ ๊ธฐ์ฌํ๋ ๋ฐฉ๋ฒ
- local: add_new_model
title: ๐ค Transformers์ ์๋ก์ด ๋ชจ๋ธ์ ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ
+ - local: auto_docstring
+ title: ๋ชจ๋ธ ๋ฌธ์ํ
- local: add_new_pipeline
title: ์ด๋ป๊ฒ ๐ค Transformers์ ํ์ดํ๋ผ์ธ์ ์ถ๊ฐํ๋์?
- local: testing
diff --git a/docs/source/ko/auto_docstring.md b/docs/source/ko/auto_docstring.md
new file mode 100644
index 000000000000..6549777a37e8
--- /dev/null
+++ b/docs/source/ko/auto_docstring.md
@@ -0,0 +1,280 @@
+
+
+# ๋ชจ๋ธ ๋ฌธ์ํ[[documenting-a-model]]
+
+Transformers์ `@auto_docstring` ๋ฐ์ฝ๋ ์ดํฐ๋ ๋ชจ๋ธ ํด๋์ค ๋ฐ ํด๋น ๋ฉ์๋์ ์ผ๊ด๋ docstring์ ์์ฑํฉ๋๋ค. ์ด๋ ํ์ค ์ธ์ ์ค๋ช
์ ์๋์ผ๋ก ํฌํจํ๋ฉด์๋ ์๋ก์ด ๋๋ ์ฌ์ฉ์ ์ง์ ์ธ์๋ฅผ ์ถ๊ฐํ๊ธฐ ์ํ ์ฌ์ ์๋ฅผ ํ์ฉํ์ฌ ์์ฉ๊ตฌ ์ฝ๋๋ฅผ ์ค์
๋๋ค. ํ์ค docstring์ ์๋์ผ๋ก ์ถ๊ฐํ ํ์ ์์ด ์ ์ธ์ ๋ฌธ์ํ์๋ง ์ง์คํ ์ ์์ด [์ ๋ชจ๋ธ ๊ธฐ์ฌํ๊ธฐ](./modular_transformers)๊ฐ ๋ ์ฌ์์ง๋๋ค.
+
+์ด ๊ฐ์ด๋์์๋ `@auto_docstring` ๋ฐ์ฝ๋ ์ดํฐ ์ฌ์ฉ ๋ฐฉ๋ฒ๊ณผ ๊ทธ ์๋ ๋ฐฉ์์ ์ค๋ช
ํฉ๋๋ค.
+
+## @auto_docstring[[autodocstring]]
+
+๋ชจ๋ธ๋ง ํ์ผ(`modular_model.py` ๋๋ `modeling_model.py`)์์ ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๋ ๊ฒ์ผ๋ก ์์ํฉ๋๋ค.
+
+```python
+from ...utils import auto_docstring
+```
+
+`@auto_docstring` ๋ฅผ ํด๋์ค ํน์ ํจ์์ ์ ์ฉํ ์ง ์ ํํ์ฌ ์๋ ์์์ฒ๋ผ ์ฌ์ฉํ์ธ์.
+
+
+
+
+`@auto_docstring`์ ํด๋์ค ์ ์ ๋ฐ๋ก ์์ ๋ฐฐ์นํฉ๋๋ค. ์ด ๋ฐ์ฝ๋ ์ดํฐ๋ `__init__` ๋ฉ์๋์ ์๊ทธ๋์ฒ์ docstring์์ ๋งค๊ฐ๋ณ์ ์ค๋ช
์ ์ถ์ถํฉ๋๋ค.
+
+```python
+from transformers.modeling_utils import PreTrainedModel
+from ...utils import auto_docstring
+
+@auto_docstring
+class MyAwesomeModel(PreTrainedModel):
+ def __init__(self, config, custom_parameter: int = 10, another_custom_arg: str = "default"):
+ r"""
+ custom_parameter (`int`, *optional*, defaults to 10):
+ MyAwesomeModel์ ๋ํ custom_parameter ์ค๋ช
์
๋๋ค.
+ another_custom_arg (`str`, *optional*, defaults to "default"):
+ ๋ค๋ฅธ ๊ณ ์ ์ธ์์ ๋ํ ๋ฌธ์์
๋๋ค.
+ """
+ super().__init__(config)
+ self.custom_parameter = custom_parameter
+ self.another_custom_arg = another_custom_arg
+ # ... ... ๋๋จธ์ง ์ด๊ธฐํ ์ฝ๋(init)
+
+ # ... ๊ธฐํ ๋ฉ์๋
+```
+
+๋ณด๋ค ์ธ๋ฐํ ์ ์ด๋ฅผ ์ํด ์ธ์๋ฅผ `@auto_docstring` ์ ์ง์ ์ ๋ฌํ ์๋ ์์ต๋๋ค. `custom_intro` ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ์ฌ ์ธ์ ๋ชฉ๋ก์ ๋ํ ์ค๋ช
์, `custom_args` ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ์ฌ ๊ฐ๋ณ ์ธ์๋ค์ ์ค๋ช
ํ ์ ์์ต๋๋ค.
+
+```python
+@auto_docstring(
+ custom_intro="""์ด ๋ชจ๋ธ์ ํน์ ์๋์ง ์์
์ ์ํํฉ๋๋ค.
+ ํ์ค Transformer ์ํคํ
์ฒ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ณ ์ ํ ์์ ์ฌํญ์ ํฌํจํฉ๋๋ค.""",
+ custom_args="""
+ custom_parameter (`type`, *optional*, defaults to `default_value`):
+ `args_doc.py`์ ์ ์๋์ง ์์๊ฑฐ๋ ์ฌ์ ์ํ๋ ๊ฒฝ์ฐ custom_parameter์ ๋ํ ๊ฐ๊ฒฐํ ์ค๋ช
์
๋๋ค.
+ internal_helper_arg (`type`, *optional*, defaults to `default_value`):
+ `args_doc.py`์ ์ ์๋์ง ์์๊ฑฐ๋ ์ฌ์ ์ํ๋ ๊ฒฝ์ฐ internal_helper_arg์ ๋ํ ๊ฐ๊ฒฐํ ์ค๋ช
์
๋๋ค.
+ """
+)
+class MySpecialModel(PreTrainedModel):
+ def __init__(self, config: ConfigType, custom_parameter: "type" = "default_value", internal_helper_arg=None):
+ # ...
+```
+
+`custom_intro`๋ง ์ฌ์ฉํ๊ณ ์ฌ์ฉ์ ์ง์ ์ธ์๋ฅผ ํด๋์ค์ ์ง์ ์ ์ํ ์๋ ์์ต๋๋ค.
+
+```python
+@auto_docstring(
+ custom_intro="""์ด ๋ชจ๋ธ์ ํน์ ์๋์ง ์์
์ ์ํํฉ๋๋ค.
+ ํ์ค Transformer ์ํคํ
์ฒ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ณ ์ ํ ์์ ์ฌํญ์ ํฌํจํฉ๋๋ค.""",
+)
+class MySpecialModel(PreTrainedModel):
+ def __init__(self, config: ConfigType, custom_parameter: "type" = "default_value", internal_helper_arg=None):
+ r"""
+ custom_parameter (`type`, *optional*, defaults to `default_value`):
+ `args_doc.py`์ ์ ์๋์ง ์์๊ฑฐ๋ ์ฌ์ ์ํ๋ ๊ฒฝ์ฐ custom_parameter์ ๋ํ ๊ฐ๊ฒฐํ ์ค๋ช
์
๋๋ค.
+ internal_helper_arg (`type`, *optional*, defaults to `default_value`):
+ `args_doc.py`์ ์ ์๋์ง ์์๊ฑฐ๋ ์ฌ์ ์ํ๋ ๊ฒฝ์ฐ internal_helper_arg์ ๋ํ ๊ฐ๊ฒฐํ ์ค๋ช
์
๋๋ค.
+ """
+ # ...
+```
+
+
+
+
+`@auto_docstring`์ ๋ฉ์๋ ์ ์ ๋ฐ๋ก ์์ ๋ฐฐ์นํฉ๋๋ค. ์ด ๋ฐ์ฝ๋ ์ดํฐ๋ ํจ์ ์๊ทธ๋์ฒ์์ ๋งค๊ฐ๋ณ์ ์ค๋ช
์ ์ถ์ถํฉ๋๋ค.
+
+```python
+ @auto_docstring
+ def forward(
+ self,
+ input_ids: Optional[torch.Tensor] = None,
+ attention_mask: Optional[torch.Tensor] = None,
+ new_custom_argument: Optional[torch.Tensor] = None,
+ arg_documented_in_args_doc: Optional[torch.Tensor] = None,
+ # ... ๋ค๋ฅธ ์ธ์๋ค
+ ) -> Union[Tuple, ModelOutput]: # ๋ฐํ ๊ฐ์ ๋ํ ์ค๋ช
์ ModelOutput ํด๋์ค docstring์์ ์๋์ผ๋ก ์์ฑ๋ฉ๋๋ค.
+ r"""
+ new_custom_argument (`torch.Tensor`, *optional*):
+ Description of this new custom argument and its expected shape or type.
+ """
+ # ...
+```
+
+์ ์ด๋ฅผ ๊ฐํํ๊ธฐ ์ํด ์ธ์๋ค์ `@auto_docstring`์ ์ง์ ์ ๋ฌํ ์๋ ์์ต๋๋ค. `custom_intro` ๋งค๊ฐ๋ณ์๋ ์ธ์๋ค์ ๋ํ ์ ๋ฐ์ ์ธ ์ค๋ช
์ ์์ฑํ ๋ ์ฌ์ฉํ๊ณ , `custom_args` ๋งค๊ฐ๋ณ์๋ ๊ฐ ์ธ์๋ณ ์ค๋ช
์ ์์ฑํ ๋ ์ฌ์ฉํฉ๋๋ค.
+
+docstring์ `Returns` ๋ฐ `Examples` ๋ถ๋ถ๋ ์๋์ผ๋ก ์ง์ ํ ์ ์์ต๋๋ค.
+
+
+```python
+MODEL_COMMON_CUSTOM_ARGS = r"""
+ common_arg_1 (`torch.Tensor`, *optional*, defaults to `default_value`):
+ common_arg_1์ ๋ํ ์ค๋ช
+ common_arg_2 (`torch.Tensor`, *optional*, defaults to `default_value`):
+ common_arg_2์ ๋ํ ์ค๋ช
+ ...
+"""
+
+class MyModel(PreTrainedModel):
+ # ...
+ @auto_docstring(
+ custom_intro="""
+ This is a custom introduction for the function.
+ """
+ custom_args=MODEL_COMMON_CUSTOM_ARGS
+ )
+ def forward(
+ self,
+ input_ids: Optional[torch.Tensor] = None,
+ attention_mask: Optional[torch.Tensor] = None,
+ common_arg_1: Optional[torch.Tensor] = None,
+ common_arg_2: Optional[torch.Tensor] = None,
+ #...
+ function_specific_argument: Optional[torch.Tensor] = None,
+ # ... ๋ค๋ฅธ ์ธ์๋ค
+ ) -> torch.Tensor:
+ r"""
+ function_specific_argument (`torch.Tensor`, *optional*):
+ ์ด ํจ์์ ํน์ ํ ์ธ์์ ๋ํ ์ค๋ช
์
๋๋ค.
+
+ Returns:
+ `torch.Tensor`: ์ผ๋ฐ์ ์ธ ํ์
์ ๋ฐํํ๋ ํจ์์ ๋ํด ์ฌ์ฉ์ ์ง์ "Returns" ์น์
์ ์ง์ ํ ์ ์์ต๋๋ค.
+
+ Example:
+
+ (๊ธฐ๋ณธ ์์๋ฅผ ์ฌ์ฉ์ ์ง์ ์์๋ก ์ฌ์ ์ํ๊ฑฐ๋, pipeline์ด ์๋ ๋ชจ๋ธ ํด๋์ค์ ๋ํ ์์๋ฅผ ์ถ๊ฐํ๋ ๊ฒฝ์ฐ)
+
+ ```python
+ ...
+ ```
+ """
+ # ...
+```
+
+
+
+
+## ์ธ์ ๋ฌธ์ํ[[documenting-arguments]]
+
+๋ค์ํ ์ ํ์ ์ธ์๋ฅผ ๋ฌธ์ํํ๊ธฐ ์ํ ๊ท์น์ ์๋์ ํ์ธํ ์ ์์ต๋๋ค.
+
+- ํ์ค ์ธ์(`input_ids`, `attention_mask`, `pixel_values` ๋ฑ)๋ `args_doc.py`์์ ์ ์๋์ด ์์ผ๋ฉฐ, ํด๋น ํ์ผ์์ ๋ถ๋ฌ์ ์ฌ์ฉํฉ๋๋ค. ์ด๋ ํ์ค ์ธ์์ ๋ํ ๋จ์ผ ์ ๋ณด ์ถ์ฒ์ด๋ฏ๋ก, ์ธ์์ ์ค๋ช
๊ณผ ํํ๊ฐ `args_doc.py`์ ์ธ์์ ๋์ผํ ๊ฒฝ์ฐ์๋ ๋ก์ปฌ์์ ์ฌ์ ์ํด์๋ ์ ๋ฉ๋๋ค.
+
+ ํ์ค ์ธ์๊ฐ ๋ชจ๋ธ์์ ๋ค๋ฅด๊ฒ ๋์ํ๋ ๊ฒฝ์ฐ, `r""" """` ๋ธ๋ก ๋ด์์ ๋ก์ปฌ๋ก ์ฌ์ ์ํ ์ ์์ต๋๋ค. ์ด ๋ก์ปฌ ์ ์๋ ๋ ๋์ ์ฐ์ ์์๋ฅผ ๊ฐ์ง๋๋ค. ์๋ฅผ ๋ค์ด, labels ์ธ์๋ ์ข
์ข
๋ชจ๋ธ๋ณ๋ก ์ฌ์ฉ์ ์ ์๋๋ฉฐ ์ผ๋ฐ์ ์ผ๋ก ์ฌ์ ์๊ฐ ํ์ํฉ๋๋ค.
+
+
+- ์ ์ธ์๋ ์ฌ์ฉ์ ์ ์ ์ธ์๋ ํจ์ ์๊ทธ๋์ฒ ๋ค์ `r""" """` ๋ธ๋ก์, ํด๋์ค์ ๊ฒฝ์ฐ `__init__` ๋ฉ์๋์ docstring์ ๋ฌธ์ํํด์ผ ํฉ๋๋ค.
+
+ ```py
+ argument_name (`type`, *optional*, defaults to `X`):
+ ์ธ์์ ๋ํ ์ค๋ช
์
๋๋ค.
+ Explain its purpose, expected shape/type if complex, and default behavior.
+ ์ฌ๋ฌ ์ค์ ๊ฑธ์ณ ์์ฑํ ์ ์์ต๋๋ค.
+ ```
+
+ * `type`์ ๋ฐฑํฑ์ผ๋ก ๊ฐ์ธ์ธ์.
+ * ์ธ์๊ฐ ํ์๊ฐ ์๋๊ฑฐ๋ ๊ธฐ๋ณธ๊ฐ์ด ์๋ ๊ฒฝ์ฐ *optional*์ ์ถ๊ฐํ์ธ์.
+ * ๊ธฐ๋ณธ๊ฐ์ด ์๋ ๊ฒฝ์ฐ "defaults to X"๋ฅผ ์ถ๊ฐํ์ธ์. ๊ธฐ๋ณธ๊ฐ์ด None์ธ ๊ฒฝ์ฐ "defaults to None"์ ์ถ๊ฐํ ํ์๋ ์์ต๋๋ค.
+
+ ์ด๋ฌํ ์ธ์๋ค์ `custom_args` ์ธ์๋ก `@auto_docstring`์ ์ ๋ฌํ ์๋ ์์ต๋๋ค. ์ด๋ ๋ชจ๋ธ๋ง ํ์ผ์ ์ฌ๋ฌ ์์น์์ ์๋ก์ด ์ธ์๋ค์ docstring ๋ธ๋ก์ด ๋ฐ๋ณต๋๋ ๊ฒฝ์ฐ ํ ๋ฒ๋ง ์ ์ํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
+
+ ```py
+ class MyModel(PreTrainedModel):
+ # ...
+ @auto_docstring(
+ custom_intro="""
+ ์ด ํจ์์ ๋ํ ์ฌ์ฉ์ ์ ์ ๋์
๋ถ์
๋๋ค.
+ """
+ custom_args=r"""
+ common_arg_1 (`torch.Tensor`, *optional*, defaults to `default_value`):
+ common_arg_1์ ๋ํ ์ค๋ช
+ """
+ )
+ ```
+
+## docstring ๊ฒ์ฌ[[checking-the-docstrings]]
+
+Transformers๋ Pull Request์์ CI(continuous intergration, ์ง์์ ํตํฉ) ๊ฒ์ฌ๋ฅผ ํธ๋ฆฌ๊ฑฐํ ๋ docstring ์ ํจ์ฑ์ ํ์ธํ๋ ์ ํธ๋ฆฌํฐ ์คํฌ๋ฆฝํธ๋ฅผ ํฌํจํฉ๋๋ค. ์คํฌ๋ฆฝํธ๋ ๋ค์ ๊ธฐ์ค์ ๊ฒ์ฌํฉ๋๋ค.
+
+* `@auto_docstring` ์ด ๊ด๋ จ ๋ชจ๋ ํด๋์ค ๋ฐ ๊ณต๊ฐ ๋ฉ์๋์ ์ ์ฉ๋์๋์ง ํ์ธํฉ๋๋ค.
+* ์ธ์๊ฐ ์์ ํ๊ณ ์ผ๊ด์ ์ธ์ง ํ์ธํฉ๋๋ค. ๋ฌธ์ํ๋ ์ธ์๊ฐ ์๊ทธ๋์ฒ์ ์กด์ฌํ๋์ง ํ์ธํ๊ณ , docstring์ ํ์
๋ฐ ๊ธฐ๋ณธ๊ฐ์ด ์๊ทธ๋์ฒ์ ์ผ์นํ๋์ง ๊ฒ์ฆํฉ๋๋ค. ์๋ ค์ง ํ์ค ์ธ์๊ฐ ์๋๊ฑฐ๋ ๋ก์ปฌ ์ค๋ช
์ด ์๋ ์ธ์๋ ํ๋๊ทธ๊ฐ ์ง์ ๋ฉ๋๋ค.
+* `` ๋ฐ `` ๊ฐ์ ์๋ฆฌ ํ์์(placeholder)๋ฅผ ์์ง ์๊ณ ์ฑ์ฐ๋๋ก ๋์์ค๋๋ค.
+* docstring์ด ์์๋๋ docstring ์คํ์ผ์ ๋ฐ๋ผ ํ์์ด ์ง์ ๋์๋์ง ํ์ธํฉ๋๋ค.
+
+์ด๋ฌํ ๊ฒ์ฌ๋ฅผ ์ปค๋ฐํ๊ธฐ ์ ์ ๋ก์ปฌ์์ ์คํํ ์ ์์ต๋๋ค. ๋ค์ ๋ช
๋ น์ด๋ฅผ ์คํํ์ธ์.
+
+```bash
+make fix-copies
+```
+
+`make fix-copies` ๋ ๋ค๋ฅธ ์ฌ๋ฌ ๊ฒ์ฌ๋ ์คํํฉ๋๋ค. ํด๋น ๊ฒ์ฌ๊ฐ ํ์ํ์ง ์์ ๊ฒฝ์ฐ, docstring ๋ฐ ์๋ docstring ๊ฒ์ฌ๋ง ์ํํ๋ ค๋ฉด ์๋ ๋ช
๋ น์ด๋ฅผ ์คํํ์ธ์.
+
+```bash
+python utils/check_docstrings.py # diff์ ํฌํจ๋ ํ์ผ๋ง ํ์ธํ๊ณ ์์ ํ์ง ์์ต๋๋ค.
+# python utils/check_docstrings.py --fix_and_overwrite # diff์ ํ์ผ์ ์์ ํ๊ณ ๋ฎ์ด์๋๋ค.
+# python utils/check_docstrings.py --fix_and_overwrite --check_all # ๋ชจ๋ ํ์ผ์ ์์ ํ๊ณ ๋ฎ์ด์๋๋ค.
+```
+
+## modular_model.py ํ์ผ[[modularmodelpy-files]]
+
+๋ชจ๋ํ๋ ํ์ผ(`modular_model.py`) ์์
์ `@auto_docstring` ์ ์ฉ์ ๋ํ ๋ค์ ์ง์นจ์ ๋ฐ๋ฅด์ธ์.
+
+- ๋ชจ๋ํ๋ ํ์ผ์ ๋
๋ฆฝ ์คํํ ๋ชจ๋ธ์ ๊ฒฝ์ฐ, `modeling_model.py` ํ์ผ์์์ ๊ฐ์ด `@auto_docstring`์ ์ ์ฉํฉ๋๋ค.
+- ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ชจ๋ธ์ ์์ํ๋ ๋ชจ๋ธ์ ๊ฒฝ์ฐ, `@auto_docstring`์ ์์ฑ๋ ๋ชจ๋ธ๋ง ํ์ผ๋ก ์๋์ผ๋ก ์ ๋ฌ๋ฉ๋๋ค. ๋ชจ๋ํ๋ ํ์ผ์ `@auto_docstring`์ ์ถ๊ฐํ ํ์๊ฐ ์์ต๋๋ค.
+
+ `@auto_docstring` ๋์์ ์์ ํด์ผ ํ๋ ๊ฒฝ์ฐ, ๋ชจ๋ํ๋ ํ์ผ์ ์ฌ์ฉ์ ์ง์ ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ์ ์ฉํฉ๋๋ค. ์๋ณธ ํจ์ ๋๋ ํด๋์ค์ ์๋ **๋ค๋ฅธ ๋ชจ๋ ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ๋ฐ๋์ ํฌํจ**ํด์ผ ํฉ๋๋ค.
+
+> [!WARNING]
+> ๋ชจ๋ํ๋ ํ์ผ์์ ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ์ฌ์ ์ํ ๋, ๋ถ๋ชจ ๋ชจ๋ธ์ ํด๋น ํจ์ ๋๋ ํด๋์ค์ ์ ์ฉ๋ **๋ชจ๋ ** ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ํฌํจํด์ผ ํฉ๋๋ค. ์ผ๋ถ ๋ฐ์ฝ๋ ์ดํฐ๋ง ์ฌ์ ์ํ๋ฉด ๋ค๋ฅธ ๋ฐ์ฝ๋ ์ดํฐ๋ ์์ฑ๋ ๋ชจ๋ธ๋ง ํ์ผ์ ํฌํจ๋์ง ์์ต๋๋ค.
+
+## ์๋ ๋ฐฉ์[[how-it-works]]
+
+`@auto_docstring` ๋ฐ์ฝ๋ ์ดํฐ๋ ๋ค์์ ํตํด docstring์ ์๋์ผ๋ก ์์ฑํฉ๋๋ค.
+
+1. ๋ฐ์ฝ๋ ์ดํธ๋ ํด๋์ค์ `__init__` ๋ฉ์๋ ๋๋ ๋ฐ์ฝ๋ ์ดํธ๋ ํจ์์ ์๊ทธ๋์ฒ(์ธ์, ํ์
, ๊ธฐ๋ณธ๊ฐ)๋ฅผ ๊ฒ์ฌํฉ๋๋ค.
+2. ์ผ๋ฐ์ ์ธ ์ธ์ (`input_ids`, `attention_mask`, ๋ฑ)์ ๋ํด ๋ฏธ๋ฆฌ ์ ์๋ docstring์ [`ModelArgs`], [`ImageProcessorArgs`] ๋ฐ `args_doc.py` ํ์ผ๊ณผ ๊ฐ์ ๋ด๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์์ค์์ ๊ฒ์ํฉ๋๋ค.
+3. ์๋์ ๊ฐ์ด ๋ ๊ฐ์ง ๋ฐฉ๋ฒ ์ค ํ๋๋ก ์ธ์ ์ค๋ช
์ ์ถ๊ฐํฉ๋๋ค.
+
+ | ๋ฐฉ๋ฒ | ์ค๋ช
| ์ฌ์ฉ๋ฒ |
+ |---|---|---|
+ | `r""" """` | ๋ฉ์๋ ์๊ทธ๋์ฒ์ ์ง์ ๋๋ `__init__` docstring ๋ด์ ์ฌ์ฉ์ ์ง์ docstring ๋ด์ฉ์ ์ถ๊ฐํฉ๋๋ค. | ์๋ก์ด ์ธ์๋ฅผ ๋ฌธ์ํํ๊ฑฐ๋ ํ์ค ์ค๋ช
์ ์ฌ์ ์ํฉ๋๋ค. |
+ | `custom_args` | `@auto_docstring`์ ํน์ ์ธ์์ ๋ํ ์ฌ์ฉ์ ์ง์ Docstring์ ์ง์ ์ถ๊ฐํฉ๋๋ค. | ๋ชจ๋ธ๋ง ํ์ผ์ ์ฌ๋ฌ ์์น์์ ๋ฐ๋ณต๋๋ ๊ฒฝ์ฐ ์๋ก์ด ์ธ์์ ๋ํ docstring์ ํ ๋ฒ๋ง ์ ์ํฉ๋๋ค. |
+
+4. ํด๋์ค ๋ฐ ํจ์ ์ค๋ช
์ ์ถ๊ฐํฉ๋๋ค. `ModelForCausalLM`๊ณผ ๊ฐ์ ํ์ค ๋ช
๋ช
ํจํด์ ๊ฐ์ง ๋ชจ๋ธ ํด๋์ค ๋๋ ํ์ดํ๋ผ์ธ์ ์ํ๋ ๊ฒฝ์ฐ, `@auto_docstring`์ `args_doc.py`์ `ClassDocstring`์ ์ฌ์ฉํ์ฌ ์ ์ ํ ์ค๋ช
์ ์๋์ผ๋ก ์์ฑํฉ๋๋ค.
+
+ ๋ํ, `@auto_docstring`์ ํด๋์ค ๋๋ ํจ์๋ฅผ ์ค๋ช
ํ๋ `custom_intro` ์ธ์๋ฅผ ํ์ฉํฉ๋๋ค.
+
+5. ํ
ํ๋ฆฟ ์์คํ
์ ์ฌ์ฉํด ์ด๋ฏธ ์ ์๋ docstring์ Transformers [auto_modules](https://github.com/huggingface/transformers/tree/main/src/transformers/models/auto)์ ์ ๋ณด(`{{processor_class}}` , `{{config_class}}` ๋ฑ)๋ฅผ ๋์ ์ผ๋ก ์ฝ์
ํฉ๋๋ค.
+
+6. ๋ชจ๋ธ์ ์์
๋๋ pipeline ํธํ์ฑ์ ๊ธฐ๋ฐ์ผ๋ก ์ ์ ํ ์ฌ์ฉ ์์๋ฅผ ์ฐพ์ต๋๋ค. ๋ชจ๋ธ์ ๊ตฌ์ฑ ํด๋์ค์์ ์ฒดํฌํฌ์ธํธ ์ ๋ณด๋ฅผ ์ถ์ถํ์ฌ ์ค์ ๋ชจ๋ธ ์๋ณ์๋ฅผ ํฌํจํ ๊ตฌ์ฒด์ ์ธ ์์๋ฅผ ์ ๊ณตํฉ๋๋ค.
+
+7. docstring์ ๋ฐํ ๊ฐ์ ์ถ๊ฐํฉ๋๋ค. `forward`์ ๊ฐ์ ๋ฉ์๋์ ๊ฒฝ์ฐ, ๋ฐ์ฝ๋ ์ดํฐ๋ ๋ฉ์๋์ ๋ฐํ ํ์
์ฃผ์์ ๊ธฐ๋ฐ์ผ๋ก docstring์ `Returns` ํ๋๋ฅผ ์๋์ผ๋ก ์์ฑํฉ๋๋ค.
+
+ ์๋ฅผ ๋ค์ด, ๋ฉ์๋๊ฐ [`~transformers.utils.ModelOutput`] ์๋ธํด๋์ค๋ฅผ ๋ฐํํ๋ ๊ฒฝ์ฐ, `@auto_docstring`์ ํด๋์ค์ Docstring์์ ํ๋ ์ค๋ช
์ ์ถ์ถํ์ฌ ํฌ๊ด์ ์ธ ๋ฐํ ๊ฐ ์ค๋ช
์ ์์ฑํฉ๋๋ค. ํจ์์ docstring์์ ์ฌ์ฉ์ ์ง์ `Returns` ํ๋๋ฅผ ์๋์ผ๋ก ์ง์ ํ ์๋ ์์ต๋๋ค.
+
+8. unpack ์ฐ์ฐ์๋ก ํ์
์ด ์ง์ ๋ kwargs๋ฅผ ํ์ด์ ์ค๋ช
ํฉ๋๋ค. ํน์ ๋ฉ์๋(`UNROLL_KWARGS_METHODS`์ ์ ์๋จ) ๋๋ ํด๋์ค(`UNROLL_KWARGS_CLASSES`์ ์ ์๋จ)์ ๊ฒฝ์ฐ, ๋ฐ์ฝ๋ ์ดํฐ๋ `Unpack[KwargsTypedDict]`๋ก ํ์
์ด ์ง์ ๋ `**kwargs` ํ๋ผ๋ฏธํฐ๋ฅผ ์ฒ๋ฆฌํฉ๋๋ค. `TypedDict`์์ ๋ฌธ์๋ฅผ ์ถ์ถํ์ฌ ๊ฐ ํ๋ผ๋ฏธํฐ๋ฅผ ํจ์์ docstring์ ์ถ๊ฐํฉ๋๋ค.
+
+ ํ์ฌ [`FastImageProcessorKwargs`]๋ง ์ง์ํฉ๋๋ค.
+
+## ๋ชจ๋ฒ ์ฌ๋ก[[best-practices]]
+
+Transformers์ ์ผ๊ด๋๊ณ ์ ์ตํ ๋ฌธ์๋ฅผ ์ ์งํ๋ ๋ฐ ๋์์ด ๋๋๋ก ๋ค์ ๋ชจ๋ฒ ์ฌ๋ก๋ฅผ ๋ฐ๋ฅด์ธ์!
+
+* ์๋ก์ด PyTorch ๋ชจ๋ธ ํด๋์ค ([`PreTrainedModel`] ์๋ธํด๋์ค) ๋ฐ `forward` ๋๋ `get_text_features`์ ๊ฐ์ ๊ธฐ๋ณธ ๋ฉ์๋์ `@auto_docstring`์ ์ฌ์ฉํ์ธ์.
+* ํด๋์ค์ ๊ฒฝ์ฐ, `@auto_docstring`์ `__init__` ๋ฉ์๋์ docstring์์ ํ๋ผ๋ฏธํฐ ์ค๋ช
์ ๊ฐ์ ธ์จ๋ค๋ ์ ์ ๊ธฐ์ตํ์ธ์.
+* ํ์ค docstring์ ์ฐ์ ์ฌ์ฉํ๊ณ , ๋ชจ๋ธ์ ๋์์ด ๋ค๋ฅธ ๊ฒฝ์ฐ์๋ง ๊ณตํต ์ธ์๋ฅผ ์ฌ์ ์ํ์ธ์.
+* ์๋ก์ด ์ธ์๋ ์ฌ์ฉ์ ์ง์ ์ธ์๋ ๋ช
ํํ๊ฒ ๋ฌธ์ํํ์ธ์.
+* ๋ณ๊ฒฝ ์ฌํญ์ ์ปค๋ฐํ๊ธฐ ์ ์ `check_docstrings` ๋ฅผ ๋ก์ปฌ์์ ๋ฐ๋ณต์ ์ผ๋ก ์คํํ์ฌ ํ์ธํ์ธ์.