[WIP] Add Tokenizer for MyT5 Model
Author: tomlimi
Pull request: yes

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes #31260 


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [X] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [x] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [x] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker and @younesbelkada
- vision models: @amyeroberts
- speech models: @sanchit-gandhi
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @SunMarc

Integrations:

- deepspeed: HF Trainer/Accelerate: @muellerzr
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc and @younesbelkada

Documentation: @stevhliu and @MKhalusova

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


Comments:
cc @ArthurZucker @itazap 

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_31286). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

The implementation is ready. I wrote a simple unittest to check the functionality of the tokenizer, but it makes two ci tests fail with the error, saying that tested `Tomlim/myt5-base` is not a valid model handle, even though it is public at: 
https://huggingface.co/Tomlim/myt5-base

```
E   OSError: Tomlim/myt5-base is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'
E   If this is a private repository, make sure to pass a token having permission to this repo either by logging in with huggingface-cli login or by passing token=<your_token> 
```



Alright! cc @itazap if you can do a first pass! 

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

Sorry for late reply, I pushed the changes addressing the comments in the review. Can this PR be still re-opened?
Thank you!

Thanks for applying the feedback! Looks good, please update with changes from main and address the minor CI failures (+ ruff reformat)! Otherwise LGTM 🤗 

I fixed most of CLI errors, unfortunately the issue with run_tests still persitsts. It raises the error, saying that tested Tomlim/myt5-base is not a valid model handle, even though it is public at https://huggingface.co/Tomlim/myt5-base (I also had this problem with earlier version from June 6). Could it be caused by the way unittest class is declared?

```
E   OSError: Tomlim/myt5-base is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'
```

I fixed the issue with loading the model by changing the `MyT5TokenizationTest` class, and all the added tests remained unchanged. I also added a sample "vocabulary" file to `fixtures` so the tokenizer can be loaded from it. 

I see that one test fails in CI, but it is in `DPTModelTest` and is unrelated to the changed code.

Thank you from prompt reply! Please let me know if there are any other changes or tests that should be added before merging!

There might be a couple of minor conflicts to resolve!

The conflict was caused by another model being added in the meantime. I resolved it and merged the new changes from the main 🙂.

@itazap @ArthurZucker can this PR be merged? I recently presented MyT5 at ACL and expect increased interest in the model (tokenizer) in the upcoming time. Thanks!

Thank you for the review, @ArthurZucker. I added a short description of the method in the model doc and added the missing "Copied from statements". To address the other points:

1. Added tokens conversion to bytes. Actually, in `myt5_tokenizer` we do not use `added_tokens` . Morphemes are rewritten using the original vocabulary of 256 bytes,  MYTE is a rewriting method that does not require additional tokens. I kept the support of `added_tokens` in case someone would like to extend the vocabulary in their instance of the tokenizer.

2. `byte_map.json` in the hub. It is already there ([Tomlim/myt5-base](https://huggingface.co/Tomlim/myt5-base)). In the testing class, I used the vocab file from `fixtures` as it is done, e.g., in T5. I had tried to load it from the hub, but it did not work for me (I described an error in a comment a month ago). 

I think this looks good, let's rebase and merge WDYT? 🤗 

Thank you! I merged the updates from the main to the branch and pushed an empty commit with `run-slow` as instructed by the bot 🤖. I see some tests are failing but they are not related to the added code.

Oups, `Tomlim/myt5-base` seems private! Could you make it public? CIs are failing because of this!

The model is already public. I had this issue with test suite claiming that it was private before, see this [comment](https://github.com/huggingface/transformers/pull/31286#issuecomment-2301458035) from August. 

That was way I tried solving it bt adding tokenization files to `fixtures`, which I have already removed. 

Okay I'll have a look! 

<img width="684" alt="image" src="https://github.com/user-attachments/assets/fb48aed8-1d09-4fc3-8783-36a7b2867989">
Works for me, merging!

Thanks for the contribution! 🤗