VLM: special multimodal Tokenizer#34461
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
Should be ready for review @ArthurZucker ! I think we'll support simple non-multimodal tokenizers for quite a while in VLMs, no idea yet how/when to make this a new default |
ArthurZucker
left a comment
There was a problem hiding this comment.
Okay super super good! The only thing I don't like is the is_multimodal!
I think what you added gives a lot of freedom to all tokenizers -> audio_cls_token or anything that ends with token / ends with id will be properly processed!
Let's remove the is_mulitmodal and should be good!
| tokenizer = AutoTokenizer.from_pretrained(model_id) | ||
| tokenizer.extra_special_tokens = ["image_token", "boi_token", "eoi_token"] |
There was a problem hiding this comment.
| tokenizer = AutoTokenizer.from_pretrained(model_id) | |
| tokenizer.extra_special_tokens = ["image_token", "boi_token", "eoi_token"] | |
| tokenizer = AutoTokenizer.from_pretrained(model_id, extra_special_tokens = ["image_token", "boi_token", "eoi_token"]) |
There was a problem hiding this comment.
let's add a small test for this
There was a problem hiding this comment.
yes, this is actually not correct anymore hehe, forgot to update the docs. And it has a test for that already so we are good
new way of adding extra special tokens is like
tokenizer.extra_special_tokens = {"eoi_token": "<s>", "image_token": "<image>"}. After adding this line and saving the tokenizer, loading back will do the magic and tokenizer will have self.image_token attribute
There was a problem hiding this comment.
we should be able to pass it as input as well instead of forcing people to use the setter! 🤗
There was a problem hiding this comment.
yeap, realized later and added that in the docs instead of "saving-loading back". Plus extended the test
Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
| super().__init__(**kwargs) | ||
|
|
||
| self.extra_special_tokens = kwargs.pop("extra_special_tokens", {}) | ||
| self._set_model_specific_special_tokens(special_tokens=self.extra_special_tokens) |
There was a problem hiding this comment.
when we do this, we don't add them to the tokenizer vocab right?
There was a problem hiding this comment.
I think you are already checking that these tokens are added to the vocab if not already present right?
There was a problem hiding this comment.
if the special token is not present in the vocab, we do add them as new tokens to the tokenizer vocab. Should we prevent users from adding new tokens and allow to use only available tokens?
It happens because the Tokenizer initially is wired to do that, irrespective of current changes
# 4. If some of the special tokens are not part of the vocab, we add them, at the end.
# the order of addition is the same as self.SPECIAL_TOKENS_ATTRIBUTES following `tokenizers`
There was a problem hiding this comment.
NO it's alright IMO we have not really seen reports about that
* kinda works * update * add tests * update * use special tokens in processors * typo * fix copies * fix * fix moshi after rebase * update * fix tests * update * Update docs/source/en/main_classes/tokenizer.md Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * update docs * test for load time adding tokens * fix some more tests which are now fetched better * one more fix --------- Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
* kinda works * update * add tests * update * use special tokens in processors * typo * fix copies * fix * fix moshi after rebase * update * fix tests * update * Update docs/source/en/main_classes/tokenizer.md Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * update docs * test for load time adding tokens * fix some more tests which are now fetched better * one more fix --------- Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
What does this PR do?
Part of Major VLM standardization (#33948). We will have special tokens that are present in all VLMs to be part if
XXXTokenizerattributes. This will make our lives easier when doing several processing manipulations and/or formatting the prompt manually, as we can simply callself.tokenizer.image_token.Currently if we need any of VLM special tokens, those are saved in processor config, but not all models save it since not all models use it when calling the processor. After this PR I'll go over models and clean up the processing code given the changes. But we might still have to support old way, because we can't change stuff if that can break loading configs from the hub