Improve modular transformers documentation (#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 <joel@bitcrowd.net>
This commit is contained in:
Joel Koch 2024-12-20 18:16:02 +01:00 committed by GitHub
parent 504c4d3692
commit c96cc039c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,6 +22,9 @@ etc. Model contribution PRs rarely add less than 3-5k lines of code, with much o
This raises the bar for contributions, and with Modular Transformers, we're aiming to lower the bar to a much more
acceptable point.
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).
For any kind of contributions, see [CONTRIBUTING.md](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md).
## What is it?
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.
### Details
To generate a single file from the modular file, run the following command.
```bash
python utils/modular_model_converter.py --files-to-parse src/transformers/models/<your_model>/modular_<your_model>.py
```
The "linter", which unravels the inheritance and creates all single-files from the modular file, will flatten the
inheritance while trying to be invisible to Python users. At this time, the linter flattens a **single** level of
inheritance.
@ -59,7 +68,11 @@ file, and the corresponding files will be created for you.
### Enforcement
[TODO] We are introducing a new test, that makes sure the generated content matches what is present in the `modular_xxxx.py`
Run the command below to ensure the generated content matches `modular_<your_model>.py`
```bash
python utils/check_modular_conversion.py --files src/transformers/models/<your_model>/modular_<your_model>.py
```
### Examples
@ -194,4 +207,4 @@ We now also support special cases like
class GemmaVisionModel(CLIPModel):
pass
```
where the name of your class `GemmaVision` is not the same as the modular `Gemma`. This is super useful for composite models.
where the name of your class `GemmaVision` is not the same as the modular `Gemma`. This is super useful for composite models.