dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
8.92k stars 1.86k forks source link

[Tokenizers] Port CLIP Tokenizer #6993

Open ericstj opened 4 months ago

ericstj commented 4 months ago

Port CLIP tokenizer which leverages byte-level BPE. This tokenizer enables scenarios like StableDiffusion

May be dependent on https://github.com/dotnet/machinelearning/issues/6992.

Reference: https://huggingface.co/docs/transformers/main/en/model_doc/clip https://github.com/huggingface/transformers/blob/0549000c5bf6c7249f411917f2a6f0b6d0f06da1/src/transformers/models/codegen/tokenization_codegen.py#L98 https://onnxruntime.ai/docs/tutorials/csharp/stable-diffusion-csharp.html#tokenization-with-onnx-runtime-extensions

Paper: https://arxiv.org/abs/2103.00020 https://arxiv.org/pdf/2103.00020.pdf

ericstj commented 3 months ago

Note - ONNX sample doesn't require separate tokenizer.

@LittleLittleCloud might need this for a solution that works with torchsharp.