Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Umt5] Add google's umt5 to transformers #24477

Merged
merged 85 commits into from
Jul 3, 2023

Conversation

ArthurZucker
Copy link
Collaborator

@ArthurZucker ArthurZucker commented Jun 26, 2023

What does this PR do?

Superseeds #22626 which has been stale for quite some time

A kaggle notebook for reproducing and running the originial model:
https://www.kaggle.com/arthurzucker/umt5-inference

  • Tokenizer is a BertGenerationTokenizer. Here is how to convert it:
!wget https://storage.googleapis.com/t5-data/vocabs/umt5.256000/sentencepiece.model
from transformers import T5Tokenizer

umt5 = T5Tokenizer("/Users/arthurzucker/Work/transformers/sentencepiece.model")
to_add = []
for i in range(300):
    to_add.append(f"<extra_id_{i}>")
tokenizer.add_tokens(list(reversed(to_add)), True)  

84 tokens are free to use apparently.

  • The modeling code is just MT5, addapted to have more relative bias that is not the same for all layers.
    For a first conversion I'll be using this:
python src/transformers/models/t5/convert_t5x_checkpoint_to_pytorch.py --t5x_checkpoint_path "/Users/arthurzucker/Work/transformers/checkpoint_1000000" --config_file "/Users/arthurzucker/Work/transformers/checkpoint_1000000/config.json" --pytorch_dump_path ./ArthurZ --scalable_attention

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 26, 2023

The documentation is not available anymore as the PR was closed or merged.

@ArthurZucker ArthurZucker changed the title [Umt5] Add googl's umt5 to transformesr [Umt5] Add google's umt5 to transformers Jun 26, 2023
@stefan-it
Copy link
Collaborator

Hi @ArthurZucker , thanks for updating this! As far as we can tell, it is not just mT5, because of joined/separate key-value in attention. Was this problem solved in latest conversion script of this PR 🤔

/cc @agemagician

@ArthurZucker
Copy link
Collaborator Author

The conversion went well, the outputs are still a bit gibberish but didn’t have problem of un matching shape.
They mentioned that the model is closer to MT5, which is why if we we can have minimal changes, it will look like this + adapted conversion

@agemagician
Copy link
Contributor

The conversion went well, the outputs are still a bit gibberish but didn’t have problem of un matching shape. They mentioned that the model is closer to MT5, which is why if we we can have minimal changes, it will look like this + adapted conversion

So far, I can see you made similar changes as we did before, which led to gibberish output.
The one addition change you did is allowing fall back to byte for the tokenizer.

I belive the issue still exist because of the way we reshape and convert the q,k and v for the attention as @stefan-it mentioned.

@ArthurZucker
Copy link
Collaborator Author

There is also a different logic for postion_bias which seems to be missing.
Joint 3D matrix vs what we have now can be linked to the new sharding scheme, It probably the last thing to check.

@ArthurZucker
Copy link
Collaborator Author

ArthurZucker commented Jun 27, 2023

Regarding the split / merge, I don't really see a problem with the code. The checkpoints are split, and the actual code is similar to mt5 with the difference being scanning I believe. However feel free to check and I hope we can get coherent outputs!

@ArthurZucker
Copy link
Collaborator Author

Update, the outputs match 🔥 The issue was : the tokenizer

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the modeling file. Have a couple more nits.

docs/source/en/model_doc/umt5.md Outdated Show resolved Hide resolved
src/transformers/models/umt5/modeling_umt5.py Outdated Show resolved Hide resolved
src/transformers/models/umt5/modeling_umt5.py Outdated Show resolved Hide resolved
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
@ArthurZucker
Copy link
Collaborator Author

Currently setting up an instance ton convert an upload the xxl model, other models are available here

@ArthurZucker ArthurZucker merged commit 799df10 into huggingface:main Jul 3, 2023
@long21wt long21wt mentioned this pull request Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants