# Convert slow XLMRobertaTokenizer to fast one

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fconvert-slow-xlmrobertatokenizer-to-fast-one%2F20876%3E%5C
**Category:** 🤗Transformers\
**Created:** [July 26, 2022, 8:47am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fconvert-slow-xlmrobertatokenizer-to-fast-one%2F20876 "2022-07-26T08:47:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnielsr)%5C
**Post date:** [July 26, 2022, 8:47am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fconvert-slow-xlmrobertatokenizer-to-fast-one%2F20876%2F1 "2022-07-26T08:47:08Z")

</div>

Posting a question I had which @SaulLu answered 😃 suppose you have a repo on the hub that only has slow tokenizer files, and you want to be able to load a fast tokenizer. Here’s how to do that:

```auto
!pip install -q transformers sentencepiece

model_name = "naver-clova-ix/donut-base-finetuned-docvqa"

from transformers import XLMRobertaTokenizerFast

tokenizer = XLMRobertaTokenizerFast.from_pretrained(model_name, from_slow=True)

tokenizer.save_pretrained("fast_tok", legacy_format=False)

```

---

<div class="post-metadata">

**Author:** ![ahmedlone123](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ahmedlone123](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fahmedlone123)%5C
**Post date:** [January 24, 2023, 12:20pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fconvert-slow-xlmrobertatokenizer-to-fast-one%2F20876%2F2 "2023-01-24T12:20:45Z")

</div>

hey @nielsr@SaulLu , Thank you for this but what if you have fast tokenizers and you want to conver them to slow tokenizers? I am thinking that somehow you could parse the .json (when saving a fast tokenizer) and create the sentencpeice model you need for slow tokenizers from the json. what do you think?

---

<div class="post-metadata">

**Author:** ![abdul-r17](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@abdul-r17](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fabdul-r17)%5C
**Post date:** [June 15, 2024, 10:56am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fconvert-slow-xlmrobertatokenizer-to-fast-one%2F20876%2F3 "2024-06-15T10:56:47Z")

</div>

Hi @nielsr@ahmedlone123 , I want to convert a slow tokenizer (LlamaTokenizer) to a fast one (LlamaTokenizerFast), without losing the legacy behaviour i.e, it should not append a dummy prefix “\_” in front of the sentence. It works fine with LlamaTokenizer, but when I load the same tokenizer using LlamaTokenizerFast, this behaviour is lost. How to retain the default behaviour of LlamaTokenizer (not adding a dummy prefix) in fast tokenizer?

---

<div class="post-metadata">

**Author:** ![itazap](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@itazap](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fitazap)%5C
**Post date:** [August 26, 2024, 5:36pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fconvert-slow-xlmrobertatokenizer-to-fast-one%2F20876%2F4 "2024-08-26T17:36:34Z")

</div>

Hi @abdul-r17 . Both slow and fast Llama add a dummy prefix. This can be controlled with the `add_prefix_space=False` parameter which you can set on the model before you save or when loading the tokenizer:

```auto
tokenizer = LlamaTokenizer.from_pretrained(model, add_prefix_space=False)
tokenizer.save_pretrained(temp_folder)
LlamaTokenizerFast.from_pretrained(temp_folder)

```

or when loading:

```auto
tokenizer = LlamaTokenizer.from_pretrained(model)
tokenizer.save_pretrained(temp_folder)
LlamaTokenizerFast.from_pretrained(temp_folder, add_prefix_space=False)

```

Hope that works in your use case! 😄
