Skip to content

Commit 5d44507

Browse files
committed
add server.
1 parent da089fe commit 5d44507

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

autocomplete/gpt2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ def predict_with_original_gpt2(prompts):
2020
for prompt in prompts:
2121
# Generate text using the model. Verbose set to False to prevent logging generated sequences.
2222
generated = model.generate(prompt, verbose=False)
23-
2423
generated = generated[0]
25-
print("=============================================================================")
2624
print(generated)
27-
print("=============================================================================")
25+
print("=" * 20)
2826

2927

30-
def train(model_dir="outputs/fine-tuned/", train_file="download/train.txt", valid_file="download/valid.txt",
28+
def train(model_dir="outputs/fine-tuned/",
29+
train_file="download/train.txt",
30+
valid_file="download/valid.txt",
3131
num_train_epochs=3):
3232
train_args = {
3333
"reprocess_input_data": True,

autocomplete/server.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@author:XuMing(xuming624@qq.com)
33
@description: Server
44
"""
5+
import argparse
56
import uvicorn
67
import sys
78
import os
@@ -16,8 +17,11 @@
1617
pwd_path = os.path.abspath(os.path.dirname(__file__))
1718
use_cuda = torch.cuda.is_available()
1819
# Use finetuned GPT2 model
19-
model_dir = os.path.join(pwd_path, "outputs/fine-tuned/")
20-
gpt2_infer = Infer(model_name="gpt2", model_dir=model_dir, use_cuda=use_cuda)
20+
parser = argparse.ArgumentParser()
21+
parser.add_argument("--model_name_or_path", type=str, default="shibing624/code-autocomplete-gpt2-base",
22+
help="Model save dir or model name")
23+
args = parser.parse_args()
24+
gpt2_infer = Infer(model_name="gpt2", model_dir=args.model_name_or_path, use_cuda=use_cuda)
2125

2226
# define the app
2327
app = FastAPI()

0 commit comments

Comments
 (0)