![]() * refactor LlamaAttention * minimal changes * fix llama * update * modular gemmas * modular nits * modular updates * nits * simplify * gpt2 * more modualr and fixes * granite * modular modular modular * nits * update * qwen2 + starcoder2 * mostly gemma2 * Update image_processing_auto.py * fix * Update modular_starcoder2.py * fix * remove all copied from attentions * remove gcv * make fix-copies * oups * oups2.0 * fix some modulars + all copied from * should be good now * revert unwanted changes * Update modeling_decision_transformer.py * finish cleanup * Update modeling_olmo.py * consistency * re-add gradient checkpointing attribute * fix * style * make config necessary * bis * bis * Update modeling_my_new_model2.py * is_causal attr * fix * remove past kv return from decoder layer * fix * default rope config * correctly fix rope config * fix bias * fix gpt2 attention output * fix test * fix inits * fix default sdpa * fix default sdpa implementation * harmonize classes * fix mistral * fix sliding window models * mixtral * be more explicit * style * fix * several fixes * Update modeling_dbrx.py * fix test * olmo + phi * rotary * syle * phi * phi again * again * kwargs * Update test_modeling_common.py * skip fx tracing tests * Update modeling_utils.py * gemma 2 * again * Update modeling_recurrent_gemma.py * gemma2 * granite * style * starcoder * Update sdpa_attention.py * switch args * Update modeling_mllama.py * fix * cache type tests * gpt2 * Update test_modeling_common.py * fix * consistency * fix shape with encoder * should be the last one * tests non model * most comments * small oupsi * be more explicit in modulars * more explicit modulars * CIs! it works locally * add kwargs to _flash_attention_forward --------- Co-authored-by: Cyril Vallez <cyril.vallez@gmail.com> |
||
---|---|---|
.. | ||
configuration_dummy.py | ||
configuration_my_new_model.py | ||
configuration_my_new_model2.py | ||
configuration_new_model.py | ||
configuration_super.py | ||
convert_examples.sh | ||
image_processing_new_imgproc_model.py | ||
modeling_dummy_bert.py | ||
modeling_dummy.py | ||
modeling_from_uppercase_model.py | ||
modeling_multimodal1.py | ||
modeling_multimodal2.py | ||
modeling_my_new_model2.py | ||
modeling_new_task_model.py | ||
modeling_roberta.py | ||
modeling_super.py | ||
modular_dummy_bert.py | ||
modular_dummy.py | ||
modular_from_uppercase_model.py | ||
modular_multimodal1.py | ||
modular_multimodal2.py | ||
modular_my_new_model.py | ||
modular_my_new_model2.py | ||
modular_new_imgproc_model.py | ||
modular_new_model.py | ||
modular_new_task_model.py | ||
modular_roberta.py | ||
modular_super.py | ||
README.md |
Using the modular_converter
linter
pip install libcst
is a must!
sh examples/modular-transformers/convert_examples.sh
to get the converted outputs
The modular converter is a new linter
specific to transformers
. It allows us to unpack inheritance in python to convert a modular file like modular_gemma.py
into a single model single file
.
Examples of possible usage are available in the examples/modular-transformers
, or modular_gemma
for a full model usage.
python utils/modular_model_converter.py --files_to_parse "/Users/arthurzucker/Work/transformers/examples/modular-transformers/modular_my_new_model2.py"
How it works
We use the libcst
parser to produce an AST representation of the modular_xxx.py
file. For any imports that are made from transformers.models.modeling_xxxx
we parse the source code of that module, and build a class dependency mapping, which allows us to unpack the modularerence dependencies.
The code from the modular
file and the class dependency mapping are "merged" to produce the single model single file.
We use ruff to automatically remove the potential duplicate imports.
Why we use libcst instead of the native AST?
AST is super powerful, but it does not keep the docstring
, comment
or code formatting. Thus we decided to go with libcst