forked from axolotl-ai-cloud/axolotl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workaround for md5 variations (axolotl-ai-cloud#533)
* workaround for md5 variations * refactor the prepared hash too
- Loading branch information
Showing
2 changed files
with
79 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
""" | ||
test module for the axolotl.utis.data module | ||
""" | ||
import unittest | ||
|
||
from transformers import LlamaTokenizer | ||
|
||
from axolotl.utils.data import encode_pretraining, md5 | ||
|
||
|
||
class TestEncodePretraining(unittest.TestCase): | ||
""" | ||
test class for encode pretraining and md5 helper | ||
""" | ||
|
||
def setUp(self): | ||
self.tokenizer = LlamaTokenizer.from_pretrained("huggyllama/llama-7b") | ||
self.tokenizer.add_special_tokens( | ||
{ | ||
"eos_token": "</s>", | ||
"bos_token": "<s>", | ||
"unk_token": "<unk>", | ||
"pad_token": "<pad>", | ||
} | ||
) | ||
self.max_tokens = 15 # set a small number for easy inspection | ||
|
||
def test_encode_pretraining(self): | ||
examples = { | ||
"text": [ | ||
"Hello, world!", | ||
"Nice to meet you.", | ||
"lorem ipsum dolor sit amet.", | ||
"Nice to meet you again!.", | ||
"hello, hello", | ||
] | ||
} | ||
result = encode_pretraining(self.tokenizer, self.max_tokens, examples) | ||
|
||
self.assertEqual(len(result["input_ids"]), 3) | ||
|
||
# Assert the length of input_ids and attention_mask is correct | ||
self.assertEqual(len(result["input_ids"][0]), self.max_tokens) | ||
self.assertEqual(len(result["attention_mask"][0]), self.max_tokens) | ||
|
||
# Assert EOS and PAD tokens are correctly added | ||
# hello world! is 4 tokens | ||
self.assertEqual(result["input_ids"][0][0], self.tokenizer.bos_token_id) | ||
self.assertEqual(result["input_ids"][0][5], self.tokenizer.eos_token_id) | ||
self.assertEqual(result["input_ids"][0][6], self.tokenizer.pad_token_id) | ||
# second part, 5 tokens | ||
self.assertEqual(result["input_ids"][0][7], self.tokenizer.bos_token_id) | ||
self.assertEqual(result["input_ids"][0][13], self.tokenizer.eos_token_id) | ||
self.assertEqual(result["input_ids"][0][14], self.tokenizer.pad_token_id) | ||
|
||
def test_md5(self): | ||
self.assertEqual(md5("hello world"), "5eb63bbbe01eeed093cb22bb8f5acdc3") | ||
self.assertEqual( | ||
md5("hello world", "utf-8"), "5eb63bbbe01eeed093cb22bb8f5acdc3" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |