Skip to content

Commit 304274c

Browse files
committed
made codegpt truncate sequences that are too long. server now uses 2 gpu's, with codegpt on gpu 2
1 parent 007684c commit 304274c

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

code4me-server/src/codegpt.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,23 @@ def DecodeIds(idxs):
149149
return codes.strip(" ")
150150

151151

152-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
152+
device = torch.device("cuda:1" if torch.cuda.is_available() else "cpu")
153153
model.to(device)
154154
model.eval()
155155
break_ids = [tokenizer.sep_token_id]
156156

157157

158158
def codegpt_predict(left_context: str, right_context: str):
159-
# preprocess
160-
left_context = left_context.replace("\n", "<EOL>")
161-
left_context = f"<s> {left_context}"
162-
163-
inputs = torch.tensor(tokenizer.encode(left_context)).unsqueeze(0).to(device)
159+
input = input.replace("\n", "<EOL>")
160+
block_size = 1024
161+
predict_size = 64
162+
tokens = tokenizer.encode(input)[-(block_size - predict_size - 1):]
163+
# print tokens as strings
164+
# prepend with <s>
165+
tokens = [tokenizer.bos_token_id] + tokens
166+
inputs = torch.tensor(tokens).unsqueeze(0).to(device)
164167
with torch.no_grad():
165-
beam_size = 5
168+
beam_size = 3
166169
m = torch.nn.LogSoftmax(dim=-1)
167170
outputs = model(inputs[:, :-1])[1]
168171
p = []
@@ -195,7 +198,7 @@ def codegpt_predict(left_context: str, right_context: str):
195198
if 0 in t:
196199
t = t[:t.index(0)]
197200
text = DecodeIds(t).strip("<EOL>").strip()
198-
# post process
199201
text = text.replace("<EOL>", "\n")
200202
return text
203+
return ""
201204

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,4 @@ services:
3535
- 3000
3636
environment:
3737
- CODE4ME_CUDA=True
38-
- NVIDIA_VISIBLE_DEVICES=1
3938
- "SURVEY_LINK=https://docs.google.com/forms/d/1uES5o6etbWEZVNpUc0TGisDJXIIuj5hIwa9tF7_FQuw/?entry.1566855902={user_id}"

0 commit comments

Comments
 (0)