Skip to content

Commit

Permalink
GPT: fix batch predict. (PaddlePaddle#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZHUI authored May 19, 2021
1 parent c7914e9 commit f2dbd81
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions paddlenlp/transformers/gpt/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,14 +781,14 @@ def model(self,
def forward(self, input_ids, end_id):
output, cached_kvs = self.model(input_ids, use_cache=True, cache=None)
src_ids = input_ids
nid = paddle.argmax(output[0, -1]).reshape([1, -1])
nid = paddle.argmax(output[:, -1, :], axis=-1).reshape([-1, 1])
src_ids = paddle.concat([src_ids, nid], axis=1)
cur_len = 0
while (cur_len < self.max_predict_len):
output, cached_kvs = self.model(
nid, use_cache=True, cache=cached_kvs)

nid = paddle.argmax(output[0, -1]).reshape([1, -1])
nid = paddle.argmax(output[:, -1, :], axis=-1).reshape([-1, 1])
src_ids = paddle.concat([src_ids, nid], axis=1)
cur_len += 1
if paddle.max(nid) == end_id:
Expand Down

0 comments on commit f2dbd81

Please sign in to comment.