Skip to content

Commit

Permalink
update text server to support compute logprobs (NVIDIA#7733)
Browse files Browse the repository at this point in the history
* update text server to support compute logprobs

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix typo

---------

Signed-off-by: Zhilin Wang <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Zhilin123 and pre-commit-ci[bot] authored Oct 24, 2023
1 parent 609af14 commit 265a0a6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions nemo/collections/nlp/modules/common/text_generation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"repetition_penalty",
"min_tokens_to_generate",
"end_strings",
"compute_logprob",
]
)

Expand Down Expand Up @@ -165,6 +166,12 @@ def put(self):
if neighbors < 0:
return "num of neighbors must be an integer no less than 0"

compute_logprob = False
if "compute_logprob" in request.get_json():
compute_logprob = request.get_json()["compute_logprob"]
if not isinstance(compute_logprob, bool):
return "compute_logprob must be a boolean value"

with lock: # Need to get lock to keep multiple threads from hitting code
MegatronGenerate.send_do_generate() # Tell other ranks we're doing generate
extra = {}
Expand Down Expand Up @@ -192,6 +199,7 @@ def put(self):
repetition_penalty,
end_strings=end_strings,
min_tokens_to_generate=min_tokens_to_generate,
compute_logprob=compute_logprob,
**extra,
)
for k in output:
Expand Down

0 comments on commit 265a0a6

Please sign in to comment.