Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to use env variable for BPE_FILE location #128

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 33 additions & 11 deletions tiktoken_ext/openai_public.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from tiktoken.load import data_gym_to_mergeable_bpe_ranks, load_tiktoken_bpe
import os

ENDOFTEXT = "<|endoftext|>"
FIM_PREFIX = "<|fim_prefix|>"
Expand All @@ -8,9 +9,17 @@


def gpt2():
vocab_bpe_file = os.environ.get(
"TIKTOKEN_BPE_FILE_GPT2_VOCAB",
"https://openaipublic.blob.core.windows.net/gpt-2/encodings/main/vocab.bpe",
)
encoder_json_file = os.environ.get(
"TIKTOKEN_BPE_FILE_GPT2_ENCODER",
"https://openaipublic.blob.core.windows.net/gpt-2/encodings/main/encoder.json",
)
mergeable_ranks = data_gym_to_mergeable_bpe_ranks(
vocab_bpe_file="https://openaipublic.blob.core.windows.net/gpt-2/encodings/main/vocab.bpe",
encoder_json_file="https://openaipublic.blob.core.windows.net/gpt-2/encodings/main/encoder.json",
vocab_bpe_file=vocab_bpe_file,
encoder_json_file=encoder_json_file,
)
return {
"name": "gpt2",
Expand All @@ -22,9 +31,11 @@ def gpt2():


def r50k_base():
mergeable_ranks = load_tiktoken_bpe(
"https://openaipublic.blob.core.windows.net/encodings/r50k_base.tiktoken"
tiktoken_bpe_file = os.environ.get(
"TIKTOKEN_BPE_FILE_R50K_BASE",
"https://openaipublic.blob.core.windows.net/encodings/r50k_base.tiktoken",
)
mergeable_ranks = load_tiktoken_bpe(tiktoken_bpe_file)
return {
"name": "r50k_base",
"explicit_n_vocab": 50257,
Expand All @@ -35,9 +46,11 @@ def r50k_base():


def p50k_base():
mergeable_ranks = load_tiktoken_bpe(
"https://openaipublic.blob.core.windows.net/encodings/p50k_base.tiktoken"
tiktoken_bpe_file = os.environ.get(
"TIKTOKEN_BPE_FILE_P50K_BASE",
"https://openaipublic.blob.core.windows.net/encodings/p50k_base.tiktoken",
)
mergeable_ranks = load_tiktoken_bpe(tiktoken_bpe_file)
return {
"name": "p50k_base",
"explicit_n_vocab": 50281,
Expand All @@ -48,10 +61,17 @@ def p50k_base():


def p50k_edit():
mergeable_ranks = load_tiktoken_bpe(
"https://openaipublic.blob.core.windows.net/encodings/p50k_base.tiktoken"
tiktoken_bpe_file = os.environ.get(
"TIKTOKEN_BPE_FILE_P50K_BASE",
"https://openaipublic.blob.core.windows.net/encodings/p50k_base.tiktoken",
)
special_tokens = {ENDOFTEXT: 50256, FIM_PREFIX: 50281, FIM_MIDDLE: 50282, FIM_SUFFIX: 50283}
mergeable_ranks = load_tiktoken_bpe(tiktoken_bpe_file)
special_tokens = {
ENDOFTEXT: 50256,
FIM_PREFIX: 50281,
FIM_MIDDLE: 50282,
FIM_SUFFIX: 50283,
}
return {
"name": "p50k_edit",
"pat_str": r"""'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+""",
Expand All @@ -61,9 +81,11 @@ def p50k_edit():


def cl100k_base():
mergeable_ranks = load_tiktoken_bpe(
"https://openaipublic.blob.core.windows.net/encodings/cl100k_base.tiktoken"
tiktoken_bpe_file = os.environ.get(
"TIKTOKEN_BPE_FILE_CL100K_BASE",
"https://openaipublic.blob.core.windows.net/encodings/cl100k_base.tiktoken",
)
mergeable_ranks = load_tiktoken_bpe(tiktoken_bpe_file)
special_tokens = {
ENDOFTEXT: 100257,
FIM_PREFIX: 100258,
Expand Down