diff --git a/cmake/ext_ortlib.cmake b/cmake/ext_ortlib.cmake index 49dd05c8a..53fe00932 100644 --- a/cmake/ext_ortlib.cmake +++ b/cmake/ext_ortlib.cmake @@ -34,7 +34,7 @@ else() if (OCOS_ONNXRUNTIME_VERSION) set(ONNXRUNTIME_VER ${OCOS_ONNXRUNTIME_VERSION}) else() - set(ONNXRUNTIME_VER "1.17.1") + set(ONNXRUNTIME_VER "1.19.2") # need to check if android package of this version is available too. endif() if (ANDROID) diff --git a/include/ort_c_to_cpp.h b/include/ort_c_to_cpp.h index a10618ae8..5d26a5831 100644 --- a/include/ort_c_to_cpp.h +++ b/include/ort_c_to_cpp.h @@ -395,7 +395,7 @@ inline bool IsScalarOr1ElementVector(size_t num_dimensions, int64_t shape_size) return false; } -#define ORTX_RETURN_IF_ERROR(expr) \ +#define ORTW_RETURN_IF_ERROR(expr) \ do { \ auto _status = (expr); \ if (_status != nullptr) { \ diff --git a/include/ortx_tokenizer.h b/include/ortx_tokenizer.h index 9558d1e77..e51a5bd5f 100644 --- a/include/ortx_tokenizer.h +++ b/include/ortx_tokenizer.h @@ -29,8 +29,8 @@ struct OrtxTokenizerBlob { #ifdef __cplusplus OrtxTokenizerBlob(const std::string_view& config_json_blob, const std::string_view& vocab_json_blob, - const std::string_view& token_module_blob, - const std::string_view& raw_model_blob) + const std::string_view& token_module_blob = {}, + const std::string_view& raw_model_blob = {}) : config_json_blob(config_json_blob.data()), vocab_json_blob(vocab_json_blob.data()), token_module_blob(token_module_blob.data()), raw_model_blob(raw_model_blob.data()), config_blob_len(config_json_blob.size()), diff --git a/include/ortx_utils.h b/include/ortx_utils.h index 59f101347..240874c30 100644 --- a/include/ortx_utils.h +++ b/include/ortx_utils.h @@ -37,6 +37,14 @@ typedef OrtxObject OrtxTensorResult; // C, instead of C++ doesn't cast automatically, // so we need to use a macro to cast the object to the correct type #define ORTX_DISPOSE(obj) OrtxDispose((OrtxObject**)&obj) +#define ORTX_RETURN_IF_ERROR(expr) \ + do { \ + auto _status = (expr); \ + if (!_status.IsOk()) { \ + return _status; \ + } \ + } while (0) + typedef uint32_t extTokenId_t; diff --git a/onnxruntime_extensions/_cuops.py b/onnxruntime_extensions/_cuops.py index 8d0cf3bd8..6be03a9b2 100644 --- a/onnxruntime_extensions/_cuops.py +++ b/onnxruntime_extensions/_cuops.py @@ -491,6 +491,16 @@ def get_outputs(cls): ] +class HfJsonTokenizer(CustomOp): + @classmethod + def get_inputs(cls): + return [cls.io_def('str', onnx_proto.TensorProto.STRING, ['N'])] + + @classmethod + def get_outputs(cls): + return [cls.io_def("ids", onnx.TensorProto.INT64, ['N', None])] + + # TODO: have a C++ impl. def _argsort_op(x, dim): d = numpy.argsort(x, dim) @@ -544,4 +554,4 @@ def build_graph(cls, op_class, *args, **kwargs): @staticmethod def get_op_class(op_type): - return globals()[op_type] + return globals()[op_type] \ No newline at end of file diff --git a/onnxruntime_extensions/cvt.py b/onnxruntime_extensions/cvt.py index 820964155..307bffabb 100644 --- a/onnxruntime_extensions/cvt.py +++ b/onnxruntime_extensions/cvt.py @@ -12,6 +12,24 @@ from ._hf_cvt import HFTokenizerConverter, HFTokenizerOnnxGraph # noqa from ._ortapi2 import make_onnx_model, SingleOpGraph +import os +import numpy as np +import tempfile +import shutil + +# edit environment variables to avoid protobuf version mismatch +os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python" + +from transformers.convert_slow_tokenizer import SpmConverter # noqa: E402 +from transformers import AutoTokenizer # noqa: E402 +from tokenizers import decoders, normalizers, pre_tokenizers, Regex # noqa: E402 + + +OrtxTokenizer = None +try: + from onnxruntime_extensions.pp_api import Tokenizer as OrtxTokenizer +except ImportError: + pass _is_torch_available = False try: @@ -24,11 +42,150 @@ _PRE_POST_PAIR = {'TrieTokenizer': "TrieDetokenizer"} +def _get_prepend_scheme(add_prefix_space: bool, original_tokenizer) -> str: + if add_prefix_space: + prepend_scheme = "always" + if not getattr(original_tokenizer, "legacy", True): + prepend_scheme = "first" + else: + prepend_scheme = "never" + return prepend_scheme + + +class Baichuan2Converter(SpmConverter): + handle_byte_fallback = True + + def __init__(self, original_tokenizer): + super().__init__(original_tokenizer) + original_tokenizer.add_prefix_space = False + + def vocab(self, proto): + vocab = [ + (self.original_tokenizer.convert_ids_to_tokens(0), 0.0), + (self.original_tokenizer.convert_ids_to_tokens(1), 0.0), + (self.original_tokenizer.convert_ids_to_tokens(2), 0.0), + ] + vocab += [(piece.piece, piece.score) for piece in proto.pieces[3:]] + return vocab + + def unk_id(self, proto): + unk_id = 0 + return unk_id + + def decoder(self, replacement, add_prefix_space): + sequence = [ + decoders.Replace("▁", " "), + decoders.ByteFallback(), + decoders.Fuse(), + ] + if add_prefix_space: + sequence += [decoders.Strip(content=" ", left=1)] + return decoders.Sequence(sequence) + + def normalizer(self, proto): + if getattr(self.original_tokenizer, "legacy", True): + sequence = [] + if getattr(self.original_tokenizer, "add_prefix_space", True): + sequence += [normalizers.Prepend(prepend="▁")] + sequence += [normalizers.Replace(pattern=" ", content="▁")] + return normalizers.Sequence(sequence) + return None # non-legacy, no normalizer + + def pre_tokenizer(self, replacement, add_prefix_space): + if not getattr(self.original_tokenizer, "legacy", True): # non-legacy, we need a replace + prepend_scheme = _get_prepend_scheme(add_prefix_space, self.original_tokenizer) + return pre_tokenizers.Metaspace(replacement=replacement, prepend_scheme=prepend_scheme, split=False) + else: + return super().pre_tokenizer(replacement, add_prefix_space) + + +class ChatGlmConverter(SpmConverter): + def normalizer(self, proto): + precompiled_charsmap = proto.normalizer_spec.precompiled_charsmap + _normalizers = [ + normalizers.Strip(left=False, right=True), # stripping is important + normalizers.Replace(Regex(" {2,}"), "▁"), + ] + return normalizers.Sequence([normalizers.Precompiled(precompiled_charsmap)] + _normalizers) + + def pre_tokenizer(self, replacement, add_prefix_space): + prepend_scheme = "always" + if hasattr(self.original_tokenizer, "legacy") and not self.original_tokenizer.legacy: + prepend_scheme = "first" + return pre_tokenizers.Metaspace( + replacement=replacement, add_prefix_space=add_prefix_space, prepend_scheme=prepend_scheme + ) + + +JSON_TOKEN_CONVERTERS = { + "BaichuanTokenizer": Baichuan2Converter, + "ChatGLMTokenizer": ChatGlmConverter, +} + +# Save tokenizer JSON files using HuggingFace AutoTokenizer +def convert_tokenizer(model_path, output_dir): + tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True) + if output_dir is None: + if os.path.isdir(model_path): + output_dir = model_path + else: + # create a temporary directory + output_dir = tempfile.mkdtemp() + tokenizer.save_pretrained(output_dir) + json_path = os.path.join(output_dir, "tokenizer.json") + + if type(tokenizer).__name__ in JSON_TOKEN_CONVERTERS: + GenericSpmConverter = JSON_TOKEN_CONVERTERS[type(tokenizer).__name__] + + converted = GenericSpmConverter(tokenizer).converted() + converted.save(json_path) + print(f"**Tokenizer saved to {json_path}") + return output_dir + +# Validate tokenizer files downloaded from memory +def validate_tokenizer(model_path, output_dir): + test_sentence = "I like walking my cute dog\n and\x17 then, 生活的真谛是 \t\t\t\t \n\n61" + if OrtxTokenizer is None: + print("onnxruntime_extensions package was built with C API enabled, skipping tokenization test") + ortx_tokenizer = OrtxTokenizer(output_dir) + tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True, use_fast=False) + expected_ids = tokenizer(test_sentence, return_tensors="np")["input_ids"] + ortx_ids = np.asarray(ortx_tokenizer.tokenize(test_sentence)) + assert np.array_equal(expected_ids[0], ortx_ids), f"Tokenization mismatch: {expected_ids[0]} != {ortx_ids}" + print("Tokenization test passed") + +# Download tokenizer JSON files from memory +def download_tokenizer(tokenizer_dir, output_dir): + try: + from transformers.utils import cached_file + + resolved_full_file = cached_file(tokenizer_dir, "tokenizer.json") + resolved_config_file = cached_file(tokenizer_dir, "tokenizer_config.json") + except ImportError: + raise ValueError(f"Directory '{tokenizer_dir}' not found and transformers is not available") + if not os.path.exists(resolved_full_file): + raise FileNotFoundError(f"Downloaded HF file '{resolved_full_file}' cannot be found") + if os.path.dirname(resolved_full_file) != os.path.dirname(resolved_config_file): + raise FileNotFoundError( + f"Downloaded HF files '{resolved_full_file}' " f"and '{resolved_config_file}' are not in the same directory" + ) + + if output_dir is None or len(output_dir) == 0: + output_dir = os.path.dirname(resolved_full_file) + print(f"Using {output_dir} as output directory") + return output_dir + else: + # copy the files to the output directory + shutil.copy(resolved_full_file, output_dir) + shutil.copy(resolved_config_file, output_dir) + return output_dir + def gen_processing_models(processor: Union[str, object], pre_kwargs: dict = None, post_kwargs: dict = None, opset: int = None, + schema_v2: bool = False, **kwargs): """ Generate the pre- and post-processing ONNX model, basing on the name or HF class. @@ -47,6 +204,9 @@ def gen_processing_models(processor: Union[str, object], Keyword arguments for generating the post-processing model opset: int the target opset version of the model + schema_v2: bool + the flag for using embedded tokenizer files; this option leverages the blob-loading functionality + which loads HF tokenizers from memory rather than using the tokenizer files in HF JSON format. kwargs: The additional arguments for generating models @@ -58,11 +218,42 @@ def gen_processing_models(processor: Union[str, object], if pre_kwargs is None and post_kwargs is None: raise ValueError( "Either pre_kwargs or post_kwargs should be provided. None means no processing graph output.") - if isinstance(processor, str): + + # If true, we get the tokenizer JSON files by either downloading from cache or using HuggingFace AutoTokenizer + # to convert them, and then create an ONNX model with the JSON files as strings in the model attributes (attrs). + if schema_v2: + model_name = processor if isinstance(processor, str) else type(processor).__name__ + + converted_tokenizer = {"Baichuan2", "chatglm"} + need_convert = False + for token in converted_tokenizer: + if model_name.find(token) != -1: + need_convert = True + break + + if need_convert: + model_dir = convert_tokenizer(model_name) + validate_tokenizer(model_name, None) + else: + model_dir = download_tokenizer(model_name, None) + + # Load the content of tokenizer.json into a string + with open(f"{model_dir}/tokenizer.json", "r", encoding="utf-8") as f: + tokenizer_vocab = f.read() + + # Load the content of tokenizer_config.json into a string + with open(f"{model_dir}/tokenizer_config.json", "r", encoding="utf-8") as f: + tokenizer_config = f.read() + + # Create an ONNX model with these JSON file strings in attrs g_pre, g_post = (None, None) - if pre_kwargs: - g_pre = SingleOpGraph.build_graph(processor, **pre_kwargs) - if post_kwargs: + if pre_kwargs is not None: + # Add tokenizer_vocab and tokenizer_config to the kwargs + # so they are added to attrs in build_graph + pre_kwargs['tokenizer_vocab'] = tokenizer_vocab + pre_kwargs['tokenizer_config'] = tokenizer_config + g_pre = SingleOpGraph.build_graph("HfJsonTokenizer", **pre_kwargs) + if post_kwargs is not None: if pre_kwargs is None: cls_name = processor else: @@ -70,27 +261,46 @@ def gen_processing_models(processor: Union[str, object], raise RuntimeError( f"Cannot locate the post processing operator name from {processor}") cls_name = _PRE_POST_PAIR[processor] + # Add tokenizer_vocab and tokenizer_config to the kwargs + # so they are added to attrs in build_graph + post_kwargs['tokenizer_vocab'] = tokenizer_vocab + post_kwargs['tokenizer_config'] = tokenizer_config g_post = SingleOpGraph.build_graph(cls_name, **post_kwargs) return make_onnx_model(g_pre) if g_pre else None, make_onnx_model(g_post) if g_post else None - - cls_name = type(processor).__name__ - if cls_name == "WhisperProcessor": - if WhisperDataProcGraph is None: - raise ValueError( - "The Whisper processor needs torch.onnx support, please install pytorch 2.0 and above") - _converter = WhisperDataProcGraph(processor, opset=opset, **kwargs) - pre_m = _converter.pre_processing( - **pre_kwargs) if pre_kwargs is not None else None - post_m = _converter.post_processing( - **post_kwargs) if post_kwargs is not None else None - return pre_m, post_m - elif HFTokenizerOnnxGraph.is_supported(processor): - _converter = HFTokenizerOnnxGraph(processor) - pre_g = _converter.pre_processing( - **pre_kwargs) if pre_kwargs is not None else None - post_g = _converter.post_processing( - **post_kwargs) if post_kwargs is not None else None - return make_onnx_model(pre_g) if pre_g else None, \ - make_onnx_model(post_g) if post_g else None else: - raise ValueError(f"Unsupported processor/tokenizer: {cls_name}") + if isinstance(processor, str): + g_pre, g_post = (None, None) + if pre_kwargs: + g_pre = SingleOpGraph.build_graph(processor, **pre_kwargs) + if post_kwargs: + if pre_kwargs is None: + cls_name = processor + else: + if processor not in _PRE_POST_PAIR: + raise RuntimeError( + f"Cannot locate the post processing operator name from {processor}") + cls_name = _PRE_POST_PAIR[processor] + g_post = SingleOpGraph.build_graph(cls_name, **post_kwargs) + return make_onnx_model(g_pre) if g_pre else None, make_onnx_model(g_post) if g_post else None + + cls_name = type(processor).__name__ + if cls_name == "WhisperProcessor": + if WhisperDataProcGraph is None: + raise ValueError( + "The Whisper processor needs torch.onnx support, please install pytorch 2.0 and above") + _converter = WhisperDataProcGraph(processor, opset=opset, **kwargs) + pre_m = _converter.pre_processing( + **pre_kwargs) if pre_kwargs is not None else None + post_m = _converter.post_processing( + **post_kwargs) if post_kwargs is not None else None + return pre_m, post_m + elif HFTokenizerOnnxGraph.is_supported(processor): + _converter = HFTokenizerOnnxGraph(processor) + pre_g = _converter.pre_processing( + **pre_kwargs) if pre_kwargs is not None else None + post_g = _converter.post_processing( + **post_kwargs) if post_kwargs is not None else None + return make_onnx_model(pre_g) if pre_g else None, \ + make_onnx_model(post_g) if post_g else None + else: + raise ValueError(f"Unsupported processor/tokenizer: {cls_name}") \ No newline at end of file diff --git a/operators/tokenizer/bpe_decoder.hpp b/operators/tokenizer/bpe_decoder.hpp index fb0a8d1e5..1cbb5a06e 100644 --- a/operators/tokenizer/bpe_decoder.hpp +++ b/operators/tokenizer/bpe_decoder.hpp @@ -49,26 +49,26 @@ struct KernelBpeDecoder { } std::string added_tokens; - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "added_tokens", added_tokens)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "added_tokens", added_tokens)); if (!added_tokens.empty()) { auto um = ParseId2String(added_tokens); added_tokens_ = std::map(um.begin(), um.end()); } std::string all_special_ids; - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "all_special_ids", all_special_ids)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "all_special_ids", all_special_ids)); if (!all_special_ids.empty()) { auto um = ParseId2String(all_special_ids); std::transform(um.begin(), um.end(), std::inserter(all_special_ids_, all_special_ids_.end()), [](const auto& p) { return p.first; }); } - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "en_normalization", en_normalization_)); - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "skip_special_tokens", skip_special_tokens_)); - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "whitespace_token", whitespace_token_)); - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "bos_token", bos_token_)); - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "eos_token", eos_token_)); - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "unk_token", unk_token_)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "en_normalization", en_normalization_)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "skip_special_tokens", skip_special_tokens_)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "whitespace_token", whitespace_token_)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "bos_token", bos_token_)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "eos_token", eos_token_)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "unk_token", unk_token_)); return status; } diff --git a/operators/tokenizer/bpe_kernels.cc b/operators/tokenizer/bpe_kernels.cc index d5f27b81f..4ca160c9f 100644 --- a/operators/tokenizer/bpe_kernels.cc +++ b/operators/tokenizer/bpe_kernels.cc @@ -124,24 +124,24 @@ KernelBpeTokenizer::KernelBpeTokenizer(const BpeModelConf& conf) OrtStatusPtr KernelBpeTokenizer::OnModelAttach(const OrtApi& api, const OrtKernelInfo& info) { // note: if the attribute doesn't exist in op node, GetOpAttribute doesn't return a failed status; std::string vocab; - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "vocab", vocab)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "vocab", vocab)); if (vocab.empty()) { return OrtW::CreateStatus("vocabulary shouldn't be empty.", ORT_INVALID_ARGUMENT); } std::string merges; - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "merges", merges)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "merges", merges)); if (merges.empty()) { return OrtW::CreateStatus("merges shouldn't be empty.", ORT_INVALID_ARGUMENT); } - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "padding_length", padding_length_)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "padding_length", padding_length_)); if (padding_length_ != -1 && padding_length_ <= 0) { return OrtW::CreateStatus("padding_length should be more than 0 or equal -1", ORT_INVALID_ARGUMENT); } std::string model_name; - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "model_name", model_name)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "model_name", model_name)); if (!model_name.empty()) { model_name_ = model_name; } @@ -159,7 +159,7 @@ OrtStatusPtr KernelBpeTokenizer::OnModelAttach(const OrtApi& api, const OrtKerne } std::string added_token; - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "added_token", added_token)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "added_token", added_token)); status = bbpe_tokenizer_->LoadAddedTokens(added_token.c_str()); if (!status.IsOk()) { return (OrtStatusPtr)status; diff --git a/operators/tokenizer/sentencepiece_decoder.hpp b/operators/tokenizer/sentencepiece_decoder.hpp index b7e64873d..3f592ae93 100644 --- a/operators/tokenizer/sentencepiece_decoder.hpp +++ b/operators/tokenizer/sentencepiece_decoder.hpp @@ -12,7 +12,7 @@ struct KernelSentencepieceDecoder { OrtStatusPtr OnModelAttach(const OrtApi& api, const OrtKernelInfo& info) { std::string model_blob; - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "model", model_blob)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "model", model_blob)); sentencepiece::ModelProto model_proto; model_proto.ParseFromArray(model_blob.data(), static_cast(model_blob.size())); diff --git a/operators/tokenizer/sentencepiece_tokenizer.cc b/operators/tokenizer/sentencepiece_tokenizer.cc index e44217287..867a018b6 100644 --- a/operators/tokenizer/sentencepiece_tokenizer.cc +++ b/operators/tokenizer/sentencepiece_tokenizer.cc @@ -11,7 +11,7 @@ OrtStatusPtr KernelSentencepieceTokenizer::OnModelAttach(const OrtApi& api, const OrtKernelInfo& info) { std::string model_as_string; - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "model", model_as_string)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "model", model_as_string)); sentencepiece::ModelProto model_proto; std::vector model_as_bytes; diff --git a/operators/tokenizer/tokenizer_jsconfig.hpp b/operators/tokenizer/tokenizer_jsconfig.hpp index acb565a2e..cd1a67b59 100644 --- a/operators/tokenizer/tokenizer_jsconfig.hpp +++ b/operators/tokenizer/tokenizer_jsconfig.hpp @@ -10,6 +10,30 @@ namespace ort_extensions { +enum class TokenType { + kUnknown, kUnigram, kBPE +}; + +constexpr std::pair kTokenizerDict[] = { + {"PreTrainedTokenizerFast", TokenType::kBPE}, + {"CLIPTokenizer", TokenType::kBPE}, + {"WhisperTokenizer", TokenType::kBPE}, + {"GemmaTokenizer", TokenType::kBPE}, + {"LlamaTokenizer", TokenType::kBPE}, + {"Phi3Tokenizer", TokenType::kBPE}, + {"CodeLlamaTokenizer", TokenType::kBPE}, + {"CodeGenTokenizer", TokenType::kBPE}, + {"GPT2Tokenizer", TokenType::kBPE}, + {"Qwen2Tokenizer", TokenType::kBPE}, + {"BaichuanTokenizer", TokenType::kBPE}, + + {"", TokenType::kUnigram}, + {"T5Tokenizer", TokenType::kUnigram}, + {"ChatGLMTokenizer", TokenType::kUnigram}, + {"XLMRobertaTokenizer", TokenType::kUnigram} +}; + + // TokenJsonConfig: Handles loading and parsing of JSON configuration files for tokenizers class TokenJsonConfig final { public: @@ -230,6 +254,14 @@ class TokenJsonConfig final { return added_token; } + static TokenType GetTokenType(const std::string& tok) { + static const std::unordered_map dict { + std::begin(kTokenizerDict), std::end(kTokenizerDict) }; + + auto iter = dict.find(tok); + return iter == dict.end() ? TokenType::kUnknown : iter->second; + } + private: void LoadAddedTokens(const json& tok_json) { auto added_tokens = tok_json.find("added_tokens"); diff --git a/operators/tokenizer/tokenizer_op_impl.hpp b/operators/tokenizer/tokenizer_op_impl.hpp new file mode 100644 index 000000000..455f88fa5 --- /dev/null +++ b/operators/tokenizer/tokenizer_op_impl.hpp @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include + +#include "bpe_kernels.h" +#include "ugm_kernels.hpp" + +#include "ext_status.h" +#include "op_def_struct.h" +#include "ort_c_to_cpp.h" + +namespace ort_extensions { + +class JsonTokenizerOpKernel { + public: + OrtStatusPtr OnModelAttach(const OrtApi& api, const OrtKernelInfo& info) { + std::string config_json; + ORTW_RETURN_IF_ERROR(OrtW::API::GetOpAttributeString(api, info, "tokenizer_config", config_json)); + + std::string vocab_json; + ORTW_RETURN_IF_ERROR(OrtW::API::GetOpAttributeString(api, info, "tokenizer_vocab", vocab_json)); + + TokenJsonConfig cfg; + OrtxTokenizerBlob blob({config_json.c_str(), config_json.length()}, + {vocab_json.c_str(), vocab_json.length()}); + + ORTX_RETURN_IF_ERROR(cfg.LoadFromBlob(blob)); + + auto type = TokenJsonConfig::GetTokenType(cfg.tokenizer_class_); + if (type == TokenType::kUnigram) { + tokenizer_ = std::make_unique(); + } else if (type == TokenType::kBPE) { + tokenizer_ = std::make_unique(); + } else { + return OrtxStatus(kOrtxErrorCorruptData, "Unknown tokenizer type"); + } + + return std::visit([&](auto& ptr) { return ptr->Load(cfg); }, tokenizer_); + } + + OrtxStatus Compute(const ortc::Tensor& input, + ortc::Tensor& tokenize_output, + std::optional*> attention_mask = std::nullopt, + std::optional*> offset_mapping = std::nullopt) const { + + return std::visit([&](auto& ptr) { + return ptr->Compute(input, tokenize_output, attention_mask, offset_mapping); + }, tokenizer_); + } + + private: + std::variant, std::unique_ptr> tokenizer_; +}; + +} // namespace ort_extensions diff --git a/operators/tokenizer/tokenizers.cc b/operators/tokenizer/tokenizers.cc index e723a9874..813b09a9f 100644 --- a/operators/tokenizer/tokenizers.cc +++ b/operators/tokenizer/tokenizers.cc @@ -7,6 +7,8 @@ #include "bpe_kernels.h" #include "bpe_tokenizer_model.hpp" #include "bpe_decoder.hpp" +#include "tokenizer_op_impl.hpp" +using namespace ort_extensions; #endif #ifdef ENABLE_SPM_TOKENIZER @@ -40,6 +42,7 @@ FxLoadCustomOpFactory LoadCustomOpClasses_Tokenizer = []() -> CustomOpArray& { CustomCpuStructV2("RobertaTokenizer", RobertaTokenizer), CustomCpuStructV2("BpeDecoder", KernelBpeDecoder), CustomCpuStructV2("SpmTokenizer", SpmTokenizer), + CustomCpuStructV2("HfJsonTokenizer", JsonTokenizerOpKernel), #endif #ifdef ENABLE_SPM_TOKENIZER diff --git a/operators/tokenizer/trie_tokenizer.hpp b/operators/tokenizer/trie_tokenizer.hpp index 09aadeaa6..859505cc1 100644 --- a/operators/tokenizer/trie_tokenizer.hpp +++ b/operators/tokenizer/trie_tokenizer.hpp @@ -105,7 +105,7 @@ struct KernelTrieTokenizer { public: OrtStatusPtr OnModelAttach(const OrtApi& api, const OrtKernelInfo& info) { std::string text_tokens; - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "vocab", text_tokens)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "vocab", text_tokens)); tokenizer = std::make_shared(text_tokens); return nullptr; }; @@ -156,7 +156,7 @@ struct KernelTrieDetokenizer { public: OrtStatusPtr OnModelAttach(const OrtApi& api, const OrtKernelInfo& info) { std::string text_tokens; - ORTX_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "vocab", text_tokens)); + ORTW_RETURN_IF_ERROR(OrtW::GetOpAttribute(info, "vocab", text_tokens)); tokenizer = std::make_shared(text_tokens); return nullptr; }; diff --git a/operators/tokenizer/ugm_kernels.hpp b/operators/tokenizer/ugm_kernels.hpp index dd50ae4e8..b64a1c2a1 100644 --- a/operators/tokenizer/ugm_kernels.hpp +++ b/operators/tokenizer/ugm_kernels.hpp @@ -214,7 +214,13 @@ struct SpmUgmTokenizer { return std::get<0>(iter->second); } - OrtxStatus Compute(const ortc::Tensor& input, ortc::Tensor& tokenize_output) const { + OrtxStatus Compute(const ortc::Tensor& input, ortc::Tensor& tokenize_output, + std::optional*> attention_mask = std::nullopt, + std::optional*> offset_mapping = std::nullopt) const { + if (attention_mask.has_value() || offset_mapping.has_value()) { + return {kOrtxErrorInvalidArgument, "attention-mask or offset-mapping was supported in unigram tokenizer"}; + } + if (input.Shape().size() != 1) { return OrtxStatus(extError_t::kOrtxErrorInvalidArgument, "Input tensor must have rank 1."); } diff --git a/test/data/tiktoken/tokenizer_config.json b/test/data/tiktoken/tokenizer_config.json deleted file mode 100644 index 72193e9eb..000000000 --- a/test/data/tiktoken/tokenizer_config.json +++ /dev/null @@ -1,2061 +0,0 @@ -{ - "added_tokens_decoder": { - "128000": { - "content": "<|begin_of_text|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128001": { - "content": "<|end_of_text|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128002": { - "content": "<|reserved_special_token_0|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128003": { - "content": "<|reserved_special_token_1|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128004": { - "content": "<|reserved_special_token_2|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128005": { - "content": "<|reserved_special_token_3|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128006": { - "content": "<|start_header_id|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128007": { - "content": "<|end_header_id|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128008": { - "content": "<|reserved_special_token_4|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128009": { - "content": "<|eot_id|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128010": { - "content": "<|reserved_special_token_5|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128011": { - "content": "<|reserved_special_token_6|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128012": { - "content": "<|reserved_special_token_7|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128013": { - "content": "<|reserved_special_token_8|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128014": { - "content": "<|reserved_special_token_9|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128015": { - "content": "<|reserved_special_token_10|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128016": { - "content": "<|reserved_special_token_11|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128017": { - "content": "<|reserved_special_token_12|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128018": { - "content": "<|reserved_special_token_13|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128019": { - "content": "<|reserved_special_token_14|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128020": { - "content": "<|reserved_special_token_15|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128021": { - "content": "<|reserved_special_token_16|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128022": { - "content": "<|reserved_special_token_17|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128023": { - "content": "<|reserved_special_token_18|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128024": { - "content": "<|reserved_special_token_19|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128025": { - "content": "<|reserved_special_token_20|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128026": { - "content": "<|reserved_special_token_21|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128027": { - "content": "<|reserved_special_token_22|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128028": { - "content": "<|reserved_special_token_23|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128029": { - "content": "<|reserved_special_token_24|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128030": { - "content": "<|reserved_special_token_25|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128031": { - "content": "<|reserved_special_token_26|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128032": { - "content": "<|reserved_special_token_27|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128033": { - "content": "<|reserved_special_token_28|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128034": { - "content": "<|reserved_special_token_29|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128035": { - "content": "<|reserved_special_token_30|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128036": { - "content": "<|reserved_special_token_31|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128037": { - "content": "<|reserved_special_token_32|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128038": { - "content": "<|reserved_special_token_33|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128039": { - "content": "<|reserved_special_token_34|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128040": { - "content": "<|reserved_special_token_35|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128041": { - "content": "<|reserved_special_token_36|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128042": { - "content": "<|reserved_special_token_37|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128043": { - "content": "<|reserved_special_token_38|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128044": { - "content": "<|reserved_special_token_39|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128045": { - "content": "<|reserved_special_token_40|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128046": { - "content": "<|reserved_special_token_41|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128047": { - "content": "<|reserved_special_token_42|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128048": { - "content": "<|reserved_special_token_43|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128049": { - "content": "<|reserved_special_token_44|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128050": { - "content": "<|reserved_special_token_45|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128051": { - "content": "<|reserved_special_token_46|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128052": { - "content": "<|reserved_special_token_47|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128053": { - "content": "<|reserved_special_token_48|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128054": { - "content": "<|reserved_special_token_49|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128055": { - "content": "<|reserved_special_token_50|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128056": { - "content": "<|reserved_special_token_51|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128057": { - "content": "<|reserved_special_token_52|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128058": { - "content": "<|reserved_special_token_53|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128059": { - "content": "<|reserved_special_token_54|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128060": { - "content": "<|reserved_special_token_55|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128061": { - "content": "<|reserved_special_token_56|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128062": { - "content": "<|reserved_special_token_57|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128063": { - "content": "<|reserved_special_token_58|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128064": { - "content": "<|reserved_special_token_59|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128065": { - "content": "<|reserved_special_token_60|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128066": { - "content": "<|reserved_special_token_61|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128067": { - "content": "<|reserved_special_token_62|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128068": { - "content": "<|reserved_special_token_63|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128069": { - "content": "<|reserved_special_token_64|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128070": { - "content": "<|reserved_special_token_65|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128071": { - "content": "<|reserved_special_token_66|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128072": { - "content": "<|reserved_special_token_67|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128073": { - "content": "<|reserved_special_token_68|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128074": { - "content": "<|reserved_special_token_69|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128075": { - "content": "<|reserved_special_token_70|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128076": { - "content": "<|reserved_special_token_71|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128077": { - "content": "<|reserved_special_token_72|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128078": { - "content": "<|reserved_special_token_73|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128079": { - "content": "<|reserved_special_token_74|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128080": { - "content": "<|reserved_special_token_75|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128081": { - "content": "<|reserved_special_token_76|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128082": { - "content": "<|reserved_special_token_77|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128083": { - "content": "<|reserved_special_token_78|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128084": { - "content": "<|reserved_special_token_79|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128085": { - "content": "<|reserved_special_token_80|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128086": { - "content": "<|reserved_special_token_81|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128087": { - "content": "<|reserved_special_token_82|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128088": { - "content": "<|reserved_special_token_83|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128089": { - "content": "<|reserved_special_token_84|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128090": { - "content": "<|reserved_special_token_85|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128091": { - "content": "<|reserved_special_token_86|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128092": { - "content": "<|reserved_special_token_87|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128093": { - "content": "<|reserved_special_token_88|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128094": { - "content": "<|reserved_special_token_89|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128095": { - "content": "<|reserved_special_token_90|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128096": { - "content": "<|reserved_special_token_91|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128097": { - "content": "<|reserved_special_token_92|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128098": { - "content": "<|reserved_special_token_93|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128099": { - "content": "<|reserved_special_token_94|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128100": { - "content": "<|reserved_special_token_95|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128101": { - "content": "<|reserved_special_token_96|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128102": { - "content": "<|reserved_special_token_97|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128103": { - "content": "<|reserved_special_token_98|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128104": { - "content": "<|reserved_special_token_99|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128105": { - "content": "<|reserved_special_token_100|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128106": { - "content": "<|reserved_special_token_101|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128107": { - "content": "<|reserved_special_token_102|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128108": { - "content": "<|reserved_special_token_103|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128109": { - "content": "<|reserved_special_token_104|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128110": { - "content": "<|reserved_special_token_105|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128111": { - "content": "<|reserved_special_token_106|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128112": { - "content": "<|reserved_special_token_107|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128113": { - "content": "<|reserved_special_token_108|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128114": { - "content": "<|reserved_special_token_109|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128115": { - "content": "<|reserved_special_token_110|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128116": { - "content": "<|reserved_special_token_111|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128117": { - "content": "<|reserved_special_token_112|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128118": { - "content": "<|reserved_special_token_113|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128119": { - "content": "<|reserved_special_token_114|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128120": { - "content": "<|reserved_special_token_115|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128121": { - "content": "<|reserved_special_token_116|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128122": { - "content": "<|reserved_special_token_117|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128123": { - "content": "<|reserved_special_token_118|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128124": { - "content": "<|reserved_special_token_119|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128125": { - "content": "<|reserved_special_token_120|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128126": { - "content": "<|reserved_special_token_121|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128127": { - "content": "<|reserved_special_token_122|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128128": { - "content": "<|reserved_special_token_123|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128129": { - "content": "<|reserved_special_token_124|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128130": { - "content": "<|reserved_special_token_125|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128131": { - "content": "<|reserved_special_token_126|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128132": { - "content": "<|reserved_special_token_127|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128133": { - "content": "<|reserved_special_token_128|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128134": { - "content": "<|reserved_special_token_129|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128135": { - "content": "<|reserved_special_token_130|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128136": { - "content": "<|reserved_special_token_131|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128137": { - "content": "<|reserved_special_token_132|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128138": { - "content": "<|reserved_special_token_133|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128139": { - "content": "<|reserved_special_token_134|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128140": { - "content": "<|reserved_special_token_135|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128141": { - "content": "<|reserved_special_token_136|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128142": { - "content": "<|reserved_special_token_137|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128143": { - "content": "<|reserved_special_token_138|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128144": { - "content": "<|reserved_special_token_139|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128145": { - "content": "<|reserved_special_token_140|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128146": { - "content": "<|reserved_special_token_141|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128147": { - "content": "<|reserved_special_token_142|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128148": { - "content": "<|reserved_special_token_143|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128149": { - "content": "<|reserved_special_token_144|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128150": { - "content": "<|reserved_special_token_145|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128151": { - "content": "<|reserved_special_token_146|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128152": { - "content": "<|reserved_special_token_147|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128153": { - "content": "<|reserved_special_token_148|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128154": { - "content": "<|reserved_special_token_149|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128155": { - "content": "<|reserved_special_token_150|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128156": { - "content": "<|reserved_special_token_151|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128157": { - "content": "<|reserved_special_token_152|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128158": { - "content": "<|reserved_special_token_153|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128159": { - "content": "<|reserved_special_token_154|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128160": { - "content": "<|reserved_special_token_155|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128161": { - "content": "<|reserved_special_token_156|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128162": { - "content": "<|reserved_special_token_157|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128163": { - "content": "<|reserved_special_token_158|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128164": { - "content": "<|reserved_special_token_159|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128165": { - "content": "<|reserved_special_token_160|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128166": { - "content": "<|reserved_special_token_161|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128167": { - "content": "<|reserved_special_token_162|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128168": { - "content": "<|reserved_special_token_163|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128169": { - "content": "<|reserved_special_token_164|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128170": { - "content": "<|reserved_special_token_165|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128171": { - "content": "<|reserved_special_token_166|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128172": { - "content": "<|reserved_special_token_167|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128173": { - "content": "<|reserved_special_token_168|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128174": { - "content": "<|reserved_special_token_169|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128175": { - "content": "<|reserved_special_token_170|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128176": { - "content": "<|reserved_special_token_171|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128177": { - "content": "<|reserved_special_token_172|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128178": { - "content": "<|reserved_special_token_173|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128179": { - "content": "<|reserved_special_token_174|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128180": { - "content": "<|reserved_special_token_175|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128181": { - "content": "<|reserved_special_token_176|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128182": { - "content": "<|reserved_special_token_177|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128183": { - "content": "<|reserved_special_token_178|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128184": { - "content": "<|reserved_special_token_179|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128185": { - "content": "<|reserved_special_token_180|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128186": { - "content": "<|reserved_special_token_181|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128187": { - "content": "<|reserved_special_token_182|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128188": { - "content": "<|reserved_special_token_183|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128189": { - "content": "<|reserved_special_token_184|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128190": { - "content": "<|reserved_special_token_185|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128191": { - "content": "<|reserved_special_token_186|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128192": { - "content": "<|reserved_special_token_187|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128193": { - "content": "<|reserved_special_token_188|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128194": { - "content": "<|reserved_special_token_189|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128195": { - "content": "<|reserved_special_token_190|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128196": { - "content": "<|reserved_special_token_191|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128197": { - "content": "<|reserved_special_token_192|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128198": { - "content": "<|reserved_special_token_193|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128199": { - "content": "<|reserved_special_token_194|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128200": { - "content": "<|reserved_special_token_195|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128201": { - "content": "<|reserved_special_token_196|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128202": { - "content": "<|reserved_special_token_197|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128203": { - "content": "<|reserved_special_token_198|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128204": { - "content": "<|reserved_special_token_199|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128205": { - "content": "<|reserved_special_token_200|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128206": { - "content": "<|reserved_special_token_201|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128207": { - "content": "<|reserved_special_token_202|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128208": { - "content": "<|reserved_special_token_203|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128209": { - "content": "<|reserved_special_token_204|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128210": { - "content": "<|reserved_special_token_205|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128211": { - "content": "<|reserved_special_token_206|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128212": { - "content": "<|reserved_special_token_207|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128213": { - "content": "<|reserved_special_token_208|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128214": { - "content": "<|reserved_special_token_209|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128215": { - "content": "<|reserved_special_token_210|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128216": { - "content": "<|reserved_special_token_211|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128217": { - "content": "<|reserved_special_token_212|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128218": { - "content": "<|reserved_special_token_213|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128219": { - "content": "<|reserved_special_token_214|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128220": { - "content": "<|reserved_special_token_215|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128221": { - "content": "<|reserved_special_token_216|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128222": { - "content": "<|reserved_special_token_217|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128223": { - "content": "<|reserved_special_token_218|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128224": { - "content": "<|reserved_special_token_219|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128225": { - "content": "<|reserved_special_token_220|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128226": { - "content": "<|reserved_special_token_221|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128227": { - "content": "<|reserved_special_token_222|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128228": { - "content": "<|reserved_special_token_223|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128229": { - "content": "<|reserved_special_token_224|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128230": { - "content": "<|reserved_special_token_225|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128231": { - "content": "<|reserved_special_token_226|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128232": { - "content": "<|reserved_special_token_227|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128233": { - "content": "<|reserved_special_token_228|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128234": { - "content": "<|reserved_special_token_229|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128235": { - "content": "<|reserved_special_token_230|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128236": { - "content": "<|reserved_special_token_231|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128237": { - "content": "<|reserved_special_token_232|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128238": { - "content": "<|reserved_special_token_233|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128239": { - "content": "<|reserved_special_token_234|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128240": { - "content": "<|reserved_special_token_235|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128241": { - "content": "<|reserved_special_token_236|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128242": { - "content": "<|reserved_special_token_237|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128243": { - "content": "<|reserved_special_token_238|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128244": { - "content": "<|reserved_special_token_239|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128245": { - "content": "<|reserved_special_token_240|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128246": { - "content": "<|reserved_special_token_241|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128247": { - "content": "<|reserved_special_token_242|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128248": { - "content": "<|reserved_special_token_243|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128249": { - "content": "<|reserved_special_token_244|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128250": { - "content": "<|reserved_special_token_245|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128251": { - "content": "<|reserved_special_token_246|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128252": { - "content": "<|reserved_special_token_247|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128253": { - "content": "<|reserved_special_token_248|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128254": { - "content": "<|reserved_special_token_249|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - }, - "128255": { - "content": "<|reserved_special_token_250|>", - "lstrip": false, - "normalized": false, - "rstrip": false, - "single_word": false, - "special": true - } - }, - "bos_token": "<|begin_of_text|>", - "clean_up_tokenization_spaces": true, - "eos_token": "<|end_of_text|>", - "model_input_names": [ - "input_ids", - "attention_mask" - ], - "model_max_length": 1000000000000000019884624838656, - "tokenizer_class": "PreTrainedTokenizerFast" -} diff --git a/test/data/tiktoken/tokenizer.json b/test/data/tokenizer/llama3_test.onnx similarity index 99% rename from test/data/tiktoken/tokenizer.json rename to test/data/tokenizer/llama3_test.onnx index b197f72ef..847e00f07 100644 --- a/test/data/tiktoken/tokenizer.json +++ b/test/data/tokenizer/llama3_test.onnx @@ -1,4 +1,2069 @@ -{ +:ҭ +ҭ +stridsHfJsonTokenizer_1"HfJsonTokenizer* +tokenizer_config"{ + "added_tokens_decoder": { + "128000": { + "content": "<|begin_of_text|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128001": { + "content": "<|end_of_text|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128002": { + "content": "<|reserved_special_token_0|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128003": { + "content": "<|reserved_special_token_1|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128004": { + "content": "<|reserved_special_token_2|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128005": { + "content": "<|reserved_special_token_3|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128006": { + "content": "<|start_header_id|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128007": { + "content": "<|end_header_id|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128008": { + "content": "<|reserved_special_token_4|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128009": { + "content": "<|eot_id|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128010": { + "content": "<|reserved_special_token_5|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128011": { + "content": "<|reserved_special_token_6|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128012": { + "content": "<|reserved_special_token_7|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128013": { + "content": "<|reserved_special_token_8|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128014": { + "content": "<|reserved_special_token_9|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128015": { + "content": "<|reserved_special_token_10|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128016": { + "content": "<|reserved_special_token_11|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128017": { + "content": "<|reserved_special_token_12|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128018": { + "content": "<|reserved_special_token_13|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128019": { + "content": "<|reserved_special_token_14|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128020": { + "content": "<|reserved_special_token_15|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128021": { + "content": "<|reserved_special_token_16|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128022": { + "content": "<|reserved_special_token_17|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128023": { + "content": "<|reserved_special_token_18|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128024": { + "content": "<|reserved_special_token_19|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128025": { + "content": "<|reserved_special_token_20|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128026": { + "content": "<|reserved_special_token_21|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128027": { + "content": "<|reserved_special_token_22|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128028": { + "content": "<|reserved_special_token_23|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128029": { + "content": "<|reserved_special_token_24|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128030": { + "content": "<|reserved_special_token_25|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128031": { + "content": "<|reserved_special_token_26|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128032": { + "content": "<|reserved_special_token_27|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128033": { + "content": "<|reserved_special_token_28|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128034": { + "content": "<|reserved_special_token_29|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128035": { + "content": "<|reserved_special_token_30|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128036": { + "content": "<|reserved_special_token_31|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128037": { + "content": "<|reserved_special_token_32|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128038": { + "content": "<|reserved_special_token_33|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128039": { + "content": "<|reserved_special_token_34|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128040": { + "content": "<|reserved_special_token_35|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128041": { + "content": "<|reserved_special_token_36|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128042": { + "content": "<|reserved_special_token_37|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128043": { + "content": "<|reserved_special_token_38|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128044": { + "content": "<|reserved_special_token_39|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128045": { + "content": "<|reserved_special_token_40|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128046": { + "content": "<|reserved_special_token_41|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128047": { + "content": "<|reserved_special_token_42|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128048": { + "content": "<|reserved_special_token_43|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128049": { + "content": "<|reserved_special_token_44|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128050": { + "content": "<|reserved_special_token_45|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128051": { + "content": "<|reserved_special_token_46|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128052": { + "content": "<|reserved_special_token_47|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128053": { + "content": "<|reserved_special_token_48|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128054": { + "content": "<|reserved_special_token_49|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128055": { + "content": "<|reserved_special_token_50|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128056": { + "content": "<|reserved_special_token_51|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128057": { + "content": "<|reserved_special_token_52|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128058": { + "content": "<|reserved_special_token_53|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128059": { + "content": "<|reserved_special_token_54|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128060": { + "content": "<|reserved_special_token_55|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128061": { + "content": "<|reserved_special_token_56|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128062": { + "content": "<|reserved_special_token_57|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128063": { + "content": "<|reserved_special_token_58|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128064": { + "content": "<|reserved_special_token_59|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128065": { + "content": "<|reserved_special_token_60|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128066": { + "content": "<|reserved_special_token_61|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128067": { + "content": "<|reserved_special_token_62|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128068": { + "content": "<|reserved_special_token_63|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128069": { + "content": "<|reserved_special_token_64|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128070": { + "content": "<|reserved_special_token_65|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128071": { + "content": "<|reserved_special_token_66|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128072": { + "content": "<|reserved_special_token_67|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128073": { + "content": "<|reserved_special_token_68|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128074": { + "content": "<|reserved_special_token_69|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128075": { + "content": "<|reserved_special_token_70|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128076": { + "content": "<|reserved_special_token_71|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128077": { + "content": "<|reserved_special_token_72|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128078": { + "content": "<|reserved_special_token_73|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128079": { + "content": "<|reserved_special_token_74|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128080": { + "content": "<|reserved_special_token_75|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128081": { + "content": "<|reserved_special_token_76|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128082": { + "content": "<|reserved_special_token_77|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128083": { + "content": "<|reserved_special_token_78|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128084": { + "content": "<|reserved_special_token_79|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128085": { + "content": "<|reserved_special_token_80|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128086": { + "content": "<|reserved_special_token_81|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128087": { + "content": "<|reserved_special_token_82|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128088": { + "content": "<|reserved_special_token_83|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128089": { + "content": "<|reserved_special_token_84|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128090": { + "content": "<|reserved_special_token_85|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128091": { + "content": "<|reserved_special_token_86|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128092": { + "content": "<|reserved_special_token_87|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128093": { + "content": "<|reserved_special_token_88|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128094": { + "content": "<|reserved_special_token_89|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128095": { + "content": "<|reserved_special_token_90|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128096": { + "content": "<|reserved_special_token_91|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128097": { + "content": "<|reserved_special_token_92|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128098": { + "content": "<|reserved_special_token_93|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128099": { + "content": "<|reserved_special_token_94|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128100": { + "content": "<|reserved_special_token_95|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128101": { + "content": "<|reserved_special_token_96|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128102": { + "content": "<|reserved_special_token_97|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128103": { + "content": "<|reserved_special_token_98|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128104": { + "content": "<|reserved_special_token_99|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128105": { + "content": "<|reserved_special_token_100|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128106": { + "content": "<|reserved_special_token_101|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128107": { + "content": "<|reserved_special_token_102|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128108": { + "content": "<|reserved_special_token_103|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128109": { + "content": "<|reserved_special_token_104|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128110": { + "content": "<|reserved_special_token_105|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128111": { + "content": "<|reserved_special_token_106|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128112": { + "content": "<|reserved_special_token_107|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128113": { + "content": "<|reserved_special_token_108|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128114": { + "content": "<|reserved_special_token_109|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128115": { + "content": "<|reserved_special_token_110|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128116": { + "content": "<|reserved_special_token_111|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128117": { + "content": "<|reserved_special_token_112|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128118": { + "content": "<|reserved_special_token_113|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128119": { + "content": "<|reserved_special_token_114|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128120": { + "content": "<|reserved_special_token_115|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128121": { + "content": "<|reserved_special_token_116|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128122": { + "content": "<|reserved_special_token_117|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128123": { + "content": "<|reserved_special_token_118|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128124": { + "content": "<|reserved_special_token_119|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128125": { + "content": "<|reserved_special_token_120|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128126": { + "content": "<|reserved_special_token_121|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128127": { + "content": "<|reserved_special_token_122|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128128": { + "content": "<|reserved_special_token_123|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128129": { + "content": "<|reserved_special_token_124|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128130": { + "content": "<|reserved_special_token_125|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128131": { + "content": "<|reserved_special_token_126|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128132": { + "content": "<|reserved_special_token_127|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128133": { + "content": "<|reserved_special_token_128|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128134": { + "content": "<|reserved_special_token_129|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128135": { + "content": "<|reserved_special_token_130|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128136": { + "content": "<|reserved_special_token_131|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128137": { + "content": "<|reserved_special_token_132|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128138": { + "content": "<|reserved_special_token_133|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128139": { + "content": "<|reserved_special_token_134|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128140": { + "content": "<|reserved_special_token_135|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128141": { + "content": "<|reserved_special_token_136|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128142": { + "content": "<|reserved_special_token_137|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128143": { + "content": "<|reserved_special_token_138|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128144": { + "content": "<|reserved_special_token_139|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128145": { + "content": "<|reserved_special_token_140|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128146": { + "content": "<|reserved_special_token_141|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128147": { + "content": "<|reserved_special_token_142|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128148": { + "content": "<|reserved_special_token_143|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128149": { + "content": "<|reserved_special_token_144|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128150": { + "content": "<|reserved_special_token_145|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128151": { + "content": "<|reserved_special_token_146|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128152": { + "content": "<|reserved_special_token_147|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128153": { + "content": "<|reserved_special_token_148|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128154": { + "content": "<|reserved_special_token_149|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128155": { + "content": "<|reserved_special_token_150|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128156": { + "content": "<|reserved_special_token_151|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128157": { + "content": "<|reserved_special_token_152|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128158": { + "content": "<|reserved_special_token_153|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128159": { + "content": "<|reserved_special_token_154|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128160": { + "content": "<|reserved_special_token_155|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128161": { + "content": "<|reserved_special_token_156|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128162": { + "content": "<|reserved_special_token_157|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128163": { + "content": "<|reserved_special_token_158|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128164": { + "content": "<|reserved_special_token_159|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128165": { + "content": "<|reserved_special_token_160|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128166": { + "content": "<|reserved_special_token_161|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128167": { + "content": "<|reserved_special_token_162|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128168": { + "content": "<|reserved_special_token_163|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128169": { + "content": "<|reserved_special_token_164|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128170": { + "content": "<|reserved_special_token_165|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128171": { + "content": "<|reserved_special_token_166|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128172": { + "content": "<|reserved_special_token_167|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128173": { + "content": "<|reserved_special_token_168|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128174": { + "content": "<|reserved_special_token_169|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128175": { + "content": "<|reserved_special_token_170|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128176": { + "content": "<|reserved_special_token_171|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128177": { + "content": "<|reserved_special_token_172|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128178": { + "content": "<|reserved_special_token_173|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128179": { + "content": "<|reserved_special_token_174|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128180": { + "content": "<|reserved_special_token_175|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128181": { + "content": "<|reserved_special_token_176|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128182": { + "content": "<|reserved_special_token_177|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128183": { + "content": "<|reserved_special_token_178|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128184": { + "content": "<|reserved_special_token_179|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128185": { + "content": "<|reserved_special_token_180|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128186": { + "content": "<|reserved_special_token_181|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128187": { + "content": "<|reserved_special_token_182|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128188": { + "content": "<|reserved_special_token_183|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128189": { + "content": "<|reserved_special_token_184|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128190": { + "content": "<|reserved_special_token_185|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128191": { + "content": "<|reserved_special_token_186|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128192": { + "content": "<|reserved_special_token_187|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128193": { + "content": "<|reserved_special_token_188|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128194": { + "content": "<|reserved_special_token_189|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128195": { + "content": "<|reserved_special_token_190|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128196": { + "content": "<|reserved_special_token_191|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128197": { + "content": "<|reserved_special_token_192|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128198": { + "content": "<|reserved_special_token_193|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128199": { + "content": "<|reserved_special_token_194|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128200": { + "content": "<|reserved_special_token_195|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128201": { + "content": "<|reserved_special_token_196|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128202": { + "content": "<|reserved_special_token_197|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128203": { + "content": "<|reserved_special_token_198|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128204": { + "content": "<|reserved_special_token_199|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128205": { + "content": "<|reserved_special_token_200|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128206": { + "content": "<|reserved_special_token_201|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128207": { + "content": "<|reserved_special_token_202|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128208": { + "content": "<|reserved_special_token_203|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128209": { + "content": "<|reserved_special_token_204|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128210": { + "content": "<|reserved_special_token_205|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128211": { + "content": "<|reserved_special_token_206|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128212": { + "content": "<|reserved_special_token_207|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128213": { + "content": "<|reserved_special_token_208|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128214": { + "content": "<|reserved_special_token_209|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128215": { + "content": "<|reserved_special_token_210|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128216": { + "content": "<|reserved_special_token_211|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128217": { + "content": "<|reserved_special_token_212|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128218": { + "content": "<|reserved_special_token_213|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128219": { + "content": "<|reserved_special_token_214|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128220": { + "content": "<|reserved_special_token_215|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128221": { + "content": "<|reserved_special_token_216|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128222": { + "content": "<|reserved_special_token_217|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128223": { + "content": "<|reserved_special_token_218|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128224": { + "content": "<|reserved_special_token_219|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128225": { + "content": "<|reserved_special_token_220|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128226": { + "content": "<|reserved_special_token_221|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128227": { + "content": "<|reserved_special_token_222|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128228": { + "content": "<|reserved_special_token_223|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128229": { + "content": "<|reserved_special_token_224|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128230": { + "content": "<|reserved_special_token_225|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128231": { + "content": "<|reserved_special_token_226|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128232": { + "content": "<|reserved_special_token_227|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128233": { + "content": "<|reserved_special_token_228|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128234": { + "content": "<|reserved_special_token_229|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128235": { + "content": "<|reserved_special_token_230|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128236": { + "content": "<|reserved_special_token_231|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128237": { + "content": "<|reserved_special_token_232|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128238": { + "content": "<|reserved_special_token_233|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128239": { + "content": "<|reserved_special_token_234|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128240": { + "content": "<|reserved_special_token_235|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128241": { + "content": "<|reserved_special_token_236|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128242": { + "content": "<|reserved_special_token_237|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128243": { + "content": "<|reserved_special_token_238|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128244": { + "content": "<|reserved_special_token_239|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128245": { + "content": "<|reserved_special_token_240|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128246": { + "content": "<|reserved_special_token_241|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128247": { + "content": "<|reserved_special_token_242|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128248": { + "content": "<|reserved_special_token_243|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128249": { + "content": "<|reserved_special_token_244|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128250": { + "content": "<|reserved_special_token_245|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128251": { + "content": "<|reserved_special_token_246|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128252": { + "content": "<|reserved_special_token_247|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128253": { + "content": "<|reserved_special_token_248|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128254": { + "content": "<|reserved_special_token_249|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "128255": { + "content": "<|reserved_special_token_250|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + } + }, + "bos_token": "<|begin_of_text|>", + "clean_up_tokenization_spaces": true, + "eos_token": "<|end_of_text|>", + "model_input_names": [ + "input_ids", + "attention_mask" + ], + "model_max_length": 1000000000000000019884624838656, + "tokenizer_class": "PreTrainedTokenizerFast" +} +*ƪ +tokenizer_vocab"ƪ{ "version": "1.0", "truncation": null, "padding": null, @@ -410560,4 +412625,13 @@ "éĶ ¦" ] } -} \ No newline at end of file +}:ai.onnx.contribog_HfJsonTokenizer_2Z +str +  +Nb +ids +  +N +B +ai.onnxB +ai.onnx.contrib \ No newline at end of file diff --git a/test/pp_api_test/test_tokenizer.cc b/test/pp_api_test/test_tokenizer.cc index ec7e45dbf..527d832cc 100644 --- a/test/pp_api_test/test_tokenizer.cc +++ b/test/pp_api_test/test_tokenizer.cc @@ -27,7 +27,7 @@ TEST(CApiTest, ApiTest) { int ver = OrtxGetAPIVersion(); EXPECT_GT(ver, 0); OrtxTokenizer* tokenizer = NULL; - extError_t err = OrtxCreateTokenizer(&tokenizer, "data/tiktoken"); + extError_t err = OrtxCreateTokenizer(&tokenizer, "data/llama2"); EXPECT_EQ(err, kOrtxOK); const char* input = "This is a test"; @@ -203,34 +203,6 @@ TEST(OrtxTokenizerTest, ClipTokenizer) { EXPECT_EQ(out_text[0], input[0]); } -TEST(OrtxTokenizerTest, TicTokenTokenizer) { - auto tokenizer = std::make_unique(); - auto status = tokenizer->Load("data/tiktoken"); - if (!status.IsOk()) { - std::cout << status.ToString() << std::endl; - tokenizer.reset(); - } - - // validate tokenizer is not null - ASSERT_NE(tokenizer.get(), nullptr) << "Tokenizer is null, stopping the test."; - - std::vector EXPECTED_IDS_0 = {128000, 2028, 374, 264, 1296}; - std::vector input = {"This is a test", "the second one"}; - - std::vector> token_ids; - status = tokenizer->Tokenize(input, token_ids); - EXPECT_TRUE(status.IsOk()); - EXPECT_EQ(token_ids.size(), 2); - EXPECT_EQ(token_ids[0], EXPECTED_IDS_0); - EXPECT_EQ(token_ids[1].size(), 4); - - std::vector out_text; - std::vector> token_ids_span = {token_ids[0], token_ids[1]}; - status = tokenizer->Detokenize(token_ids_span, out_text); - EXPECT_TRUE(status.IsOk()); - EXPECT_EQ(out_text[0], input[0]); -} - TEST(OrtxTokenizerTest, Phi3_Small_Hf_Tokenizer) { auto tokenizer = std::make_unique(); auto status = tokenizer->Load("data/tokenizer/phi-3-small-cvt"); diff --git a/test/shared_test/test_ortops.cc b/test/shared_test/test_ortops.cc index be981cc43..9534c9e6b 100644 --- a/test/shared_test/test_ortops.cc +++ b/test/shared_test/test_ortops.cc @@ -175,9 +175,7 @@ template void _assert_eq(Ort::Value& output_tensor, const std::vector& expected, size_t total_len) { ASSERT_EQ(expected.size(), total_len); T* f = output_tensor.GetTensorMutableData(); - for (size_t i = 0; i != total_len; ++i) { - ASSERT_EQ(expected[i], f[i]); - } + ASSERT_EQ(expected, std::vector(f, f + total_len)); } void GetTensorMutableDataString(const OrtApi& api, const OrtValue* value, std::vector& output) { diff --git a/test/shared_test/test_ortops_tokenizer.cc b/test/shared_test/test_ortops_tokenizer.cc index cf5228bd3..08ceb34e3 100644 --- a/test/shared_test/test_ortops_tokenizer.cc +++ b/test/shared_test/test_ortops_tokenizer.cc @@ -8,7 +8,7 @@ #include "test_kernel.hpp" -TEST(tokenizer_opertors, test_bert_tokenizer) { +TEST(tokenizer_operators, test_bert_tokenizer) { auto ort_env = std::make_unique(ORT_LOGGING_LEVEL_WARNING, "Default"); std::vector inputs(1); @@ -417,4 +417,24 @@ TEST(tokenizer_opertors, test_bert_tokenizer_decoder_with_idices) { outputs[0].dims = {1}; outputs[0].values_string = {"ZheJiuShisuibianDaDePinYing, YongLaiCeshiSuffixCase"}; TestInference(*ort_env, model_path.c_str(), inputs, outputs); -} \ No newline at end of file +} + +TEST(tokenizer_operators, test_hf_json_tokenizer) { + auto ort_env = std::make_unique(ORT_LOGGING_LEVEL_WARNING, "Default"); + + std::vector inputs(1); + inputs[0].name = "str"; + inputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING; + inputs[0].dims = {1}; + inputs[0].values_string = {"We look forward to welcoming you to our stores. Whether you shop in a store or shop online, our Specialists can help you buy the products you love."}; + + std::vector outputs(1); + outputs[0].name = "ids"; + outputs[0].element_type = ONNXTensorElementDataType::ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; + outputs[0].dims = {1, 32}; + outputs[0].values_int64 = {128000, 1687, 1427, 4741, 311, 36387, 499, 311, 1057, 10756, 13, 13440, 499, 8221, 304, 264, 3637, 477, 8221, 2930, 11, 1057, 92794, 649, 1520, 499, 3780, 279, 3956, 499, 3021, 13}; + + std::filesystem::path model_path = "data"; + model_path /= "tokenizer/llama3_test.onnx"; + TestInference(*ort_env, model_path.c_str(), inputs, outputs); +} diff --git a/test/test_embedded_tokenizer.py b/test/test_embedded_tokenizer.py new file mode 100644 index 000000000..257123e20 --- /dev/null +++ b/test/test_embedded_tokenizer.py @@ -0,0 +1,43 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +import unittest + +import numpy as np +from transformers import AutoTokenizer, GPT2Tokenizer +from onnxruntime_extensions import OrtPyFunction, gen_processing_models, ort_inference + + +class TestEmbeddedTokenizer(unittest.TestCase): + def test_clip_tokenizer(self): + tokenizer = AutoTokenizer.from_pretrained( + "openai/clip-vit-base-patch32", use_fast=False) + text = """ + 1. Testing long text with multiple lines to check newline handling + 2. As well as words with apostrophes such as you're, i'm, don't, etc. + 3. And weird characters such as . , ~ ? ( ) " [ ] ! : - . + """ + ids = tokenizer.encode(text, return_tensors="np") + + ort_tok = OrtPyFunction.from_model(gen_processing_models( + tokenizer, + pre_kwargs={"WITH_DEFAULT_INPUTS": True})[0], + schema_v2=True) + actual_ids = ort_tok([text])[0] + np.testing.assert_array_equal(ids, actual_ids) + + def test_gpt2_tokenizer(self): + tokenizer = GPT2Tokenizer.from_pretrained( + "Xenova/gpt-4", use_fast=False) + text = "Testing words with apostrophes such as you're, i'm, don't, etc." + ids = tokenizer.encode(text, return_tensors="np") + + ort_tok = OrtPyFunction.from_model(gen_processing_models( + tokenizer, + pre_kwargs={"WITH_DEFAULT_INPUTS": True})[0], + schema_v2=True) + actual_ids = ort_tok([text])[0] + np.testing.assert_array_equal(ids, actual_ids) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file