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

Add example for text-to-text transfer transformer (T5) inference #12

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
t5 : add example for text-to-text transfer transformer inference
  • Loading branch information
ggerganov committed Dec 31, 2022
commit ed683187cbe9f5574a2f8b3106d96f2e07721f49
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ target_include_directories(ggml_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(gpt-2)
add_subdirectory(gpt-j)
add_subdirectory(whisper)
add_subdirectory(t5)
6 changes: 6 additions & 0 deletions examples/t5/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# t5

set(TEST_TARGET t5)
add_executable(${TEST_TARGET} main.cpp)
target_link_libraries(${TEST_TARGET} PRIVATE ggml ggml_utils)
3 changes: 3 additions & 0 deletions examples/t5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# t5

ref: https://github.com/huggingface/transformers/blob/main/src/transformers/models/t5/modeling_t5.py
25 changes: 25 additions & 0 deletions examples/t5/convert-flan-t5-pt-to-ggml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import io
import sys
import torch

import code

from transformers import AutoModelForSeq2SeqLM, AutoTokenizer

if len(sys.argv) < 3:
print("Usage: convert-flan-t5-pt-to-ggml.py path-to-pt-model dir-output [use-f32]\n")
sys.exit(1)

fname_inp=sys.argv[1] + "/pytorch_model.bin"

try:
model_bytes = open(fname_inp, "rb").read()
with io.BytesIO(model_bytes) as fp:
checkpoint = torch.load(fp, map_location="cpu")
except:
print("Error: failed to load PyTorch model file: %s" % fname_inp)
sys.exit(1)

# list all keys
for k in checkpoint.keys():
print(k)
3 changes: 3 additions & 0 deletions examples/t5/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main() {
return 0;
}