From c7a6c32882111ff977d8f8b1b2d4e310873d8566 Mon Sep 17 00:00:00 2001 From: Joan Martinez Date: Thu, 2 May 2024 18:01:00 +0200 Subject: [PATCH] fix: protect against slow tokenizer --- convert-hf-to-gguf.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/convert-hf-to-gguf.py b/convert-hf-to-gguf.py index b7e715cb6..5a5d3b49a 100755 --- a/convert-hf-to-gguf.py +++ b/convert-hf-to-gguf.py @@ -271,10 +271,14 @@ class Model(ABC): chktxt = '\n \n\n \n\n\n \t \t\t \t\n \n \n \n \n🚀 (normal) 😶\u200d🌫️ (multiple emojis concatenated) ✅ 🦙🦙 3 33 333 3333 33333 333333 3333333 33333333 3.3 3..3 3...3 កាន់តែពិសេសអាច😁 ?我想在apple工作1314151天~ ------======= нещо на Български \'\'\'\'\'\'```````""""......!!!!!!?????? I\'ve been \'told he\'s there, \'RE you sure? \'M not sure I\'ll make it, \'D you like some tea? We\'Ve a\'lL' - pre_out = tokenizer.backend_tokenizer.pre_tokenizer.pre_tokenize_str(tokenizer.backend_tokenizer.normalizer.normalize_str(chktxt)) - chkhsh = sha256(str(pre_out).encode()).hexdigest() + if hasattr(tokenizer, 'backend_tokenizer'): + chktok = tokenizer.backend_tokenizer.pre_tokenizer.pre_tokenize_str(tokenizer.backend_tokenizer.normalizer.normalize_str(chktxt)) + chkhsh = sha256(str(chktok).encode()).hexdigest() + else: + chktok = tokenizer.encode(chktxt) + chkhsh = sha256(str(chktok).encode()).hexdigest() - print(f"pre_out: {pre_out}") + print(f"chktok: {chktok}") print(f"chkhsh: {chkhsh}") res = None