You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to convert tokenizer of SmolLM model as accepted by executorch #6813
module: extensionIssues related to code under extension/module: user experienceIssues related to reducing friction for userstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
Hi,
I am trying to convert SmolLm-135M-Instruct model to .pte format and then run on an android device.
I have been successful in converting the model but executorch requires the tokenizer in either .bin format or .model format which can then be converted into .bin format. But on huggingface tokenizer.model or tokenizer.bin files are not present.
How would I go about converting the tokenizer.json file into the appropriate format.
I tried it a while ago. tokenizer.save_pretrained will save the json format, even with legacy=Trueit doesn't save to the format that can be accepted by the llama_runner. I was trying to use the tokenizers.save for the convention as shown below, which is WIP and I haven't got a chance to back on it
import os
import argparse
from tokenizers import Tokenizer
from tokenizers.models import BPE
from tokenizers.pre_tokenizers import Whitespace
def create_tokenizer_model(input_dir, output_file):
vocab_file = os.path.join(input_dir, "vocab.json")
merges_file = os.path.join(input_dir, "merges.txt")
# Create BPE model from files
bpe = BPE.from_file(vocab_file, merges_file)
# Create tokenizer
tokenizer = Tokenizer(bpe)
# Set pre-tokenizer
tokenizer.pre_tokenizer = Whitespace()
# Save the tokenizer model
tokenizer.save(output_file)
print(f"Tokenizer model saved to {output_file}")
# Verify the tokenizer
loaded_tokenizer = Tokenizer.from_file(output_file)
test_text = "Hello, world! This is a test."
encoded = loaded_tokenizer.encode(test_text)
decoded = loaded_tokenizer.decode(encoded.ids)
print(f"Test encoding/decoding: '{test_text}' -> '{decoded}'")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Create a tokenizer")
parser.add_argument("--input_dir", help="Directory containing vocab.json and merges.txt")
parser.add_argument("--output", default="tokenizer.model", help="Output file name (default: tokenizer.model)")
args = parser.parse_args()
create_tokenizer_model(args.input_dir, args.output)
module: extensionIssues related to code under extension/module: user experienceIssues related to reducing friction for userstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
Activity
larryliu0820 commentedon Nov 13, 2024
@guangy10 do you know the answer to this?
guangy10 commentedon Nov 13, 2024
I tried it a while ago.
tokenizer.save_pretrainedwill save the json format, even withlegacy=Trueit doesn't save to the format that can be accepted by the llama_runner. I was trying to use thetokenizers.savefor the convention as shown below, which is WIP and I haven't got a chance to back on itArpit2601 commentedon Nov 14, 2024
Thanks @guangy10 for sharing your WIP script - I tried iterating on it but it would be great if you can share some pointers to get it working.
guangy10 commentedon Nov 14, 2024
Will keep you posted when I get back to this work
shirishgone commentedon Jan 13, 2025
So as of today, LlamaRunner only runs Llama models.
Are there any steps on how to run other models like Qwen 0.5 model or others.
arjunsingri commentedon Jan 31, 2025
@Arpit2601
Were you successful in getting it to work on executorch? If yes, are you able to share the steps.
nil-is-all commentedon Dec 18, 2025
Hi @guangy10, has this issue been resolved?