[Bugfix][Frontend] Handle aborted requests in beam search (#56249)
Signed-off-by: 子华 <huaxi.shx@alibaba-inc.com> Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -293,6 +293,18 @@ class BeamSearchOfflineMixin(OfflineInferenceMixin):
|
||||
allowed_sets[i] = set(entry[1])
|
||||
|
||||
for (start, end), instance in zip(instance_start_and_end, instances_batch):
|
||||
instance_output = output[start:end]
|
||||
if any(
|
||||
result is not None and result.outputs[0].finish_reason == "abort"
|
||||
for result in instance_output
|
||||
):
|
||||
for beam, result in zip(all_beams[start:end], instance_output):
|
||||
if result is not None:
|
||||
beam.finish_reason = "abort"
|
||||
instance.completed.append(beam)
|
||||
instance.beams = []
|
||||
continue
|
||||
|
||||
instance_new_beams = []
|
||||
for i in range(start, end):
|
||||
current_beam = all_beams[i]
|
||||
@@ -302,8 +314,6 @@ class BeamSearchOfflineMixin(OfflineInferenceMixin):
|
||||
continue
|
||||
|
||||
if result.outputs[0].logprobs is not None:
|
||||
# if logprobs is None, the sequence completed
|
||||
# due to max-model-len or abortion.
|
||||
logprobs = result.outputs[0].logprobs[0]
|
||||
allowed = allowed_sets[i]
|
||||
for token_id, logprob_obj in logprobs.items():
|
||||
|
||||
@@ -99,11 +99,7 @@ class BeamSearchOnlineMixin(ABC):
|
||||
|
||||
output = [x[0] for x in await asyncio.gather(*tasks)]
|
||||
|
||||
candidates = []
|
||||
# Iterate through all beam inference results
|
||||
for i, result in enumerate(output):
|
||||
current_beam = all_beams[i]
|
||||
|
||||
for result in output:
|
||||
# check for error finish reason and abort beam search
|
||||
if result.outputs[0].finish_reason == "error":
|
||||
# yield error output and terminate beam search
|
||||
@@ -126,6 +122,15 @@ class BeamSearchOnlineMixin(ABC):
|
||||
)
|
||||
return
|
||||
|
||||
if any(result.outputs[0].finish_reason == "abort" for result in output):
|
||||
for beam in all_beams:
|
||||
beam.finish_reason = "abort"
|
||||
break
|
||||
|
||||
candidates = []
|
||||
for i, result in enumerate(output):
|
||||
current_beam = all_beams[i]
|
||||
|
||||
if result.outputs[0].logprobs is not None:
|
||||
logprobs = result.outputs[0].logprobs[0]
|
||||
for token_id, logprob_obj in logprobs.items():
|
||||
|
||||
@@ -150,7 +150,8 @@ def get_beam_search_score(
|
||||
if tokens[-1] == eos_token_id:
|
||||
seq_len -= 1
|
||||
|
||||
return cumulative_logprob / (seq_len**length_penalty)
|
||||
# An aborted beam may contain only an EOS prompt token.
|
||||
return cumulative_logprob / (max(seq_len, 1) ** length_penalty)
|
||||
|
||||
|
||||
def create_sort_beams_key_function(eos_token_id: int, length_penalty: float):
|
||||
|
||||
Reference in New Issue
Block a user