hades / tests /tokenizer /test_export.py
Kolgrim's picture
HADES pipeline code, tokenizer, tests, docs
5f02c05 verified
Raw History Blame Contribute Delete
1.17 kB
from hades.tokenizer.export import encode_fast, export_hf, load_fast
from tests.conftest import FIXTURE_LINES
def test_parity_on_fixture(trained_small, tmp_path):
export_hf(trained_small, tmp_path / "t.json")
fast = load_fast(tmp_path / "t.json")
texts = FIXTURE_LINES + ["<|eos|> literal", "", " ", "é漢字 CVE-2024-3094", "\x00\x1b[31m", "á ①②"]
assert encode_fast(fast, texts) == [trained_small.encode(t) for t in texts]
def test_fast_decode_matches(trained_small, tmp_path):
export_hf(trained_small, tmp_path / "t.json")
fast = load_fast(tmp_path / "t.json")
ids = trained_small.encode(FIXTURE_LINES[0])
assert fast.decode(ids) == FIXTURE_LINES[0]
def test_parity_random_unicode(trained_small, tmp_path):
import random
export_hf(trained_small, tmp_path / "t.json")
fast = load_fast(tmp_path / "t.json")
rng = random.Random(1)
pool = "ab Z9 \t\n\r   é́漢①٣_-./[]:;<>|" + "".join(chr(c) for c in range(0x80, 0x100))
texts = ["".join(rng.choice(pool) for _ in range(rng.randint(0, 40))) for _ in range(500)]
assert encode_fast(fast, texts) == [trained_small.encode(t) for t in texts]