Skip to content

Commit 05f43ae

Browse files
add data to gitignore
1 parent 83ddf6f commit 05f43ae

4 files changed

Lines changed: 60 additions & 6 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,6 @@ docs/_build/
7070

7171
# Pyenv
7272
.python-version
73+
74+
# data
75+
python/rusty_tokey/data/*.txt

python/rusty_tokey/results/owt/vocab_20250621_165715.txt

Whitespace-only changes.

python/rusty_tokey/results/tinystories/vocab_20250621_165053.txt

Lines changed: 25 additions & 0 deletions
Large diffs are not rendered by default.

python/rusty_tokey/rlly_serious.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
PAT_RE = re.compile(PAT)
1111

1212

13-
def find_chunk_boundaries(file: BinaryIO, desired_num_chunks: int, split_special_token: bytes) -> list[int]:
13+
def find_chunk_boundaries(
14+
file: BinaryIO, desired_num_chunks: int, split_special_token: bytes
15+
) -> list[int]:
1416
"""
1517
Chunk the file into parts that can be counted independently.
1618
May return fewer chunks if the boundaries end up overlapping.
1719
"""
18-
assert isinstance(split_special_token, bytes), "Must represent special token as a bytestring"
20+
assert isinstance(split_special_token, bytes), (
21+
"Must represent special token as a bytestring"
22+
)
1923

2024
# Get total file size in bytes
2125
file.seek(0, os.SEEK_END)
@@ -52,6 +56,7 @@ def find_chunk_boundaries(file: BinaryIO, desired_num_chunks: int, split_special
5256
# Make sure all boundaries are unique, but might be fewer than desired_num_chunks
5357
return sorted(set(chunk_boundaries))
5458

59+
5560
def rusty_train_bpe(
5661
input_path: str, vocab_size: int, special_tokens: list[str]
5762
) -> tuple[dict[int, bytes], list[tuple[bytes, bytes]]]:
@@ -62,7 +67,9 @@ def rusty_train_bpe(
6267
# find the chunk boundaries
6368
boundaries = find_chunk_boundaries(f, 16, "<|endoftext|>".encode("utf-8"))
6469

65-
max_pairs = rusty_full_merge(input_path, boundaries, special_tokens, stopping_condition)
70+
max_pairs = rusty_full_merge(
71+
input_path, boundaries, special_tokens, stopping_condition
72+
)
6673
# print('max_pairs', max_pairs)
6774
vocab: dict[int, bytes] = {}
6875
# single-bytes
@@ -81,9 +88,28 @@ def rusty_train_bpe(
8188
if __name__ == "__main__":
8289
profiler = cProfile.Profile()
8390
profiler.enable()
84-
(vocab, max_pairs) = rusty_train_bpe("./python/rusty_tokey/data/tinystories_sample_5M.txt", 400, ["<|endoftext|>"])
85-
print("max_pairs", max_pairs)
86-
print("vocab", vocab)
91+
# --------- tinystories sample ---------
92+
# (vocab, max_pairs) = rusty_train_bpe("./python/rusty_tokey/data/tinystories_sample_5M.txt", 400, ["<|endoftext|>"])
93+
# print("max_pairs", max_pairs)
94+
# print("vocab", vocab)
95+
# --------- tinystories sample ---------
96+
97+
# --------- tinystories ---------
98+
# (vocab, max_pairs) = rusty_train_bpe(
99+
# "./python/rusty_tokey/data/TinyStoriesV2-GPT4-train.txt",
100+
# 10_000,
101+
# ["<|endoftext|>"],
102+
# )
103+
# print({k: v.decode("utf-8", errors="replace") for k, v in vocab.items()})
104+
# --------- tinystories ---------
105+
# --------- tinystories ---------
106+
(vocab, max_pairs) = rusty_train_bpe(
107+
"./python/rusty_tokey/data/owt_train.txt",
108+
32_000,
109+
["<|endoftext|>"],
110+
)
111+
print({k: v.decode("utf-8", errors="replace") for k, v in vocab.items()})
112+
# --------- tinystories ---------
87113
profiler.disable()
88114
stats = pstats.Stats(profiler).sort_stats("cumtime")
89115
stats.print_stats(20) # Show top 20 slowest functions

0 commit comments

Comments
 (0)