You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
custom_parameter (`type`, *optional*, defaults to `default_value`):
88
-
A concise description for custom_parameter if not defined or overriding the description in `args_doc.py`.
88
+
A concise description for custom_parameter if not defined or overriding the description in `auto_docstring.py`.
89
89
internal_helper_arg (`type`, *optional*, defaults to `default_value`):
90
-
A concise description for internal_helper_arg if not defined or overriding the description in `args_doc.py`.
90
+
A concise description for internal_helper_arg if not defined or overriding the description in `auto_docstring.py`.
91
91
"""
92
92
# ...
93
93
```
94
94
95
+
You should also use the `@auto_docstring` decorator for classes that inherit from [`~utils.ModelOutput`].
96
+
97
+
```python
98
+
@dataclass
99
+
@auto_docstring(
100
+
custom_intro="""
101
+
Custom model outputs with additional fields.
102
+
"""
103
+
)
104
+
classMyModelOutput(ImageClassifierOutput):
105
+
r"""
106
+
loss (`torch.FloatTensor`, *optional*):
107
+
The loss of the model.
108
+
custom_field (`torch.FloatTensor` of shape `(batch_size, hidden_size)`, *optional*):
109
+
A custom output field specific to this model.
110
+
"""
111
+
112
+
# Standard fields like hidden_states, logits, attentions etc. can be automatically documented if the description is the same as the standard arguments.
113
+
# However, given that the loss docstring is often different per model, you should document it in the docstring above.
# Custom fields need to be documented in the docstring above
119
+
custom_field: Optional[torch.FloatTensor] =None
120
+
```
121
+
95
122
</hfoption>
96
123
<hfoptionid="functions">
97
124
@@ -171,7 +198,7 @@ class MyModel(PreTrainedModel):
171
198
172
199
There are some rules for documenting different types of arguments and they're listed below.
173
200
174
-
- Standard arguments (`input_ids`, `attention_mask`, `pixel_values`, etc.) are defined and retrieved from `args_doc.py`. It is the single source of truth for standard arguments and should not be redefined locally if an argument's description and shape is the same as an argument in `args_doc.py`.
201
+
- Standard arguments (`input_ids`, `attention_mask`, `pixel_values`, etc.) are defined and retrieved from `auto_docstring.py`. It is the single source of truth for standard arguments and should not be redefined locally if an argument's description and shape is the same as an argument in `auto_docstring.py`.
175
202
176
203
If a standard argument behaves differently in your model, then you can override it locally in a `r""" """` block. This local definition has a higher priority. For example, the `labels` argument is often customized per model and typically requires overriding.
177
204
@@ -245,15 +272,15 @@ When working with modular files (`modular_model.py`), follow the guidelines belo
245
272
The `@auto_docstring` decorator automatically generates docstrings by:
246
273
247
274
1. Inspecting the signature (arguments, types, defaults) of the decorated class' `__init__` method or the decorated function.
248
-
2. Retrieving the predefined docstrings for common arguments (`input_ids`, `attention_mask`, etc.) from internal library sources like [`ModelArgs`], [`ImageProcessorArgs`], and the `args_doc.py` file.
275
+
2. Retrieving the predefined docstrings for common arguments (`input_ids`, `attention_mask`, etc.) from internal library sources like [`ModelArgs`], [`ImageProcessorArgs`], and the `auto_docstring.py` file.
249
276
3. Adding argument descriptions in one of two ways as shown below.
250
277
251
278
| method | description | usage |
252
279
|---|---|---|
253
280
|`r""" """`| add custom docstring content directly to a method signature or within the `__init__` docstring | document new arguments or override standard descriptions |
254
281
|`custom_args`| add custom docstrings for specific arguments directly in `@auto_docstring`| define docstring for new arguments once if they're repeated in multiple places in the modeling file |
255
282
256
-
4. Adding class and function descriptions. For model classes with standard naming patterns, like `ModelForCausalLM`, or if it belongs to a pipeline, `@auto_docstring` automatically generates the appropriate descriptions with `ClassDocstring` from `args_doc.py`.
283
+
4. Adding class and function descriptions. For model classes with standard naming patterns, like `ModelForCausalLM`, or if it belongs to a pipeline, `@auto_docstring` automatically generates the appropriate descriptions with `ClassDocstring` from `auto_docstring.py`.
257
284
258
285
`@auto_docstring` also accepts the `custom_intro` argument to describe a class or function.
"Some docstrings are redundant with the ones in `args_doc.py` and will be removed. Run `make fix-copies` or `python utils/check_docstrings.py --fix_and_overwrite` to remove the redundant docstrings."
1490
+
"Some docstrings are redundant with the ones in `auto_docstring.py` and will be removed. Run `make fix-copies` or `python utils/check_docstrings.py --fix_and_overwrite` to remove the redundant docstrings."
1491
1491
)
1492
1492
print(f"🚨 Redundant docstring for the following arguments in {candidate_file}:")
0 commit comments