Skip to content

Commit c96cc03

Browse files
authored
Improve modular transformers documentation (huggingface#35322)
* Improve modular transformers documentation - Adds hints to general contribution guides - Lists which utils scripts are available to generate single-files from modular files and check their content * Show commands in copyable code cells --------- Co-authored-by: Joel Koch <[email protected]>
1 parent 504c4d3 commit c96cc03

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

docs/source/en/modular_transformers.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ etc. Model contribution PRs rarely add less than 3-5k lines of code, with much o
2222
This raises the bar for contributions, and with Modular Transformers, we're aiming to lower the bar to a much more
2323
acceptable point.
2424

25+
If you plan to add a model to `transformers` make sure you read [How to add a model to 🤗 Transformers?](https://huggingface.co/docs/transformers/add_new_model).
26+
For any kind of contributions, see [CONTRIBUTING.md](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md).
27+
2528
## What is it?
2629

2730
Modular Transformers introduces the concept of a "modular" file to a model folder. This modular file accepts code
@@ -43,6 +46,12 @@ be moved to the new Modular Transformers format in the coming months.
4346

4447
### Details
4548

49+
To generate a single file from the modular file, run the following command.
50+
51+
```bash
52+
python utils/modular_model_converter.py --files-to-parse src/transformers/models/<your_model>/modular_<your_model>.py
53+
```
54+
4655
The "linter", which unravels the inheritance and creates all single-files from the modular file, will flatten the
4756
inheritance while trying to be invisible to Python users. At this time, the linter flattens a **single** level of
4857
inheritance.
@@ -59,7 +68,11 @@ file, and the corresponding files will be created for you.
5968

6069
### Enforcement
6170

62-
[TODO] We are introducing a new test, that makes sure the generated content matches what is present in the `modular_xxxx.py`
71+
Run the command below to ensure the generated content matches `modular_<your_model>.py`
72+
73+
```bash
74+
python utils/check_modular_conversion.py --files src/transformers/models/<your_model>/modular_<your_model>.py
75+
```
6376

6477
### Examples
6578

@@ -194,4 +207,4 @@ We now also support special cases like
194207
class GemmaVisionModel(CLIPModel):
195208
pass
196209
```
197-
where the name of your class `GemmaVision` is not the same as the modular `Gemma`. This is super useful for composite models.
210+
where the name of your class `GemmaVision` is not the same as the modular `Gemma`. This is super useful for composite models.

0 commit comments

Comments
 (0)